This sample template is used to pull code from GitHub to create a Docker image and upload it to Container Registry. This is applicable to scenarios where images are created and uploaded to an image repository. You can use this template to create an image for an existing Elastic Compute Service (ECS) instance. You can also use this template to create an image for a temporary ECS instance that will be released after the image is created. In addition, this template allows you to upload images to Container Registry Enterprise Edition or Container Registry Personal Edition based on your business requirements. You are charged for using Container Registry Enterprise Edition. You can use Container Registry Personal Edition free of charge.
Prerequisites
An ECS instance is created. The ECS instance is accessible over the Internet. For more information, see Create instances and Enable public bandwidth for an ECS instance.
Container Registry Enterprise Edition or Container Registry Personal Edition is activated. For more information, see What is Container Registry?, Differences between Personal Edition instances, Cost-effective Edition instances, and Enterprise Edition instances, and Create a Container Registry Personal Edition instance.
Procedure
The following figure shows the two steps involved in the template.
Step 1: 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.
Step 2: OOS automatically pulls code to install Docker and executes a script to create an image. After the image is created, OOS uploads the image to the specified image repository in Container Registry.

Example
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: Alicloud-ComputeNest/oos-cicd-example-java (recommended for users in the Chinese mainland)
GitHub: aliyun-computenest/oos-cicd-example-java
In this example, an ECS instance that runs Alibaba Cloud Linux 3.2104 is used. The commands for building and deploying an application vary in environments. You need to modify the commands based on your business requirements.
Create a template
Log on to the CloudOps Orchestration Service. In the left-side navigation pane, choose . On the Custom Template page, click Create Template.
On the Create Template page, select ACS-ECS-ExampleDockerBuildFromGit for the Build and Deploy parameter, and click Next Step.
On the Process Configuration tab, click Hide All in the upper-right corner. You can view the steps involved in the template.

Click Show All and configure the template.
Specify the code source. OOS generates a temporary URL for the code source. The URL is used to pull code from the code source in the next step.
Gitee is used as the code source in this example. You must obtain the required permission on the repository from which you want to pull code before you specify the Owner, Organization, and Repository parameters.
Then, select the repository from which you want to pull code. If you have forked the sample code, all repositories under your account are automatically displayed in the Repository drop-down list. In this case, select the repository to which you forked the code. When you execute the template, OOS automatically generates a temporary URL of the repository and uses the URL as the authorizedUrl in the task output. The URL is used in the subsequent step.
Create a Docker image and upload it to Container Registry.
Specify the code source. In this example, git is selected. OOS references the authorizedUrl in the output of the previous task as the URL of the code source.
NoteOOS automatically pulls code to a folder, as shown in the following figure. This folder is used as the working path in which you run subsequent commands.
Select the ECS instance for which you want to create an image. You can create an image for an existing ECS instance or a temporary ECS instance. The temporary ECS instance will be automatically released after the image is created. The temporary ECS instance is billed 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.
Write commands that are required to create an image. These commands are run after the
docker buildcommand. This way, you can make preparations before the image is created. These commands are run in the folder that is used as the working path. In this example, an image is created in a Dockerfile. No preparation is required.
Create a Docker image and upload it to Container Registry. In this case, OOS automatically runs the
docker buildcommand to create an image. You must specify the path of the Dockerfile and the context path in which thedocker buildcommand is run. For more information, see the detailed description of corresponding parameters.
In this example, Dockerfile is stored in the root directory of the pulled code, as shown in the following figure. Therefore, you can directly specify the name of the Dockerfile. You do not need to specify the context path because it is also a root directory. By default, the context path and the Dockerfile belong to the same directory.
In addition, you must specify the information about Container Registry. Container Registry Enterprise Edition and Container Registry Personal Edition are supported. You can select an edition based on your business requirements. If you are a Container Registry Enterprise Edition user, you need to select the Container Registry instance ID, namespace, and repository to which you want to upload an image.
If you are a Container Registry Personal Edition user, you need to specify the username and password, and select the repository to which you want to upload an image. For more information about how to use a repository of Container Registry Personal Edition, see Create a Container Registry Personal Edition instance.
Specify the image version. The default value consists of the current date and the execution ID. You can specify the image version of your project. Check whether the image is uploaded over a virtual private cloud (VPC). For more information, see Configure a VPC ACL.
Click Create Template.
Execute the template
On the Custom Template page, find the template that you created and click Create Execution in the Actions column. Keep the default settings and click Next Step: OK. The template is executed.

After the execution is successful, go to the Container Registry console. Check whether the latest image is pushed to the specified repository. After the image is pushed to the repository, the image can be used for subsequent deployment or other operations.
What to do next
If your code is updated, you need to only push the code to the corresponding GitHub repository and execute the template again. Then, OOS pulls the latest code from the code source, regenerates the image, and pushes the image to Container Registry. If you want to modify the template, you can modify the template and then execute the template.