This sample template is used to pull code by using Git, build a software package from the code, upload the software package to Object Storage Service (OSS), and then deploy the software package on multiple Elastic Compute Service (ECS) instances at a time. The system can build the software package on an existing ECS instance or create an ECS instance for building the software package. After the software package is built, the created ECS instance is automatically released.
Prerequisites
An ECS instance is created and the ECS instance can access the Internet. For more information, see Create an ECS instance and Enable Internet access.
ImportantThis sample template supports only the Linux operating system.
OSS is activated and an OSS buckets are created. For more information, see Activate OSS and Create a bucket.
Sample template
You specify the code source, such as Object Storage Service (OSS) or GitHub. CloudOps Orchestration Service (OOS) generates a temporary URL for the code source to pull code from the code source.
Build a software package such as a JAR package and upload it to OSS.
Pull the software package and deploy it on multiple ECS instances.
Example
Prepare the code source
The sample code of a Spring Boot project is used in this example. The code is uploaded to Gitee and GitHub. If you want to use the code, you must fork the code to your own repository. Code address:
Gitee: Sample code (recommended for users in the Chinese mainland)
GitHub:Sample code (recommended for users in the Chinese mainland)
Create a template
Log on to the CloudOps Orchestration Service console.
In the left-side navigation pane, choose and click Create Template.
In the Build and Deploy section, select ACS-ECS-ExampleSoftwarePackageBuildAndDeployFromGit and click Next.
On the Process Configuration tab, set the parameters and click Create Template.
Specify the code source to generate a temporary authorization link.
In this example, Gitee is used as the code source. Set the following parameters: Owner, Organization, Repository, and Branch.
NoteIf Alibaba Cloud is not authorized to access your GitHub or Gitee repository, click Grant the required permissions.
If you have forked the sample code, all repositories that belong to your account are automatically displayed in the Repository drop-down list. In this case, select the repository to which you forked the code.

Build a software package such as a JAR package and upload it to OSS.
Select the code source and the ECS instance, and then provide the build command.

CodeResource: In this example,
gitis selected. The output of the previous task is used, which isauthorizedUrl.Choose Building Ecs: Select an ECS instance. You can select Existing ECS or New ECS.
NoteIf you select New ECS, you are charged on a pay-as-you-go basis. OOS automatically checks whether Docker is installed on the ECS instance. If Docker is not installed, OOS automatically installs Docker Community Edition on the ECS instance.
Build Configuration: provides build commands as needed.
If you execute this sample template, Maven will be first installed and a JAR package will be created. The JAR package is in the
targetdirectory. You can replace the sample with a script that meets your requirements.Sample script (Alibaba Cloud Linux 3)
### sample build script set -e yum install -y maven-3.5.4 mvn packageSample script (Ubuntu)
### sample build script set -e apt install -y maven mvn packageSample script (CentOS)
### sample build script set -e yum install -y maven mvn package
Provide the package path and build name.
In the following example, the package path is
target/. OOS will compress the package into a.tgzfile.
Upload the build output to OSS.
Specify the OSS bucket and object path to which you want to upload the software package.

In the Task Output(Optional) section, add
bucketName(the name of the OSS bucket) andobjectName(the full path of the build in the bucket, including the directory and the name of the build) for subsequent tasks. You can directly use the outputs for subsequent tasks.Deploy the software package on multiple ECS instances that run Linux.

Target Instance: Select the ECS instances on which you want to deploy the package.
OSS: The information about the OSS bucket to which the build belongs. The OSS bucket name and OSS object name are referenced by default. You do not need to specify them repeatedly. You also need to specify the directory to download the package. In this example,
/home/admin/app/is used.Deployment Script: You can provide a deployment script based on your requirements.
In this example, the
.tgzfile is decompressed to the specified path and thejava -jarcommand is used to run the JAR package by using port 8080.
Optional. Set the concurrency control parameters to control the concurrency rate of multiple ECS instances.
Click Create Template.
Execute the template
Log on to the CloudOps Orchestration Service console.
In the left-side navigation pane, choose .
On the Custom Template page, find the template and click Create Execution in the Actions column.
In the Basic Information step, set the parameters and click Next Step: Parameter Settings.
In the Parameter Settings step, click OK if no parameters are available.
Click Create.
On the Task Execution Management page, if the execution status is Success, the execution is complete.

Log on to the ECS console.
Find the ECS instance and connect to the instance.
For more information, see Use Workbench to connect to a Linux instance over SSH.
Run the following command to check whether the deployment is successful.
curl http://localhost:8080/helloIf the following message is returned, the deployment is successful.
NoteIf the message
Failed to connect to localhost port 8080:Connection refusedis returned, the possible cause is that Java is not installed on your ECS instance. Run theyum install javacommand and check again.
What to do next
If you update your code in the future, you need to only push your updated code to the corresponding Git repository and execute this template again. Then, your latest code is automatically pulled from the repository, packaged, uploaded to OSS, and then deployed on the ECS instances. If you want to modify the template, you can modify the template and then execute the template.