Use EventBridge to automatically create ACS image caches when images are pushed to a Container Registry (ACR) Enterprise Edition instance. Image caches speed up pod startup by eliminating full image pulls.
How it works
Three services form an event-driven pipeline:
-
ACR Enterprise Edition detects an image push and emits a
cr:Artifact:PushCompletedevent. -
EventBridge receives the event on the default event bus and invokes the ACS
CreateImageCacheAPI with parameters extracted from the event payload. -
ACS creates an image cache from the pushed image for fast pod startup.
Each push triggers one CreateImageCache call. Frequent pushes increase image cache storage costs and EventBridge fees.
Prerequisites
Prepare the following resources:
|
Resource |
Description |
|
Personal Edition instances are not supported. |
|
|
Record the vSwitch ID for later use. |
|
|
Security group |
Must belong to the VPC above. Record the security group ID for later use. |
Step 1: Configure the ACR instance
Log on to the Container Registry console.
In the left-side navigation pane, click Instances.
On the Instances page, click the Enterprise Edition instance that you want to manage.
-
In the left-side navigation pane, choose . On the VPC tab, click Add VPC and add the VPC that you prepared.
-
In the left-side navigation pane, choose . Click Create Rule, and configure the following settings:
-
Event Type: Select
cr:Artifact:PushCompleted. -
Effective Scope: Select the repositories to monitor, or select all.
-
Event Notification: Select DingTalk, HTTP, or HTTPS.
The notification endpoint does not need to be functional. This step only generates an event for EventBridge to capture.
-
Step 2: Create a RAM policy
Create a custom policy that allows calling the ACS CreateImageCache API.
-
Log on to the RAM console as a RAM administrator.
-
In the left-side navigation pane, choose Permissions > Policies.
-
On the Policies page, click Create Policy.
-
On the Create Policy page, click JSON Editor.
-
Paste the following policy, then click OK:
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": "acc:CreateImageCache", "Resource": "*" }, { "Effect": "Allow", "Action": "ram:CreateServiceLinkedRole", "Resource": "*", "Condition": { "StringEquals": { "ram:ServiceName": "imc.acc.aliyuncs.com" } } } ] } -
Enter a policy name and optional description, then click OK.
Step 3: Configure EventBridge
Step 1 created an event rule in the default event bus. Edit this rule to add a target that calls the ACS CreateImageCache API.
Log on to the EventBridge console.
-
In the top navigation bar, select the same region as your VPC.
In the left-side navigation pane, click Event Buses.
-
In the default event bus row, click Event Rules in the Actions column. Find the event rule created in Step 1, click Edit Targets, then click Add Target.
Parameter
Value
Service Type
acs.openapi.accAPI Type
CreateImageCacheRegionId
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 vSwitch ID that you prepared.
-
SecurityGroupId: Enter the security group ID that you prepared.
Role
Click Authorization, EventBridge creates a role named
AliyunEventBridgeOpenApi-******. Log on to the RAM console as a RAM administrator, find this role, and attach the policy from 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. Log on to the ACS console, click Image Cache in the left-side navigation pane. Verify that a new image cache appears with a name in the format <namespace>-<repo>-<tag>.