Automatically create an image cache after you push an image to an ACR Enterprise Edition instance

Updated at:

With Alibaba Cloud EventBridge, Container Compute Service (ACS) can automatically create an image cache from an image when you push it to a Container Registry (ACR) Enterprise Edition instance. The image cache accelerates image pulls and improves pod startup speed.

Prerequisites

Step 1: Configure an ACR instance

  1. Log on to the Container Registry console.

  2. In the left-side navigation pane, click Instances.

  3. On the Instances page, click the Enterprise Edition instance that you want to manage.

  4. In the left-side navigation pane of the Enterprise Edition instance management page, choose Repository > Access Control. Then, on the VPC tab, click Add VPC to add the VPC that you created.

  5. Click Instances > Event Notification, and then click Create Rule. For Event Type, select cr:Artifact:PushCompleted. Then, as needed, select Effective Scope.

    Event Notification configuration does not affect subsequent operations. You only need to complete the configuration.

Step 2: Create a RAM policy

  1. Log on to the Resource Access Management (RAM) console as a RAM administrator.

  2. In the left-side navigation pane, choose Permissions > Policies.

  3. On the Policies page, click Create Policy.

  4. On the Create Policy page, click the JSON Editor tab.

  5. Enter the content of the policy, and then click OK.

    {
      "Version": "1",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": "acc:CreateImageCache",
          "Resource": "*"
        },
        {
          "Action": "ram:CreateServiceLinkedRole",
          "Resource": "*",
          "Effect": "Allow",
          "Condition": {
            "StringEquals": {
              "ram:ServiceName": "imc.acc.aliyuncs.com"
            }
          }
        }
      ]
    }
  6. Enter the Policy Name and Description, and then click OK.

Step 3: Configure EventBridge

  1. Log on to the EventBridge console.

  2. In the top menu bar, select the same region as the VPC.

  3. In the left-side navigation pane, click Event Buses.

  4. In the Actions column of the default event bus, click Event Rules. In the rule list, you can see the event rule that you created in Step 1: Configure an ACR instance. In the Operations column of the rule, click Edit Targets. Then, click Add Target and set the following options:

    Option

    Value

    Event Source

    acr.cr

    Event Type

    cr:Artifact:PushCompleted

    Service Type

    acs.openapi.acc

    API Type

    CreateImageCache

    RegionId

    Select Template:

    • Variables:

      {
        "InstanceName":"$.data.InstanceName",
        "RegionId":"$.data.RegionId",
        "RepoName": "$.data.RepoName",
        "RepoNamespaceName": "$.data.RepoNamespaceName",
        "Tag": "$.data.Tag"
      }
    • Template

      ${RegionId}

    ImageCacheName

    Select Template:

    • Variables:

      {
        "InstanceName":"$.data.InstanceName",
        "RegionId":"$.data.RegionId",
        "RepoName": "$.data.RepoName",
        "RepoNamespaceName": "$.data.RepoNamespaceName",
        "Tag": "$.data.Tag"
      }
    • Template

      ${RepoNamespaceName}-${RepoName}-${Tag}

    Images

    Select Template:

    • Variables:

      {
        "InstanceName":"$.data.InstanceName",
        "RegionId":"$.data.RegionId",
        "RepoName": "$.data.RepoName",
        "RepoNamespaceName": "$.data.RepoNamespaceName",
        "Tag": "$.data.Tag"
      }
    • Template

      ${InstanceName}-registry-vpc.${RegionId}.cr.aliyuncs.com/${RepoNamespaceName}/${RepoName}:${Tag}

    NetworkConfig

    • VSwitchIds: Enter the ID of the vSwitch that you prepared in advance.

    • SecurityGroupId: Enter the ID of the security group that you prepared in advance.

    Role

    Click Authorization. Then, log on to the RAM console as a RAM administrator and grant the newly created role (AliyunEventBridgeOpenApi-******) the permissions created in Step 2.

    Retry Policy and Dead-letter Queue

    Select Exponential Decay Retry and Fault Tolerance Allowed.

Step 4: Verify the result

Push an image to the ACR Enterprise Edition instance, and then log on to the ACS console . In the left-side navigation pane, choose Image Cache and check whether the image cache is automatically created.

References

For information about the billing rules of EventBridge, see Billing Overview.