Skip to content

Commit 36a9023

Browse files
committed
ecs updates
1 parent 11d0d9c commit 36a9023

File tree

5 files changed

+38
-63
lines changed

5 files changed

+38
-63
lines changed

ansible/deploy-ecs-proxies.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@
4545

4646
roles:
4747
- setup-facts
48+
- deploy-ecs-proxies-retag
4849
- deploy-ecs-proxies

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

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

33-
# TEST REPO (override this for testing) - DELETE
34-
35-
- set_fact:
36-
test_repo: "canary_canary-api"
37-
3833
- name: Read lifecycle policy file
3934
ansible.builtin.slurp:
4035
src: "{{ playbook_dir }}/ecr-lifecycle/ecr_lifecycle.json"
4136
register: desired_policy_raw
42-
# when: new_repos # Uncomment
43-
44-
- name: Debug raw slurp output
45-
debug:
46-
var: desired_policy_raw
37+
# when: new_repos UNCOMMENT
4738

4839
- name: Decode lifecycle policy JSON
4940
set_fact:
5041
desired_policy_json: "{{ desired_policy_raw.content | b64decode | from_json }}"
51-
# when: new_repos # Uncomment
42+
# when: new_repos UNCOMMENT
5243

53-
- name: Debug decoded lifecycle policy JSON
54-
debug:
55-
var: desired_policy_json
56-
57-
- name: Apply lifecycle policy to ECR repo
44+
- name: Apply lifecycle policy to each new repo
5845
ansible.builtin.command: >
5946
{{ aws_cmd }} ecr put-lifecycle-policy
60-
--repository-name {{ test_repo }}
47+
--repository-name {{ item }}
6148
--lifecycle-policy-text '{{ desired_policy_json | to_json }}'
49+
with_items: "{{ new_repos }}"
6250
register: lifecycle_update
63-
# ignore_errors: yes
64-
# with_items: "{{ new_repos }}" # Uncomment
65-
# when:
66-
# - new_repos # Uncomment
67-
68-
- name: Debug lifecycle update result
69-
debug:
70-
var: lifecycle_update
51+
ignore_errors: yes
52+
# when: new_repos UNCOMMENT
7153

7254
- name: ecr login
7355
shell: "eval $({{ aws_cmd }} ecr get-login --no-include-email)"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- name: Pull existing image {{ item }}:{{ build_label }}
2+
ansible.builtin.command:
3+
cmd: >
4+
docker pull {{ ecr_registry }}/{{ item }}:{{ build_label }}
5+
with_items: "{{ repo_names }}"
6+
register: pull_results
7+
8+
- name: Retag image {{ item.item }}:{{ build_label }} → ecs-{{ build_label }}
9+
ansible.builtin.command:
10+
cmd: >
11+
docker tag
12+
{{ ecr_registry }}/{{ item.item }}:{{ build_label }}
13+
{{ ecr_registry }}/{{ item.item }}:ecs-{{ build_label }}
14+
with_items: "{{ pull_results.results }}"
15+
when: item.rc == 0
16+
17+
- name: Push new tag ecs-{{ build_label }} for {{ item.item }}
18+
ansible.builtin.command:
19+
cmd: >
20+
docker push {{ ecr_registry }}/{{ item.item }}:ecs-{{ build_label }}
21+
with_items: "{{ pull_results.results }}"
22+
when: item.rc == 0
23+
24+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
build_label: "{{ lookup('env', 'build_label') }}"
3+
containers: "{{ docker_containers | json_query('[].name') | unique | sort }}"
4+
repo_names: "{{ containers | map('regex_replace', '^(.*)$', service_id + '_\\1') | list }}"
5+
base_dir: "{{ playbook_dir }}/../.."
6+

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

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -82,44 +82,6 @@
8282
register: tfapply
8383
when: not do_not_terraform
8484

85-
- name: Retag ECS image using ECR API (release pipelines only)
86-
when: lookup('env', 'RELEASE_RELEASEID') | length > 0
87-
vars:
88-
# Choose PTL for lower envs, PROD for prod
89-
TARGET_ACCOUNT: >-
90-
{{
91-
(apigee_environment == "prod")
92-
| ternary(PROD_ACCOUNT_ID, PTL_ACCOUNT_ID)
93-
}}
94-
REPO: "{{ service_id }}_{{ ecs_service[0].name }}"
95-
OLD: "{{ build_label }}"
96-
NEW: "ecs-{{ build_label }}"
97-
shell: |
98-
# 1. Fetch manifest from the SAME account (PTL for lower envs, PROD for prod)
99-
MANIFEST=$(aws ecr batch-get-image \
100-
--region eu-west-2 \
101-
--registry-id {{ TARGET_ACCOUNT }} \
102-
--repository-name {{ REPO }} \
103-
--image-ids imageTag={{ OLD }} \
104-
--query 'images[0].imageManifest' \
105-
--output text)
106-
107-
# Safety check: ensure the base tag exists
108-
if [ -z "$MANIFEST" ]; then
109-
echo "ERROR: Tag {{ OLD }} does not exist in account {{ TARGET_ACCOUNT }}"
110-
exit 1
111-
fi
112-
113-
# 2. Write the new tag into the SAME account
114-
aws ecr put-image \
115-
--region eu-west-2 \
116-
--registry-id {{ TARGET_ACCOUNT }} \
117-
--repository-name {{ REPO }} \
118-
--image-tag {{ NEW }} \
119-
--image-manifest "$MANIFEST"
120-
args:
121-
executable: /bin/bash
122-
12385
rescue:
12486
- name: output plan
12587
debug:

0 commit comments

Comments
 (0)