Use the publish feature of the Application Management Service to deploy a Java application to a group of Elastic Compute Service (ECS) instances. This service offers centralized, reusable workflows for publishing applications and managing their lifecycle across multiple servers, enhancing deployment efficiency and reliability.
Solution architecture
Application Management, Object Storage Service (OSS), and ECS work together to enable automated application deployment.
The core workflow is as follows:
-
Define the application and resources: Create an application and an application group in Application Management, and then import the target ECS instances into the group.
-
Prepare the deployment: Upload the application's JAR package to a bucket in OSS. Then, create a deployment for the application that contains the JAR package information and deployment scripts.
-
Execute the deployment: Use Application Management to publish the specified deployment to the target application group. Application Management uses automated tasks to download the deployment and start the application.
Key concepts
Applications, application groups, and deployments are the core concepts in Application Management:
-
Application: An application consists of an application program and the resources required for its deployment. It is managed and maintained as a single unit.
-
Application program: The program to be deployed, such as a web service, a machine learning model, or a database service.
-
Resources: The cloud resources required to deploy the application program, such as ECS instances, ESS scaling groups, or container clusters.
-
-
Application group: An application can be divided into multiple groups to isolate resources and configurations for different environments. For example:
-
By environment:
prod-group(production environment group) andpre-group(staging environment group). -
By region:
hangzhou-group(Hangzhou region group) andbeijing-group(Beijing region group). After you create the groups, you can import resources into each one.
-
-
Deployment: A deployment is a collection of the source files and the start/stop scripts for an application release. It contains all the information required for the release and is used for standardized, versioned application management. To release an application, you publish its deployment to an application group.
Procedure
-
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 an OSS deployment.
-
Download the official sample JAR package and upload it to OSS.
-
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 Type to OSS File. Configure the parameters, and then click OK.
-
OSS file information: Specify the OSS bucket and the file path of the JAR package.
If the ECS instance and the OSS bucket are in the same region, you can select internal network download to increase the download speed.
-
Working directory: Set the execution directory for the start and stop scripts. The OSS file is automatically downloaded to this directory. Example:
/root/deploy. -
Alibaba Cloud Linux
start_application() { set -e yum install -y maven-3.5.4 java -jar ./sample-spring-1.0-SNAPSHOT.jar & } start_applicationUbuntu
start_application() { set -e 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.