This template pulls code from Git, builds a package, uploads it to Object Storage Service (OSS), and deploys it to multiple Elastic Compute Service (ECS) instances. You can build on an existing ECS instance or a temporary instance that is released after the build.
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 package and deploy it to multiple ECS instances.
Example
Prepare the code source
This example uses a sample Spring Boot project. The code is available in Gitee and GitHub repositories. Before you start, fork the project to your own repository.
-
Gitee: Gitee sample code (Recommended for users in the Chinese mainland)
-
GitHub: GitHub sample code (Recommended for users outside the Chinese mainland)
Create a template
-
Log on to the CloudOps Orchestration Service console.
-
In the left-side navigation pane, choose , and then click Create Template.
-
In the Building and Deployment section, select Build a software package, upload it to OSS, and then deploy it, and click Next.
-
On the Process Configuration tab, enter the template parameters and click Create Template.
-
Specify a code source to generate a temporary authorization link for pulling the code.
This example uses Gitee as the code source. Enter the Owner, Organization, repository, and branch for your repository.
Note-
If you have not authorized Alibaba Cloud to read your repositories from GitHub or Gitee, click Go to Authorization to grant access.
-
If you have already forked the sample code, your repositories are automatically listed in the repository drop-down list. Select the forked repository.

-
-
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 for the package.

In the Task Output(Optional) section, add
bucketName(OSS bucket name) andobjectName(full path of the build in the bucket). These outputs can be referenced by subsequent tasks. -
Deploy the package to multiple Linux-based ECS instances.

-
Target Instance: Select the ECS instances to deploy the package to.
-
OSS: The bucket name and object name are auto-populated from the previous step. Specify the download directory for the package. This example uses
/home/admin/app/. -
Deployment Script: Provide a deployment script for your application.
This example decompresses the
.tgzfile and runs the JAR package on port 8080 withjava -jar.
-
-
Optional. Configure concurrency control for multi-instance deployment.
-
Click Create Template.
-
Execute the template
-
Log on to the CloudOps Orchestration Service console.
-
In the left-side navigation pane, choose .
-
On the custom task template page, find the template that you created and click Create an execution in the Actions column.
-
In the Basic Information step, configure the parameters and click Next: Set Parameters.
-
In the Parameter Settings step, if no changes are needed, click Next: Confirm.
-
Click Create.
On the task execution management page, a status of Successful indicates that the execution is complete.

-
Log on to the ECS console.
-
Connect to the ECS instance.
-
Run the following command to verify the deployment.
curl http://localhost:8080/helloIf the following message appears, the deployment succeeded.
NoteIf you see
Failed to connect to localhost port 8080:Connection refused, Java may not be installed. Runyum install javaand retry.
What to do next
To deploy updated code, push it to the Git repository and re-execute this template. The latest code is automatically pulled, packaged, uploaded to OSS, and deployed. You can also modify the template before re-execution.