Updated on 2024-06-19 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: Deployment is triggered when any image tags are generated or updated.
    • Specific tag: Deployment is triggered when a specific image tag is generated or updated.
    • Tags matching regular expression: Deployment is triggered when an image tag that matches the 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 image v1. 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.

  2. Push the Nginx image v2 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, locate the trigger and click Records to check whether the trigger is successful.

    Figure 3 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 image v0. 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.

  2. Push the Nginx image v1 to SWR. The welcome page of the Deployment created using this new image should display Hello, SWR! (v1).

  3. Push the Nginx image v2 to SWR. The welcome page of the Deployment created using this new image should display Hello, SWR! (v2).

  4. Check whether the deployment is triggered successfully.

    On the Triggers tab page, click to check the result. As shown in Figure 4, only the deployment of the Nginx image v2 is triggered.

    Figure 4 Result

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