Skip to content

Commit 9378fe7

Browse files
committed
APM 6720 ecr lifecycle policy
1 parent 7eac65b commit 9378fe7

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

ansible/roles/build-ecs-proxies/tasks/build-container.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@
3131
ansible.builtin.command:
3232
cmd: "docker push {{ image_name }}"
3333
when: build_result.rc == 0
34+
35+
- name: Apply lifecycle policy to ecr {{ service_id }}_{{ item }}
36+
ansible.builtin.command:
37+
cmd: >
38+
{{ aws_cmd }} ecr put-lifecycle-policy
39+
--repository-name {{ service_id }}_{{ item }}
40+
--lifecycle-policy-text file://{{ base_dir }}/ecr/ecr_lifecycle.json
41+
when: lifecycle_check.rc != 0 and build_result.rc == 0

ecr/ecr_lifecyle.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"rules": [
3+
{
4+
"rulePriority": 1,
5+
"description": "Expire untagged images beyond the latest 3",
6+
"selection": {
7+
"tagStatus": "untagged",
8+
"countType": "imageCountMoreThan",
9+
"countNumber": 10
10+
},
11+
"action": {
12+
"type": "expire"
13+
}
14+
},
15+
{
16+
"rulePriority": 2,
17+
"description": "Retain ECS-protected images",
18+
"selection": {
19+
"tagStatus": "tagged",
20+
"tagPrefixList": ["ecs-"],
21+
"countType": "imageCountMoreThan",
22+
"countNumber": 9999
23+
},
24+
"action": {
25+
"type": "retain"
26+
}
27+
}
28+
]
29+
}

0 commit comments

Comments
 (0)