If you want to pull code from GitHub and use the code to build and deploy an application on a single Elastic Compute Service (ECS) instance, you can execute a CloudOps Orchestration Service (OOS) template to build and deploy the application.
This sample template is used to build and deploy applications on a single ECS instance. If you want to publish a build to a repository or deploy it on multiple ECS instances, see Build an image and upload it to Container Registry, Create a Docker image, upload it to Container Registry, and deploy it to ECS, Build a software package and upload it to OSS, and Build a software package, upload it to OSS, and then deploy it on ECS instances.
Prerequisites
An ECS instance is created. For more information, see Create an instance.
The ECS instance can access the Internet. For more information, see Enable Internet access.
Sample template
You specify the code source, such as OSS or GitHub. OOS generates a temporary URL for the code source to pull code from the code source.
OOS automatically pulls code to execute a script used to build and deploy an application.
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-ExampleLocalBuildAndDeployOnSingleECSFromGit and click Next Step.
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.

Pull code from Gitee to build and deploy an application.
Select the ECS instance on which you want to deploy the application. Set CodeResource to
git. The default valueauthorizedUrl, which is the output of the previous task, is used for CodeResourceUrl. This example is for reference only. You can specify a script based on your requirements.
Sample script (Alibaba Cloud Linux 3)
### Build jar file. set -e yum install -y maven-3.5.4 mvn package ### Stop the previous version of the application (if any) and deploy the current version. PID=$(ps -ef | grep "sample-spring-1.0-SNAPSHOT.jar" | grep -v "grep" | awk '{print $2}') if [ -n "$PID" ]; then kill -9 $PID fi java -jar target/sample-spring-1.0-SNAPSHOT.jar &Sample script (Ubuntu)
### Build jar file. set -e apt install -y maven mvn package ### Stop the previous version of the application (if any) and deploy the current version. PID=$(ps -ef | grep "sample-spring-1.0-SNAPSHOT.jar" | grep -v "grep" | awk '{print $2}') if [ -n "$PID" ]; then kill -9 $PID fi java -jar target/sample-spring-1.0-SNAPSHOT.jar &Sample script (CentOS)
### Build jar file. set -e yum install -y maven mvn package ### Stop the previous version of the application (if any) and deploy the current version. PID=$(ps -ef | grep "sample-spring-1.0-SNAPSHOT.jar" | grep -v "grep" | awk '{print $2}') if [ -n "$PID" ]; then kill -9 $PID fi java -jar target/sample-spring-1.0-SNAPSHOT.jar &NoteAfter the template is executed, the code is pulled to a folder in the
/root/workspace/task IDdirectory. This folder is also used as the working path for the build and deployment script. You can also specify a custom path in the script.
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 field is returned, the deployment is successful.
