Deploy applications from a Git repository to ECS instances or ESS scaling groups.
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.
-
Retrieve deployment information: Git repository details and start/stop scripts.
-
Pull code from the specified branch into the
code_deploy_applicationfolder in the working directory. -
Run the stop script to stop the current application.
-
Run the start script to launch the new application version.
-
Usage notes
-
Only Linux instances are supported.
-
Start and stop scripts must be Shell scripts.
Procedure
-
Create an application and import an ECS instance.
-
If you do not have an ECS instance, create a Linux instance with a public IP address on the ECS console - Custom Launch page.
Recommended images: Alibaba Cloud Linux 3.2104 LTS 64-bit or Ubuntu 22.04 64-bit. The sample scripts target these images. Modify the scripts if you use a different image.
-
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.
-
Fork the sample code to your Git repository.
Requires a Gitee or GitHub account. Use Gitee for instances in the Chinese mainland.
-
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 RevisionType to Git Repo, configure the parameters, and then click OK.
-
Git repository information: Specify the repository that stores your code.
On first use, follow the on-screen instructions to authorize Git repository access.
-
Working directory: The directory where start and stop scripts run. Example:
/root/deploy. Code is pulled to thecode_deploy_applicationfolder in this directory. -
Alibaba Cloud Linux
# Note: The code is downloaded to the code_deploy_application folder within the working directory. # Start the current version of the application. start_application() { cd ./code_deploy_application set -e yum install -y maven-3.5.4 java -jar sample-spring-1.0-SNAPSHOT.jar & } start_applicationUbuntu
# Note: The code is downloaded to the code_deploy_application folder within the working directory. # Start the current version of the application. start_application() { cd ./code_deploy_application set -e apt update apt install -y maven java -jar sample-spring-1.0-SNAPSHOT.jar & } start_application -
# Stop the application, if it is running. 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.
Key parameters
|
Parameter |
Description |
|
Platform |
Select the Git platform where your code is hosted. |
|
Owner |
Select the repository owner. Authorization is required on first use. |
|
Organization |
Select a personal or organization repository. |
|
Repository |
Select the code repository. |
|
Branch |
Select the branch to deploy. |
|
CommitId |
Auto-populated. The system retrieves the latest CommitId after you select a branch. |
|
Working directory |
The directory where start and stop scripts run.
|
|
Application start script |
Shell script to start the application. |
|
Application stop script |
The shell script to stop the application. For example, the following script stops a container named
|