You can use a command-only deployment package to deploy an application using only scripts, without providing any source files.
How it works
-
If you deploy to an Auto Scaling (ESS) group, scaling activities are paused during the deployment. They resume automatically 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 a deployment.
Configure a deployment with your application's source file information, start script, and stop script.
Create a release task, select a release mode, and publish the deployment to the target application group.
-
The automated deployment process works as follows:
-
The service retrieves the deployment package information, including the startup and shutdown scripts.
-
Run shutdown script: The service executes the shutdown script to stop the previous application version.
-
Run startup script: The service executes the startup script to start the new application version.
-
Usage notes
-
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 your Elastic Compute Service (ECS) instances.
-
If you do not have an ECS instance, go to the ECS console - Custom Launch page to create a Linux ECS instance.
The following example scripts are for these images. If you use a different image, you must modify the scripts accordingly.
-
Go to the ECS console - Application management page and click Create from Existing Resources to 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 your target application.
-
On the application details page, select the Deployment tab, and then click Create Deployment.
-
On the Create Deployment page, set Deployment Package Type to Run Command, configure the parameters, and then click OK.
-
Working directory: Specify the working directory for the startup and shutdown scripts. 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
-
-
-
Go back to the deployment list, find the deployment that you created, and click Deploy. Select the target group and click OK to start the deployment.
-
Verify the result.
Navigate to the details page of the target instance. Click Connect and select Workbench. Follow the on-screen prompts to access the terminal.
-
Run the
curl http://localhost:8080/hellocommand. A response ofAlibaba Spring Sample!indicates a successful deployment.
Docker application example
-
Prepare the application, group, and ECS instances.
Before you deploy, create an application and a group in ECS Application Management. Then, add your ECS instances to the group.
-
If you do not have an ECS instance, go to the ECS console - Custom Launch page to create a Linux ECS instance.
The following example scripts are for these images. If you use a different image, you must modify the scripts accordingly.
-
Go to the ECS console - Application management page and click Create from Existing Resources to create an application and an application group, and import the ECS instance into the application group.
Install Docker on the ECS instances in the group. On the O&M tab of the application group, select ACS-ECS-BulkyConfigureOOSPackageWithTemporaryURL to install Docker in a batch.
If your ECS instance was created from a custom image, you cannot install extensions this way. You must remotely connect to the instance and manually install Docker.
-
-
Create a deployment package.
-
Pull the sample image to your local machine, and then push the image to your ACR Personal Edition 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 your target application.
-
On the application details page, select the Parameters tab and click Create Parameter. Create two parameters,
usernameandpassword, for the ACR Personal Edition username and password. To ensure security, create thepasswordparameter as an encrypted parameter. -
On the application details page, select the Deployment tab, and then click Create Deployment.
-
On the Create Deployment page, set Deployment Package Type to Run Command, configure the parameters, and then click OK.
-
Working directory: Specify the execution directory for the startup and shutdown scripts. Example:
/root/deploy. -
Application startup script: Replace the
<repo>and<image>placeholders with your ACR Personal Edition repository and image details.In the following image, the first field is
repo, and the second field isimage. Replace the corresponding parameters in the application startup script with the values of these two fields.
### 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() { # Find the container by name and remove it 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
-
-
-
Go back to the deployment list, find the deployment that you created, and click Deploy. Select the target group and click OK to start the deployment.
-
Verify the result.
Navigate to the details page of the target instance. Click Connect and select Workbench. Follow the on-screen prompts to access the terminal.
-
Run the
curl http://localhost:8080/hellocommand. A response ofAlibaba Spring Sample!indicates a successful deployment.
Key parameters
|
Parameter |
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
|