Skip to content

Commit 051fdac

Browse files
committed
aws ecr tagging updates for canary
1 parent 955d019 commit 051fdac

File tree

4 files changed

+69
-43
lines changed

4 files changed

+69
-43
lines changed

ansible/ecr-lifecycle/ecr_lifecycle.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"rules": [
33
{
44
"rulePriority": 1,
5-
"description": "Keep the 10 most recent ECS deployment images - AMEND NUMBER AFTER TEST",
5+
"description": "Keep the 6 most recent ECS deployment images tagged ecs- (release images)",
66
"selection": {
77
"tagStatus": "tagged",
88
"tagPrefixList": ["ecs-"],
99
"countType": "imageCountMoreThan",
10-
"countNumber": 800
10+
"countNumber": 6
1111
},
1212
"action": { "type": "expire" }
1313
},
@@ -24,11 +24,11 @@
2424
},
2525
{
2626
"rulePriority": 3,
27-
"description": "Keep the 5 most recent build images (all tags) - AMEND NUMBER AFTER TEST",
27+
"description": "Keep the 6 most recent build images (all tags)",
2828
"selection": {
2929
"tagStatus": "any",
3030
"countType": "imageCountMoreThan",
31-
"countNumber": 800
31+
"countNumber": 6
3232
},
3333
"action": { "type": "expire" }
3434
}

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,28 @@
3030
with_items: "{{ new_repos }}"
3131
when: new_repos
3232

33-
- name: Read lifecycle policy file
34-
ansible.builtin.slurp:
35-
src: "{{ playbook_dir }}/ecr-lifecycle/ecr_lifecycle.json"
36-
register: desired_policy_raw
37-
when: new_repos | length > 0
38-
39-
- name: Decode lifecycle policy JSON
40-
set_fact:
41-
desired_policy_json: "{{ desired_policy_raw.content | b64decode | from_json }}"
42-
when: new_repos | length > 0
43-
44-
- name: Apply lifecycle policy to each new repo
45-
ansible.builtin.command: >
46-
{{ aws_cmd }} ecr put-lifecycle-policy
47-
--repository-name {{ item }}
48-
--lifecycle-policy-text '{{ desired_policy_json | to_json }}'
49-
with_items: "{{ new_repos }}"
50-
register: lifecycle_update
51-
ignore_errors: yes
52-
when: new_repos | length > 0
33+
# TO DO- Add back in once confirmed lifecycle policy to be applied to all new repos.
34+
35+
# - name: Read lifecycle policy file
36+
# ansible.builtin.slurp:
37+
# src: "{{ playbook_dir }}/ecr-lifecycle/ecr_lifecycle.json"
38+
# register: desired_policy_raw
39+
# when: new_repos | length > 0
40+
41+
# - name: Decode lifecycle policy JSON
42+
# set_fact:
43+
# desired_policy_json: "{{ desired_policy_raw.content | b64decode | from_json }}"
44+
# when: new_repos | length > 0
45+
46+
# - name: Apply lifecycle policy to each new repo
47+
# ansible.builtin.command: >
48+
# {{ aws_cmd }} ecr put-lifecycle-policy
49+
# --repository-name {{ item }}
50+
# --lifecycle-policy-text '{{ desired_policy_json | to_json }}'
51+
# with_items: "{{ new_repos }}"
52+
# register: lifecycle_update
53+
# ignore_errors: yes
54+
# when: new_repos | length > 0
5355

5456
- name: ecr login
5557
shell: "eval $({{ aws_cmd }} ecr get-login --no-include-email)"

ansible/roles/deploy-ecs-proxies-retag/tasks/main.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- name: Pull existing image
3131
ansible.builtin.command:
3232
cmd: >
33-
docker pull {{ ecr_registry }}/{{ item }}:{{ build_label }}
33+
docker pull --platform=all {{ ecr_registry }}/{{ item }}:{{ build_label }}
3434
loop: "{{ repo_names }}"
3535
loop_control:
3636
label: "{{ item }}"
@@ -42,7 +42,9 @@
4242
loop: "{{ pull_results.results }}"
4343
loop_control:
4444
label: "{{ item.item }}"
45-
when: item.rc == 0
45+
when:
46+
- item.rc == 0
47+
- item.item == "canary_canary-api"
4648

4749
- name: Retag image
4850
ansible.builtin.command:
@@ -53,15 +55,19 @@
5355
loop: "{{ pull_results.results }}"
5456
loop_control:
5557
label: "{{ item.item }}"
56-
when: item.rc == 0
58+
when:
59+
- item.rc == 0
60+
- item.item == "canary_canary-api"
5761

5862
- name: Debug pushing image
5963
debug:
6064
msg: "Pushing ecs-{{ build_label }} for {{ item.item }}"
6165
loop: "{{ pull_results.results }}"
6266
loop_control:
6367
label: "{{ item.item }}"
64-
when: item.rc == 0
68+
when:
69+
- item.rc == 0
70+
- item.item == "canary_canary-api"
6571

6672
- name: Push new tag
6773
ansible.builtin.command:
@@ -70,7 +76,20 @@
7076
loop: "{{ pull_results.results }}"
7177
loop_control:
7278
label: "{{ item.item }}"
73-
when: item.rc == 0
74-
75-
79+
when:
80+
- item.rc == 0
81+
- item.item == "canary_canary-api"
7682

83+
- name: Delete old tag from ECR
84+
ansible.builtin.command:
85+
cmd: >
86+
aws ecr batch-delete-image
87+
--repository-name {{ item.item }}
88+
--image-ids imageTag={{ build_label }}
89+
--region {{ aws_region }}
90+
loop: "{{ pull_results.results }}"
91+
loop_control:
92+
label: "{{ item.item }}"
93+
when:
94+
- item.rc == 0
95+
- item.item == "canary_canary-api"

ansible/roles/deploy-ecs-proxies/templates/terraform/locals.tf

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,23 @@ locals {
4343

4444
}
4545

46-
ecs_service = [
47-
{% for container in ecs_service %}
48-
{{
49-
(
50-
container
51-
| combine(
52-
{'image': '${local.account_id}.dkr.ecr.eu-west-2.amazonaws.com/' + service_id + '_' + container.name + ':ecs-' + build_label }
53-
)
54-
) | to_json
55-
}},
56-
{% endfor %}
57-
]
46+
ecs_service = [
47+
{% for container in ecs_service %}
48+
{{
49+
(
50+
container
51+
| combine(
52+
{
53+
'image':
54+
'${local.account_id}.dkr.ecr.eu-west-2.amazonaws.com/'
55+
+ service_id + '_' + container.name
56+
+ (container.name == "canary_canary-api" ? ':ecs-' + build_label : ':' + build_label)
57+
}
58+
)
59+
) | to_json
60+
}},
61+
{% endfor %}
62+
]
5863

5964
exposed_service = element(matchkeys(local.ecs_service, local.ecs_service.*.expose, list(true)), 0)
6065

0 commit comments

Comments
 (0)