If a service provider uses a continuous integration (CI) environment to build or update software, the service provider can add the updates to deployment packages of the Elastic Compute Service (ECS) image type in Compute Nest to the CI process. This way, when the service provider publishes the verified software version to Compute Nest, the version and content of the deployment package of the ECS image type are simultaneously updated and published. This topic describes how to add the updates to a deployment package of the ECS image type in Compute Nest to the CI process as a service provider.
Preparations
Prepare the following items before you begin:
Build a CI environment. In this example, a CI environment is built by using Jenkins. For more information, see the Example of building a CI environment section of this topic.
Install Alibaba Cloud CLI 3.0.141 or later.
After you build a CI environment, install the jq command-line JSON processor.
In the Compute Nest console, create a deployment package to be added to the CI process. For more information, see Overview.
Create a virtual private cloud (VPC), vSwitch, and security group used for creating an ECS image. For more information, see Create and manage a VPC, Create and manage vSwitches, and Create a security group.
Procedure
Before you proceed, make sure that your account is attached with the AliyunComputeNestSupplierFullAccess and AliyunECSFullAccess policies that allow you to manage Compute Nest services as a service provider and manage ECS resources. For more information, see View the permissions of a RAM user.
Configure the environment variables that are used by Alibaba Cloud CLI in the CI environment.
export ALIBABACLOUD_ACCESS_KEY_ID=yourAccessKeyID export ALIBABACLOUD_ACCESS_KEY_SECRET=yourAccessKeySecret export ALIBABACLOUD_REGION_ID=cn-hangzhou # Set the environment variable to cn-hangzhou or ap-southeast-1.Create an ECS image.
You must use the ACS-ECS-UpdateImage public template provided by CloudOps Orchestration Service (OOS) to create an ECS image.
# Update an image by using OOS. # Specify the parameters that are required to execute the template used to update an image. For more information about the parameters, visit https://oos.console.alibabacloud.com/cn-hangzhou/template/public/detail/ACS-ECS-UpdateImage. regionId="cn-hangzhou" # The region ID of the execution. securityGroupId="sg-8vb9b*****wvnuqy6" # The security group that is used to create a temporary instance. vSwitchId="vsw-8vb5p1******zv01c" # The vSwitch that is used to create a temporary instance. instanceType="ecs.g5.large" # The instance type of the temporary instance. sourceImageId="centos_7_8_x64_20G_alibase_20200622.vhd" # The source image to be updated. commandType="RunShellScript" # The type of the command. # The command content. The following sample command is used to install MySQL. Replace the sample command with the command used to install your software. commandContent='yum install mysql -y' parameters="{ \"securityGroupId\": \"$securityGroupId\", \"commandType\": \"$commandType\", \"sourceImageId\": \"$sourceImageId\", \"regionId\": \"$regionId\", \"vSwitchId\": \"$vSwitchId\", \"instanceType\": \"$instanceType\", \"commandContent\": \"$commandContent\", \"ramRoleName\": \"\" }" # Start the execution. execution_id=`aliyun oos StartExecution --TemplateName ACS-ECS-UpdateImage --Parameters "${parameters}" | jq -r ".Execution.ExecutionId"` # Wait until the execution is complete. while do status=`aliyun oos ListExecutions --ExecutionId ${execution_id} |jq -r '.Executions[0].Status'` if [ "$status" == "Success" ]; then break fi sleep 1 done # Obtain the image ID. image_id=`aliyun oos ListExecutions --ExecutionId ${execution_id} |jq -r '.Executions[0].Outputs | fromjson | .imageId'`Continuously integrate the deployment package of the ECS image type.
When you run the integrating command, replace
<your_artifact_id>in the command lines with the ID of your deployment package.# Specify the ID of the deployment package. artifact_id=<your_artifact_id> # Create a deployment package. aliyun computenestsupplier CreateArtifact --ArtifactId ${artifact_id} --ArtifactType EcsImage --Name 'Deployment package of the ECS image type for CI' --VersionName 'NewVersion' --ArtifactProperty "{\"ImageId\":\"${image_id}\",\"RegionId\":\"cn-hangzhou\"}" --SupportRegionIds.1 null # Publish the deployment package. aliyun computenestsupplier ReleaseArtifact --ArtifactId ${artifact_id}
Example of building a CI environment
The following example shows how to create an Elastic Compute Service (ECS) instance with Jenkins installed and complete the initial configurations of Jenkins by using Resource Orchestration Service (ROS) to build a CI environment. In this example, the Alibaba Cloud Linux operating system is used.
Log on to the ROS console.
In the left-side navigation pane, choose .
Find the template named Installs Jenkins on an ECS instance (Existing VPC) and click Create Stack.
Configure the parameters as prompted and click Create. For more information, see Create a stack.
After the stack is created, you can view the output information on the Outputs tab of the stack details page.
After the stack is created, obtain the Jenkins URL on the Outputs tab of the stack details page and open the URL in a browser. Example: http://39.**.**.168:8080.
On the Unlock Jenkins page, enter the password in the Administrator password field. The password is the value of the InitialAdminPassword output keyword displayed on the Outputs tab of the stack details page.
On the Customize Jenkins page, click Install suggested plugins.
After the plug-ins are installed, specify the username and password on the Create First Admin User page to create an administrator user. Then, log on to Jenkins as the created user.
