New image tags are created as services evolve. As the number of image tags grows, storage costs and quota usage also increase. This may eventually cause image pushes to fail. Regularly removing unneeded image tags can effectively prevent such issues.
Scenario introduction
Each OCI artifact repository in CR can store only a limited number of image tags. After this limit is exceeded, images with new tags cannot be pushed. Too many image tags increase both image maintenance efforts and storage costs. We recommend that you use tag retention to automatically clean up image tags. This helps maintain sufficient image tag quota and prevent image push failures. This topic uses a cleanup policy based on regular expression matching as an example. At 00:00 every Sunday, the policy retains images with tags starting with tag in the repo OCI artifact repository. For example, images with tags such as tag1 and tag2 are retained.
Feature introduction
Image cleanup methods are flexible and can meet image cleanup requirements in different scenarios. Images can currently be cleaned up by quantity, time, or regular expression matching. Cleanup can be performed at the instance, namespace, or OCI artifact repository scope.
- Quantity-based: Retain only a specified number of the most recently pushed image tags and remove all others. For example, retain the latest 100 image tags.
- Time-based: Retain only image tags pushed within a specified number of days and remove all others. For example, retain image tags from the past month.
- Regular expression matching: Retain required image tags by using regular expressions. The expressions match image tag names, such as latest and v*.
- Instance: Perform cleanup within a single instance.
- Namespace: Perform cleanup within a single namespace.
- OCI artifact repository: Perform cleanup in one or more OCI artifact repositories within a specified namespace.
Prerequisites
Procedure
Step 1: Create a tag retention rule
- Select the target region in the top navigation bar.
- In the left navigation bar, click Tag retention.
- On the Tag retention rule page, click Create tag retention rules.
- Configure the tag retention rule parameters. This topic describes only the parameters relevant to this scenario. For details about other parameters, see Creating tag retention rules.
- Click Confirm to complete the operation.
Step 2: Execute the rule
Rules configured with timed triggers can also be triggered manually.
- Automatic execution: Cleanup is automatically performed at 00:00 every Sunday, as configured in this example. On the "Tag retention rule" page, view the scheduled execution time in the Trigger method column.
- Manual execution: You can manually trigger image cleanup. On the "Tag retention rule" page, click Execute in the Actions column. Then, click Confirm on the confirmation page.
Step 3: View cleanup records
- On the Tag retention rule page, click the name of the target rule.
- Click the ID of the target execution task to view information about retained or cleared images.