|
| 1 | +- name: Ensure docker_containers is loaded |
| 2 | + include_vars: |
| 3 | + file: "{{ lookup('env', 'CONTAINER_VARS_FILE') }}" |
| 4 | + when: docker_containers is not defined |
| 5 | + |
| 6 | +- name: Debug docker_containers (retag role) |
| 7 | + debug: |
| 8 | + var: docker_containers |
| 9 | + |
| 10 | +- name: Debug containers (retag role) |
| 11 | + debug: |
| 12 | + var: containers |
| 13 | + |
| 14 | +- name: Debug repo_names (retag role) |
| 15 | + debug: |
| 16 | + var: repo_names |
| 17 | + |
| 18 | +- name: Login to ECR |
| 19 | + shell: > |
| 20 | + {{ aws_cmd }} ecr get-login-password --region {{ aws_region }} |
| 21 | + | docker login --username AWS --password-stdin {{ ecr_registry }} |
| 22 | +
|
| 23 | +- name: Debug pulling image |
| 24 | + debug: |
| 25 | + msg: "Pulling {{ ecr_registry }}/{{ item }}:{{ build_label }}" |
| 26 | + loop: "{{ repo_names }}" |
| 27 | + loop_control: |
| 28 | + label: "{{ item }}" |
| 29 | + |
| 30 | +- name: Pull existing image |
| 31 | + ansible.builtin.command: |
| 32 | + cmd: > |
| 33 | + docker pull {{ ecr_registry }}/{{ item }}:{{ build_label }} |
| 34 | + loop: "{{ repo_names }}" |
| 35 | + loop_control: |
| 36 | + label: "{{ item }}" |
| 37 | + register: pull_results |
| 38 | + |
| 39 | +- name: Debug retagging image |
| 40 | + debug: |
| 41 | + msg: "Retagging {{ item.item }}:{{ build_label }} → ecs-{{ build_label }}" |
| 42 | + loop: "{{ pull_results.results }}" |
| 43 | + loop_control: |
| 44 | + label: "{{ item.item }}" |
| 45 | + when: |
| 46 | + - item.rc == 0 |
| 47 | + - item.item == "canary_canary-api" |
| 48 | + |
| 49 | +- name: Retag image |
| 50 | + ansible.builtin.command: |
| 51 | + cmd: > |
| 52 | + docker tag |
| 53 | + {{ ecr_registry }}/{{ item.item }}:{{ build_label }} |
| 54 | + {{ ecr_registry }}/{{ item.item }}:ecs-{{ build_label }} |
| 55 | + loop: "{{ pull_results.results }}" |
| 56 | + loop_control: |
| 57 | + label: "{{ item.item }}" |
| 58 | + when: |
| 59 | + - item.rc == 0 |
| 60 | + - item.item == "canary_canary-api" |
| 61 | + |
| 62 | +- name: Debug pushing image |
| 63 | + debug: |
| 64 | + msg: "Pushing ecs-{{ build_label }} for {{ item.item }}" |
| 65 | + loop: "{{ pull_results.results }}" |
| 66 | + loop_control: |
| 67 | + label: "{{ item.item }}" |
| 68 | + when: |
| 69 | + - item.rc == 0 |
| 70 | + - item.item == "canary_canary-api" |
| 71 | + |
| 72 | +- name: Push new tag |
| 73 | + ansible.builtin.command: |
| 74 | + cmd: > |
| 75 | + docker push {{ ecr_registry }}/{{ item.item }}:ecs-{{ build_label }} |
| 76 | + loop: "{{ pull_results.results }}" |
| 77 | + loop_control: |
| 78 | + label: "{{ item.item }}" |
| 79 | + when: |
| 80 | + - item.rc == 0 |
| 81 | + - item.item == "canary_canary-api" |
| 82 | + |
| 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" |
0 commit comments