All Products
Search
Document Center

CloudOps Orchestration Service:Build a software package, upload it to OSS, and then deploy it on ECS instances

Last Updated:Apr 09, 2025

This sample template is used to pull code by using Git, build a software package from the code, upload the software package to Object Storage Service (OSS), and then deploy the software package on multiple Elastic Compute Service (ECS) instances at a time. The system can build the software package on an existing ECS instance or create an ECS instance for building the software package. After the software package is built, the created ECS instance is automatically released.

Prerequisites

Sample template

image
  1. You specify the code source, such as Object Storage Service (OSS) or GitHub. CloudOps Orchestration Service (OOS) generates a temporary URL for the code source to pull code from the code source.

  2. Build a software package such as a JAR package and upload it to OSS.

  1. Pull the software package and deploy it on multiple ECS instances.

Example

Prepare the code source

The sample code of a Spring Boot project is used in this example. The code is uploaded to Gitee and GitHub. If you want to use the code, you must fork the code to your own repository. Code address:

  • Gitee: Sample code (recommended for users in the Chinese mainland)

  • GitHub:Sample code (recommended for users in the Chinese mainland)

Create a template

  1. Log on to the CloudOps Orchestration Service console.

  2. In the left-side navigation pane, choose Automated Task > Custom Template and click Create Template.

  3. In the Build and Deploy section, select ACS-ECS-ExampleSoftwarePackageBuildAndDeployFromGit and click Next.

  4. On the Process Configuration tab, set the parameters and click Create Template.

    1. Specify the code source to generate a temporary authorization link.

      In this example, Gitee is used as the code source. Set the following parameters: Owner, Organization, Repository, and Branch.

      Note
      • If Alibaba Cloud is not authorized to access your GitHub or Gitee repository, click Grant the required permissions.

      • If you have forked the sample code, all repositories that belong to your account are automatically displayed in the Repository drop-down list. In this case, select the repository to which you forked the code.

      2024-12-16_11-42-41.png

    2. Build a software package such as a JAR package and upload it to OSS.

      1. Select the code source and the ECS instance, and then provide the build command.

        oss.png

        • CodeResource: In this example, git is selected. The output of the previous task is used, which is authorizedUrl.

        • Choose Building Ecs: Select an ECS instance. You can select Existing ECS or New ECS.

          Note

          If you select New ECS, you are charged on a pay-as-you-go basis. OOS automatically checks whether Docker is installed on the ECS instance. If Docker is not installed, OOS automatically installs Docker Community Edition on the ECS instance.

        • Build Configuration: provides build commands as needed.

          If you execute this sample template, Maven will be first installed and a JAR package will be created. The JAR package is in the target directory. You can replace the sample with a script that meets your requirements.

          Sample script (Alibaba Cloud Linux 3)

          ### sample build script
          set -e
          yum install -y maven-3.5.4
          mvn package

          Sample script (Ubuntu)

          ### sample build script
          set -e
          apt install -y maven
          mvn package

          Sample script (CentOS)

          ### sample build script
          set -e
          yum install -y maven
          mvn package
      2. Provide the package path and build name.

        In the following example, the package path is target/. OOS will compress the package into a .tgz file.

        构建物.png

    3. Upload the build output to OSS.

      Specify the OSS bucket and object path to which you want to upload the software package.

      goujianwu --oos.png

      In the Task Output(Optional) section, add bucketName (the name of the OSS bucket) and objectName (the full path of the build in the bucket, including the directory and the name of the build) for subsequent tasks. You can directly use the outputs for subsequent tasks.

    4. Deploy the software package on multiple ECS instances that run Linux.

      目标ECS.png

      • Target Instance: Select the ECS instances on which you want to deploy the package.

      • OSS: The information about the OSS bucket to which the build belongs. The OSS bucket name and OSS object name are referenced by default. You do not need to specify them repeatedly. You also need to specify the directory to download the package. In this example, /home/admin/app/ is used.

      • Deployment Script: You can provide a deployment script based on your requirements.

        In this example, the .tgz file is decompressed to the specified path and the java -jar command is used to run the JAR package by using port 8080.

    5. Optional. Set the concurrency control parameters to control the concurrency rate of multiple ECS instances.

    6. Click Create Template.

Execute the template

  1. Log on to the CloudOps Orchestration Service console.

  2. In the left-side navigation pane, choose Automated Task > Custom Template.

  3. On the Custom Template page, find the template and click Create Execution in the Actions column.

  4. In the Basic Information step, set the parameters and click Next Step: Parameter Settings.

  5. In the Parameter Settings step, click OK if no parameters are available.

  6. Click Create.

    On the Task Execution Management page, if the execution status is Success, the execution is complete.

    执行模板结果-zh.png

  7. Log on to the ECS console.

  8. Find the ECS instance and connect to the instance.

    For more information, see Use Workbench to connect to a Linux instance over SSH.

  9. Run the following command to check whether the deployment is successful.

    curl http://localhost:8080/hello

    If the following message is returned, the deployment is successful.image

    Note

    If the message Failed to connect to localhost port 8080:Connection refused is returned, the possible cause is that Java is not installed on your ECS instance. Run the yum install java command and check again.

What to do next

If you update your code in the future, you need to only push your updated code to the corresponding Git repository and execute this template again. Then, your latest code is automatically pulled from the repository, packaged, uploaded to OSS, and then deployed on the ECS instances. If you want to modify the template, you can modify the template and then execute the template.