Automatically create an image cache after you push an image to an ACR Enterprise Edition instance
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
-
You have created an ACR Enterprise Edition instance .
-
You have created a Virtual Private Cloud (VPC) and a vSwitch. For instructions, see VPCs and vSwitches. You have also configured a security group.
Step 1: Configure an 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 of the Enterprise Edition instance management page, choose . Then, on the VPC tab, click Add VPC to add the VPC that you created.
-
Click , 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
-
Log on to the Resource Access Management (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 the JSON Editor tab.
-
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" } } } ] } -
Enter the Policy Name and Description, and then click OK.
Step 3: Configure EventBridge
Log on to the EventBridge console.
-
In the top menu bar, select the same region as the VPC.
In the left-side navigation pane, click Event Buses.
-
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.