Build and deploy an SAE application with a pipeline

更新时间:
复制 MD 格式

You can use an Alibaba Cloud DevOps pipeline to deploy an SAE application. This automates testing code, building an image, and deploying the SAE application with phased or canary releases.

Prerequisites

Upload source code to a code repository

Alibaba Cloud DevOps pipelines support various code repositories as code sources.

To get started quickly, upload the following sample code to your code repository: nodejs-helloworld.zip.

After completing this tutorial, you can upload your application code, including the required Dockerfile, to deploy your own application.

Configure the pipeline

Step 1: Create a pipeline from a template

  1. Log on to the Flow console.

  2. On the My Pipelines page, click Create Pipeline in the upper-right corner.

  3. In the Select a Pipeline Template dialog box:

    1. At the top, select Visual Orchestration.

    2. In the left pane, select Node.js, and then select the Node.js · Test, Build Image template.

    3. Click Create to go to the Flow Configuration page of the pipeline.

Step 2: Add a pipeline source

  1. In the Pipeline Source section, click Add Pipeline Source.

  2. In the Add Pipeline Source panel:

    1. In the left pane, select Code Source.

    2. Select Code Source: Select your code repository type. This tutorial uses GitHub as an example.

    3. Click Add Service Connection:

      1. Service Authorization/Certificate: If one does not exist, click New and follow the on-screen instructions to create a Service Authorization/Certificate.

      2. Click Create.

    4. Select the Namespace, Repository, and Default Branch where your source code is located.

    5. Enable Code Source Trigger: If enabled, code commits automatically trigger the pipeline. For more information, see Code Source Trigger.

    6. Click Add.

Step 3: Configure tests

  1. In the Test stage, click the JavaScript code scan task:

    1. Build Cluster: For repositories in a region within the Chinese mainland, select Alibaba Cloud DevOps build cluster (Beijing) or Alibaba Cloud DevOps build cluster (Hangzhou). For repositories outside the Chinese mainland, select Alibaba Cloud DevOps build cluster (China (Hong Kong)).

    2. Specify Build Node: Select Linux/amd64.

    3. Build Environment: Select Specify Container Environment.

    4. Container Image Address: Select build-steps/alinux3.

    5. Task Steps: This tutorial runs the default JavaScript code scan. In a real-world scenario, configure this step as needed.

  2. In the Test stage, click the Node.js Unit Test task:

    1. This tutorial does not require a unit test, so you can click the delete button at the top of the task. In a real-world scenario, configure this step as needed.

    2. Click OK.

Step 4: Configure image building

  1. In the Build Image stage, click the build and push image to ACR (Personal Edition) task.

  2. In the panel that appears, configure the following parameters:

    1. Build Cluster: For code repositories and base images in a region within the Chinese mainland, select Alibaba Cloud DevOps build cluster (Beijing) or Alibaba Cloud DevOps build cluster (Hangzhou). For those outside the Chinese mainland, select Alibaba Cloud DevOps build cluster (China (Hong Kong)).

    2. Specify Build Node: Select Linux/amd64.

    3. Build Environment: Select Specify Container Environment.

    4. Container Image Address: Select build-steps/alinux3.

    5. Task Steps: This tutorial uses the build and push image to ACR (Personal Edition) step as an example. If you are using an ACR Enterprise Edition instance, delete the default step, click Add Step, and then select Build > build and push image to ACR (Enterprise Edition).

    6. Click Add Service Connection:

      1. Service Authorization/Certificate: If one does not exist, click New and follow the on-screen instructions to create a Service Authorization/Certificate.

      2. Click Create.

    7. Select the region and Repository of your target image repository.

    8. Tag: Set this to ${DATETIME}. This automatically generates an image tag based on the date and time.

    9. Dockerfile Path: Set this to Dockerfile. This means the Dockerfile is in the root directory of your code repository.

    10. Image Cache: For this tutorial, select Do not use cache.

    11. Keep the default values for the remaining parameters.

Step 5: Configure SAE deployment

  1. In the New Stage section, click New Task.

  2. In the panel that appears, enter SAE in the search box and select the Serverless (SAE) application deployment task:

    1. Build Cluster: For image repositories in a region within the Chinese mainland, select Alibaba Cloud DevOps build cluster (Beijing) or Alibaba Cloud DevOps build cluster (Hangzhou). For those outside the Chinese mainland, select Alibaba Cloud DevOps build cluster (China (Hong Kong)).

    2. Specify Build Node: Select Linux/amd64.

    3. Build Environment: Select Specify Container Environment.

    4. Container Image Address: Select build-steps/alinux3.

    5. Click Add Service Connection:

      1. Service Authorization/Certificate: If none exists, click New and follow the prompts to create a Service Authorization/Certificate.

      2. Click Create.

    6. Select the region and namespace of your target SAE application, and then select the SAE application.

    7. Build Artifact: Select build and push image to ACR (Personal Edition).Image Public URL or build and push image to ACR (Enterprise Edition).Image Public URL.

    8. If you are using an ACR Enterprise Edition instance, select the Use Alibaba Cloud Container Registry Enterprise Edition checkbox and enter the ACR (Enterprise Edition) Instance ID.

    9. Configure the Release Policy and its parameters. This tutorial uses the following configuration. For more information, see phased release and canary release.

      1. Release Policy: Phased release

      2. Batch Method: Automatic Confirmation

      3. Deployment Batches: 1 batch

      4. Keep the default values for the remaining parameters.

Run the pipeline

  1. In the upper-right corner, click Save and Run.

  2. In the run configuration panel that appears:

    1. Select the Branch/Tag of your Code Source.

    2. (Optional) Enter Run Comments.

  3. Click Run and wait for the pipeline to finish.

    After the pipeline runs successfully, all three stages are marked as passed: JavaScript code scan (Test stage), build and push image to ACR (Personal Edition) (Build Image stage), and Serverless (SAE) application deployment (New stage). The total duration is about 1 minute and 55 seconds.

  4. View Logs: Click Logs for each node.

  5. View Deployment Order Details: Click Deployment Order Details on the Serverless (SAE) application deployment node.

    On the change details page, the execution status is Succeeded, the change type is Deploy Application, and the description is Version: 2025-11-28-09-49-17 | Image Name: nodejs-helloworld. The deployment is performed in a single batch with automatic confirmation. The deployment process for the first batch includes steps such as initializing the environment (0.92s), initializing the container image service network (0.08s), synchronizing the container image service network (0.09s), creating or updating the deployment configuration (1.29s), and deploying the application (22.72s). All steps are successful, and the total duration is about 25 seconds.