Version Retention
While using CCR, rapid iterations in your business often lead to the generation of numerous image versions. Over time, many outdated versions become obsolete. These redundant images not only accumulate storage costs but also complicate image management. You can utilize the version retention feature for regular cleanup.
Note
- By creating retention rules, image versions not covered by the rules will be automatically deleted when the rules are executed. Note: The version retention feature does not automatically free up storage space. To clean up storage space, please configure an artifact cleanup policy. For details, see: Artifact Cleanup
- Once the version retention rules are executed, deleted image versions cannot be re-pulled. To prevent accidental deletions, it is advisable to simulate the execution for critical images first. Proceed with the official execution only after fully understanding the scope of the cleanup.
- In some situations, different image versions in a repository may correspond to the same artifact. If one image version satisfies the cleanup criteria during rule execution, all versions linked to the same artifact will be deleted.
- It is not recommended to manually delete versions during retention rule execution, as this can lead to discrepancies between the retained versions and your expectations.
Prerequisites
- Successfully Create Enterprise Edition Instance.
- At least one image registry must exist in the instance. For details, refer to Manage Image Registry.
Operation steps
- Sign in to Baidu AI Cloud Console and select Product Service > Cloud Container Registry > CCR.
- Go to the target instance, click on Repository Management, and select Version Retention.
- Click the Create Rule button. After choosing a namespace, you can opt to create a retention rule via simple mode or advanced mode.
Simple mode
- Retained versions: By default, all repositories and versions in the namespace are included.
- Retention policy: Supports the following options (choose as needed): Retain the latest n pushed versions; retain versions pushed within n days; retain the latest n pulled versions; retain versions pulled within n days.
- Execution cycle: Options include manual execution, daily, weekly, or monthly execution. Daily: 00:00 every day; weekly: 00:00 every Monday (default); monthly: 00:00 on the 1st day of each month.
Advanced mode
- Repository filtering and version filtering: Supports regular expression matching.
- Retention policy: Supports the following options (choose as needed): Retain the latest n pushed versions; retain versions pushed within n days; retain the latest n pulled versions; retain versions pulled within n days.
- A maximum of 15 retention rules can be set. The final result is the union of multiple rules.
- Execution cycle: Options include manual execution, daily, weekly, or monthly execution. Daily: 00:00 every day; weekly: 00:00 every Monday (default); monthly: 00:00 on the 1st day of each month.
Once the rule is successfully created, you can view it on the Version Retention page and perform actions such as execution, editing, or deletion of existing rules.
Reference for version retention configuration
Regular expression
When configuring version retention rules in advanced mode and filling in the Repository and Version filter rules, the regular expressions support the following matching rules:
*: Matches any string of any length that does not contain the path separator (/).
**: Matches any string of any length, including the path separator (/).
Note:
** must be used as a complete relative path. For example, using /ccr** is equivalent to /ccr and only matches first-level repositories prefixed with “ccr”. To match all repositories under “ccr”, use /ccr/**; to match all repositories prefixed with “ccr”, use /ccr/**.
?: Matches any single character except /.
{str1, str1, …}: Matches multiple regular expressions simultaneously.
Typical scenarios
| Filter type | Scenario | Regular expression |
|---|---|---|
| Repository filter | Match all image repositories in the current namespace | ** or leave blank |
| Match all first-level repositories prefixed with “ccr” in the selected namespace | ccr* | |
| Match all first-level repositories prefixed with “ccr1” and “ccr2” in the selected namespace | {ccr1, ccr2} | |
| Match all repositories under the “ccr1” and “ccr2” directories in the selected namespace | {ccr1, ccr2}/** | |
| Match all repositories prefixed with “ccr1” and “ccr2” in the selected namespace | {ccr1, ccr2}*/** | |
| Version filter | Match all 1.x version tags in the selected repository | 1.? |
| Match all version tags prefixed with “dev1” and “dev2” in the selected repository | {dev1, dev2} |
FAQ
1. How to view retention results?
Details are shown below:
RETAIN: The corresponding image version will be retained.
DEL: The corresponding image version will be automatically deleted.
2. How to ensure that image cleanup does not accidentally delete important images?
Before executing image cleanup, it is recommended to perform a simulated execution to confirm the scope of images to be deleted and the cleanup time, ensuring no critical images are accidentally removed.
