Use this deployment package type when you do not need to specify application source files and publish your application entirely through scripts.
How it works
If you deploy to an application group that is an Auto Scaling (ESS) group, scaling activities are paused during the deployment. They automatically resume after the deployment finishes, whether it succeeds or fails.
The deployment process follows a stop-then-start principle. Each deployment first runs the stop script and then runs the start script.
Create and publish the deployment.
Configure the application source file, start script, and stop script for the deployment.
Create a release task, select a release mode, and publish the deployment to the target application group.
Automated deployment flow for task publishing.
-
Retrieve deployment package details, including the application startup and shutdown scripts.
-
Run the shutdown script: Stop the previous version of the application.
-
Run the startup script: Start the new version of the application.
-
Scope
Deployments are supported only on Linux instances.
The start and stop scripts must be Shell scripts.
Procedure
Java application example
Create an application and import Elastic Compute Service (ECS) instances.
If you do not have an ECS instance, create one that runs a Linux operating system from the ECS console - Custom Launch page.
We recommend using an ECS image of Alibaba Cloud Linux 3.2104 LTS 64-bit or Ubuntu 22.04 64-bit. The scripts in the following examples are based on these two images. If you use a different image, modify the scripts as needed.
Go to the ECS console - Application Management page, click Create from Existing Resources, create an application and an application group, and import the ECS instance into the application group.
-
Create a deployment package.
Go to the ECS console - Application Management page. On the My Applications tab, click the name of the target application.
On the application product page, select the Deployment tab, and then click Create Deployment.
-
On the Create Deployment Package page, set Deployment Package Type to Command-only. Configure the parameters. Click OK to save.
-
Working directory: Set the directory where the startup and shutdown scripts run. Example:
/root/deploy. -
Alibaba Cloud Linux
start_application() { set -e curl -O https://oos-public-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/code-deploy/sample-spring-1.0-SNAPSHOT.jar yum install -y maven-3.5.4 java -jar ./sample-spring-1.0-SNAPSHOT.jar & } start_applicationUbuntu
start_application() { set -e curl -O https://oos-public-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/code-deploy/sample-spring-1.0-SNAPSHOT.jar apt update apt install -y maven java -jar ./sample-spring-1.0-SNAPSHOT.jar & } start_application -
### Stop the application (if any) stop_application() { PID=$(ps -ef | grep "sample-spring-1.0-SNAPSHOT.jar" | grep -v "grep" | awk '{print $2}') if [ -n "$PID" ]; then kill -9 $PID fi } stop_application
-
Return to the deployment list. Find the deployment that you created and click Publish. Select the target group and click OK to start the deployment.
Verify the result.
-
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Run the
curl http://localhost:8080/hellocommand. A return value ofAlibaba Spring Sample!indicates that the deployment was successful.
-
Docker application example
Prepare your application, group, and ECS instances.
Before deploying, create your application and application group in ECS Application Management. Then add your prepared ECS instances to the group.
If you do not have an ECS instance, create one that runs a Linux operating system from the ECS console - Custom Launch page.
We recommend using an ECS image of Alibaba Cloud Linux 3.2104 LTS 64-bit or Ubuntu 22.04 64-bit. The scripts in the following examples are based on these two images. If you use a different image, modify the scripts as needed.
Go to the ECS console - Application Management page, click Create from Existing Resources, create an application and an application group, and import the ECS instance into the application group.
Install Docker on the ECS instances in your group. On the Operations Management tab of your application group, select Install or uninstall extensions to install Docker in batch.
If your ECS instances were created from a custom image, you cannot install extensions this way. Instead, log on to the instance remotely and install Docker manually.
-
Create a deployment package.
-
Pull the sample image locally. Then push the image to your personal ACR instance repository.
docker pull aliyun-computenest-opensource-registry.cn-hangzhou.cr.aliyuncs.com/default/aliyun-code-deploy:latest Go to the ECS console - Application Management page. On the My Applications tab, click the name of the target application.
-
On the application details page, select the Parameters tab. Click Create Parameter. Create two parameters:
usernameandpassword. These correspond to your personal ACR username and password. For security, create thepasswordparameter as an encrypted parameter. On the application product page, select the Deployment tab, and then click Create Deployment.
-
On the Create Deployment Package page, set Deployment Package Type to Command-only. Configure the parameters. Click OK to save.
-
Working directory: Set the directory where the startup and shutdown scripts run. Example:
/root/deploy. -
Application startup script: Replace
<repo>and<image>with your personal ACR information.In the figure below, the first field is
repo. The second field isimage. Replace these values in the corresponding positions of the startup script.
### Start the current version of the application start_application() { repo="<repo>" image="<image>" container_name="my-container" docker login --username=${username} --password=${password} $repo docker pull $image docker run -d -p 8080:8080 --name $container_name $image } start_application -
### Stop the container (if any) stop_application() { # Query whether the container exists by the container name, and delete the container if it exists container_name="my-container" container_id=$(docker ps -aq -f name=${container_name}) if [ -n "$container_id" ]; then docker rm -f $container_id fi } stop_application
-
-
Return to the deployment list. Find the deployment that you created and click Publish. Select the target group and click OK to start the deployment.
Verify the result.
-
Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.
Run the
curl http://localhost:8080/hellocommand. A return value ofAlibaba Spring Sample!indicates that the deployment was successful.
-
Key fields
|
Field |
Description |
|
Working directory |
The working directory for the application startup and shutdown scripts.
|
|
Application startup script |
A Shell script that starts the application. |
|
Application shutdown script |
The Shell script to stop the application. For example, the following script stops a container named |