Updated on 2023-08-03 GMT+08:00

Adding a Trigger

Scenario

SWR works with Cloud Container Engine (CCE) to enable automatic application updates. This could be realized by adding a trigger to the desired images.

Prerequisite

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

If no applications have been created, log in to the CCE console and create one. For details, see Creating a Deployment or Creating a StatefulSet.

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.

    Figure 1 Adding a trigger
    Table 1 Trigger

    Parameter

    Description

    Name

    The name of a trigger.

    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

    Currently, only operation of updating images will be triggered. You need to specify the application to be updated and the container of the application.

    Status

    Select Enable.

    Trigger Type

    Select CCE.

    Application

    Select the container whose image you want to update.

Example 1: The trigger condition is All tags.

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!

  1. Add a trigger to the Nginx image.

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

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

    On the Triggers tab page, click to check whether the trigger is Successful.

    Figure 4 Result

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

Example 2: The trigger condition is Tags matching regular expression.

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!

  1. Add a trigger to the Nginx image.

    Set Name to Tags_regular_expression, Condition to Tags matching regular expression, regular expression to ^v2.*, and select the application and all its containers that use the Nginx image.

    Figure 5 Selecting Tags matching regular expression
  2. The Nginx v1.0.0 image is pushed to SWR. The welcome page of the Deployment created using this new image should display Hello, SWR! (v1.0.0).
    Figure 6 Image tag v1.0.0
  3. The Nginx v2.0.0 image is pushed to SWR. The welcome page of the Deployment created using this new image should display Hello, SWR! (v2.0.0).
    Figure 7 Image tag v2.0.0
  4. Check whether the Deployment is triggered successfully.

    On the Triggers tab page, click to check the result. As shown in Figure 8, only the result of Nginx v2.0.0 image is successful.

    Figure 8 Result

    The welcome page of the Deployment displays Hello, SWR! (v2.0.0).