You can use this topic to assist your process automation under the following conditions:
Code development in Java
Delivery in the JAR or WAR format
Execution on ECS or a self-managed host
2. Customer requirements
Customers use host deployment in the following typical scenarios:
Perform some quality checks on the source code such as unit testing and code scanning.
Build source code into a deliverable such as a JAR or WAR file.
Publish a deliverable to an ECS virtual host
3. Apsara DevOps operations
The following example demonstrates how to build an application deliverable and publish it to ECS. A Java Spring Boot repository is used in the example.
Create a pipeline
Log on to Apsara DevOps Flow (https://flow.alibabacloud.com/).
Click Create Pipeline.
Select the Java · Test, build Image, and deploy to ECS/VM template and click Create.
Configure a code repository
Add a code source. Select General Git. Set Code Repository to https://github.com/yunxiao-devops/spring-boot-example.git and Default Branch to master. You can enter any personal certificate, because a public code repository is used in the example.
Configure a build & archive task
Modify the Java Build & Archive task and add the Archive Path field. Set the value to deploy.sh.The deploy.sh file exists in the code repository and contains the script to boot applications on ECS. For subsequent host deployment, you must add the deploy.sh file to the package file. How to use the deploy.sh file will be described in the host deployment part.Here you specify two paths: target/and deploy.sh. Flow packages and archives the two files (or folders) into an artifact. The artifact will also be used in the subsequent host deployment task.
Configure a host deployment task
Configure the host deployment task. Select Artifact Name.default from the drop-down list. The artifact is the artifact archived in the Java build & archive task.To configure a host group, you must click Create Deployment Group to create a host group first.
Click Create Service Authorization. You are redirected to RAM to complete RAM authorization. Then, you are automatically returned to Flow.Select the region and the ECS instance to be deployed. Click Next. Enter the host group name and click Save. The host group is created.The newly created host group is automatically added to the pipeline configurations.
Configure the deployment script.
Download Path: indicates where you store the compressed package created in the build & archive task. The value in this example is /home/admin/app/package.tgz.
Execute User: indicates which role executes the script? The value in this example is root.
Deployment Script: the content of the script. The value in this example:
mkdir -p /home/admin/application/ tar zxvf /home/admin/app/package.tgz -C /home/admin/application/ sh /home/admin/application/deploy.sh restart
4.Configure a deployment policy
Suspend Strategy: indicates what suspension method is used in the host group, such as Suspend First Batch, Suspend Per Batch, or Without Suspension.We recommend that you select Suspend First Batch. After the first batch is published, check the online service. If no exceptions occur, you can continue publishing the remaining batches.
Batch Quantity: indicates the number of batches you want to divide the machines in the host group.For example, you divide a total of four machines into two batches. Each batch contains two machines.
Run a pipeline
After the configurations are complete, click Save and Run to trigger the pipeline.
Then, you can view the details of the pipeline, including code scan results, build logs, and deployment logs.