Host deployment orchestration
This topic describes how to use host deployment orchestration in Alibaba Cloud DevOps AppStack.
Create host deployment orchestration
This deployment method uses scripts to deploy an artifact package to virtual or physical machines and supports application health checks.
In , click From Template.
Select an application orchestration template. You can choose from or Alibaba Cloud DevOps sample templates. In the Select Template dialog box, under the Alibaba Cloud DevOps sample template section, select the Host Script Deployment Demo Spring Boot Template.
Click OK. The selected template is instantiated as the orchestration content for the current application. (The template is used for initialization only, and modifications to the template do not affect existing applications.)
Script execution logic
Alibaba Cloud DevOps AppStack uses the defined orchestration scripts for different operational scenarios. The execution logic is as follows:
Host deployment: stop script + start script + health check script (if configured). To redeploy a host (for example, during an environment deployment, scale out, or rollback), AppStack first runs the stop script to stop the existing service. Then, it runs the start script to start the new service. If a health check script is configured, AppStack runs it to check the service health status. The deployment is considered successful only if all scripts complete without errors.
Host offline: stop script + cleanup script (if configured). To take a host offline (for example, during an environment scale in or deletion), AppStack first runs the stop script to stop the service. Then, if a cleanup script is configured, AppStack runs it to delete unused artifact packages and log files.
Edit application orchestration
Example scenario
The following example uses a sample Alibaba Cloud DevOps Spring Boot application to demonstrate how to edit an orchestration.
Artifact: The package deployed to a host. An artifact is typically the output of a pipeline's build stage, such as a .tgz package. You can download the package from a remote HTTP source or copy it manually to the host. Learn more.
HTTP: Downloads the artifact package from a remote HTTP source. Specify the package source (where the package comes from) and the save path (where to download it). The start script uses this information to deploy the application.
Package source: Specify the HTTP download URL of the artifact package. Ensure that the URL is directly downloadable. You can use the placeholder
{{ .AppStack.artifact.xxx }}to pass the artifact URL dynamically at deployment time.Example:
{{ .AppStack.artifact.myapp }}, wheremyappis the placeholder name for the artifact package.
Save path: The path on your host where the artifact package will be downloaded, such as /home/admin/app/package.tgz. The start script uses this path to deploy the application.
Example:
/home/admin/app/package.tgz.
Local machine: Select this option if the artifact package is already on the host and does not need to be downloaded.
Enter the absolute path of the artifact package on your host, such as /home/admin/app/package.tgz. The start script uses this path to deploy the application.
Execution user: The user that runs the scripts, such as
root.Start script: When deploying an application environment, this script runs on each host in the environment to start the service.
# A typical start script first extracts the artifact package to a specified directory, and then runs the startup file (usually maintained in your code, such as deploy.sh 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 startStop script: When deploying an application environment, this script runs on each host to stop the existing service before redeployment. When an application environment is deleted, this script runs to take the service offline.
if [ -d "/home/admin/application" ]; then if [ -f "/home/admin/application/deploy.sh" ]; then sh /home/admin/application/deploy.sh stop else echo "The /home/admin/application/deploy.sh script file is not found. The stop script is skipped." fi else echo "The /home/admin/application directory is not found. The stop script is skipped." fiHealth check script: If enabled, this script runs after the start script completes to verify the deployment's success. The script must exit with
exit 0to indicate a successful health check.# A typical health check script polls a request over a period of time and determines the service status based on the response. sh /home/admin/application/deploy.sh healthcheckCleanup script: If enabled, this script runs when an application environment is deleted. It executes after the service stops and performs post-processing tasks, such as deleting unused artifacts and log files from the host.
# A typical cleanup script cleans up unused artifact packages and log files in a specified directory. sh /home/admin/application/deploy.sh clearUse placeholders and variables
Built-in artifact placeholders: Alibaba Cloud DevOps AppStack provides built-in placeholders for artifacts. When you submit a deployment, AppStack recognizes parameters defined with an artifact placeholder such as
{{ .AppStack.artifact.xxx }}as artifacts. You can inject an artifact from an upstream pipeline build stage or manually enter the artifact download URL in the deployment.Custom placeholders: In your scripts, you can define placeholders for dynamic content or environment-specific configurations. Assign a variable group variable to the placeholder. You can then change the variable value or modify the parameter in the deployment.
On the Edit Application Orchestration page, configure the host deployment information on the left: set Artifact Type to HTTP, enter
{{ .AppStack.artifact.demoapp }}for Package Source,/home/admin/app/package.tgzfor Save Path, and root for Execution User. The start script creates a directory, extracts the artifact package, and runsdeploy.sh start. The stop script runssh /home/admin/application/deploy.sh stop. On the right, configure artifacts and placeholders: set the artifact name to artifact.demoapp. In the placeholders section, add envName (Type: String, Value Source: Variable). This lets you reference variables from a variable group through the placeholder. For example, you can define aportvariable in a variable group and set its value to8080for the development environment.
This completes the host deployment configuration for the sample Spring Boot application. For more information about environment deployment and maintenance, see Host Environment Deployment and O&M.