Updating a lifecycle policy
Once you create a lifecycle policy, you can modify its rules as well as its status, name, or description.
To access the policy, use its ID. For information about getting a policy ID, see Getting information about lifecycle policies.
If you don't have the Yandex Cloud command line interface yet, install and initialize it.
-
See the description of the CLI command for updating policy parameters:
yc container repository lifecycle-policy update --help
-
Change the policy parameters, such as by renaming it:
yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --new-name new-policy
To edit a lifecycle policy, use the Update method for the LifecyclePolicyService resource. Specify the policy ID in the lifecycle_policy_id
property.
You can retrieve a list of policies using the List method for the LifecyclePolicyService resource.
Warning
You can only set a lifecycle policy for a repository. The policy applies to Docker images whose names match the repository name exactly. There is no support for prefix matching. You can't set a policy for a repository group, registry, folder, or cloud.
Examples
Updating lifecycle policy rules
-
Prepare new policy rules and save them to a file named
new-rules.json
.Example of the contents of a file with rules, where:
description
: Description of the policy rule.tag_regexp
: Docker image tag for filtering. Atest.*
regular expression fortag_regexp
lets you get all images with tags starting withtest
.untagged
: Flag indicating that the rule applies to Docker images without tags.expire_period
: Time after which the lifecycle policy may apply to the Docker image. Parameter format: Number and unit of measurements
,m
,h
, ord
(seconds, minutes, hours, or days).expire_period
must be a multiple of 24 hours.retained_top
: Number of Docker images that are not deleted even if they match the rule.
[ { "description": "delete prod Docker images older than 60 days but retain 20 last ones", "tag_regexp": "prod", "expire_period": "60d", "retained_top": 20 }, { "description": "delete all test Docker images except 10 last ones", "tag_regexp": "test.*", "retained_top": 10 }, { "description": "delete all untagged Docker images older than 48 hours", "untagged": true, "expire_period": "48h" } ]
-
Change the policy rules by running the command with the following parameter:
new-rules
: Path to the file with the new policy description.
Alert
Updating the policy completely overwrites all current rules by destroying them.
yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --new-rules ./new-rules.json
Result:
WARN: All current lifecycle rules will be overwritten. Are you sure?[y/N] y id: crp6lg1868p3i0emkv1b name: test-policy ... expire_period: 172800s tag_regexp: test.* untagged: true
Updating a lifecycle policy status
Activate a lifecycle policy
Activate a deactivated lifecycle policy by running the command below with the --activate
flag:
yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --activate
Result:
id: crp6lg1868p3i0emkv1b
name: test-policy
repository_id: crp3cpm16edqql0t30s2
...
expire_period: 172800s
tag_regexp: test.*
untagged: true
Disable a lifecycle policy
Deactivate an active policy by running the command below with the --disable
flag:
yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --disable
Result:
id: crp6lg1868p3i0emkv1b
name: test-policy
repository_id: crp3cpm16edqql0t30s2
...
expire_period: 172800s
tag_regexp: test.*
untagged: true
Updating a lifecycle policy name
Change the policy name by running the command:
yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --new-name new-policy
Where new-name
is the new policy name.
{% include [name-format](../../../_includes/name-format.md) %}
Result:
id: crp6lg1868p3i0emkv1b
name: new-policy
repository_id: crp3cpm16edqql0t30s2
...
expire_period: 172800s
tag_regexp: test.*
untagged: true
Updating a lifecycle policy description
Change the policy description by running the command:
yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --new-description "new description"
Where new-description
is the new policy description.
Result:
id: crp6lg1868p3i0emkv1b
name: test-policy
repository_id: crp3cpm16edqql0t30s2
...
expire_period: 172800s
tag_regexp: test.*
untagged: true