Updated on 2024-04-19 GMT+08:00

Adding a Trigger

Scenario

SWR works with Cloud Container Engine (CCE) to achieve automatic application update. When images are updated, these new images can be automatically deployed to update the applications that use these images. You only need to add a trigger to the desired images. Every time these images are updated, they can trigger automatic updates of the applications that use them.

Prerequisite

A containerized application has been created on CCE by using an image from SWR.

To create an application, log in to the CCE console and create a workload.

Procedure

  1. Log in to the SWR console.
  2. In the navigation pane on the left, choose My Images, and click the target image.
  3. Click the Triggers tab, then click Add Trigger. On the page displayed, configure the following parameters according to Table 1 and click OK.

    Table 1 Trigger

    Parameter

    Description

    Name

    The name can contain 1 to 64 characters, and must start with a letter. Only letters, digits, underscores (_), and hyphens (-) are allowed. The name cannot end with an underscore or hyphen. Consecutive underscores or hyphens are not allowed and an underscore cannot be placed next to a hyphen.

    Condition

    The following trigger conditions are supported:

    • All tags: Trigger when any image tags are generated or updated.
    • Specific tag: Trigger when a specific image tag is generated or updated.
    • Tags matching regular expression: Trigger when an image tag that matches the specified regular expression is generated or updated. The regular expression rules are as follows:
      • *: matches any field that does not contain the path separator /.
      • **: matches any field that contains the path separator /.
      • ?: Matches any single character except /.
      • {option 1, option 2, ...}: matches multiple options.

    Operation

    Operation that will be triggered when the conditions you set are met. Currently, only application update is supported. You need to specify the application to be updated and the container image of the application.

    Status

    Select Enable.

    Trigger Type

    Select CCE.

    Application

    Select the container whose image you want to update.

Example

A Deployment named nginx is created using the Nginx v1 image. The Deployment provides service to external systems with a welcome page displaying Hello, SWR!

Figure 1 Nginx deployment
  1. Add a trigger to the Nginx image.

    Set Name to All_tags, Condition to All tags, and select the application and all its containers that use the Nginx image.

  2. Check the image tags. The Nginx image v2 is pushed to SWR. The welcome page of the Deployment created using this new image should display Hello, SoftWare Repository for Container!
    Figure 2 Image tag v2

  3. Check whether the deployment is triggered successfully.

    On the Triggers tab page, click and the trigger is successful.

    The welcome page of the Deployment displays Hello, SoftWare Repository for Container!

    Figure 3 Updated Nginx