Use this deployment type to publish an application whose source files are stored in a Git repository.
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 process for the publishing task.
Retrieve the deployment information. This includes the Git repository information and the application's start and stop scripts.
Pull the code. The code is pulled from the specified branch into the
code_deploy_applicationfolder in the working directory.Run the stop script. The application stop script is run to stop the old version of the application.
Run the start script. The application start script is run to start the new version of the application.
Scope
Deployments are supported only on Linux instances.
Only Shell scripts are supported for the start and stop scripts.
Procedure
Create an application and import an Elastic Compute Service (ECS) instance.
If you do not have an ECS instance, go to the ECS console - Custom Launch page. Create an ECS instance that runs a Linux operating system and has Internet access.
Select an ECS image, such as Alibaba Cloud Linux 3.2104 LTS 64-bit or Ubuntu 22.04 64-bit. The scripts in the following examples are written for these two images. If you use a different image, you must modify the scripts based on the examples.
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 the deployment.
Fork the following sample code to your personal Git repository.
You must register a personal Gitee or GitHub account. If the instance is in the Chinese mainland, use Gitee.
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 page, set RevisionType to Git Repository Code, configure the parameters, and then click OK.
Git repository information: Configure the information for the Git repository where your code is located.
If this is your first time, follow the prompts in the console to grant authorization for the Git repository.
Working directory: The directory where the application start and stop scripts are run. Example:
/root/deploy. By default, the code is pulled to thecode_deploy_applicationfolder in this directory.Alibaba Cloud Linux
### Note: The code from the Git repository is automatically downloaded to the code_deploy_application folder in the working directory. The path is {working directory}/code_deploy_application. ### Start the current version of the application. function 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 from the Git repository is automatically downloaded to the code_deploy_application folder in the working directory. The path is {working directory}/code_deploy_application. ### Start the current version of the application. function 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 any) function 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.
Key parameters
Field | Description |
Platform | Select the Git repository platform where the code is located. |
Owner | Select the account that owns the Git repository. Grant authorization the first time you use it. |
Organization | Select a personal repository or an organization repository. |
Repository | Select the repository where the code is located. |
Branch | Select the branch to deploy. |
CommitId | You do not need to enter a value. After you select a branch, the system automatically obtains the latest CommitId. |
Working directory | The working directory for the application's start and stop scripts.
|
Application start script | The Shell script used to start the application. |
Application stop script | The Shell script to stop the application. For example, the following script stops a container named |