Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Adding an Image Retention Policy

Updated on 2024-06-19 GMT+08:00

Scenario

You can add a retention policy to an image in SWR to automatically delete any unused image tags. The policy takes effect immediately after you set it. There are two types of policies:

  • Number of days: keeping only image tags that have been pushed to SWR within a certain number of days.
  • Number of tags: keeping only a certain number of the most recent image tags.

You can configure filters for your retention policy to prevent certain image tags from being affected by the retention policy.

Notes and Constraints

Only one retention rule can be added to an image. If you want to add a new retention policy, you must delete the existing policy.

Procedure

  1. Log in to the SWR console.
  2. In the navigation pane on the left, choose My Images, and click the desired image to enter its details page.
  3. On the Retention tab page, click Add Retention Policy. Configure the policy based on Table 1 and click OK.

    Figure 1 Adding a retention policy
    Table 1 Parameters for adding an image retention policy

    Parameter

    Description

    Policy Type

    There are two types of retention policies:

    • Number of days: keeping only image tags that have been pushed to SWR within a certain number of days.
    • Number of tags: keeping only a certain number of the most recent image tags.

    Count Limit (Number of days)

    When you set Policy Type to Number of days, the value of Count Limit indicates the maximum number of the most recent image tags to be retained. The value should be an integer ranging from 1 to 365.

    Count Limit (Number of tags)

    When you set Policy Type to Number of tags, the value of Count Limit indicates the maximum number of the most recent image tags to be retained. The value should be an integer ranging from 1 to 1,000.

    Tag Filter

    Enter image tags that you do not want this retention policy to apply to.

    Regular Expression Filter

    Enter a regular expression. Image tags meeting this regular expression will not be affected by this retention policy.

    After the retention policy is added, SWR immediately applies the policy and displays deleted image tags (if any) in the Retention Logs area.

    Figure 2 Checking the retention policy and logs

Example 1: Set Policy Type to Number of Days

The update time of Nginx v1 image and Nginx v2 image is shown in the following figure.

Figure 3 Image tags
  1. Add a retention policy.

    Set Policy Type to Number of days, and Count Limit to 3.

    Figure 4 Adding a retention policy
  2. Check whether the retention policy has taken effect.

    Check Retention Logs. Nginx v1 image has been stored for more than three days (the current time is 2021/09/01 16:00:00). Therefore, it is automatically removed.

    Check Image Tag. Only Nginx v2 image is left.

    Figure 5 Image tag v2

    The retention policy has taken effect.

Example 2: Set Policy Type to Number of Tags, and Specify Regular Expression Filter

Click Image Tags tab page. Nginx v1 image, Nginx v2 image, Nginx v1.0.0 image and Nginx v2.0.0 image are shown in Image tags.

Figure 6 Nginx image tags
  1. Add a retention policy.

    Set Policy Type to Number of tags, Count Limit to 1, and Regular Expression Filter to ^v2.*.

    Figure 7 Adding a retention policy
  2. Check whether the retention policy has taken effect.

    Before the retention policy takes effect, Nginx v2 image and Nginx v2.0.0 image are filtered for matching the regular expression. Only one of Nginx v1 image and Nginx v1.0.0 image will be stored. Nginx v1 image will be removed because it is older.

    Check Retention Logs and Image Tag. If Nginx v1 image is removed, the retention policy has taken effect.

    Figure 8 Image tags

    The following regular expressions are for your reference:

    • ^[0-9]*$: filters out tags consisting of numbers.
    • ^.{2,5}$: filters out tags with a length ranging from 2 to 5 characters.
    • ^[a-z]+$: filters out tags consisting of lowercase letters.
    • ^[A-Za-z0-9]+$: filters out tags consisting of letters and numbers.
    CAUTION:

    If there is an OR (|) operator in a regular expression, enclose the OR part in parentheses, or the regular expression will be parsed incorrectly and all tags of the image will be removed.

    For example, if you only want to retain tags containing a or s, the regular should be (.*a.*|.*s.*).

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback