zuul-jobs/roles/promote-docker-image/tasks/main.yaml
Clark Boylan 4ed66807a0 Use unique loop vars to avoid conflicts
We have to be careful about avoiding outer loop loop_var conflicts in
ansible. Because the zuul-jobs roles are meant to be reconsumed
elsewhere we should not use 'item' loopvars and instead set them to
something a bit more unique.

We use a zj_ prefix to try and be unique to this repo and document this
convention.

Change-Id: I20b9327a914890e9eafcb2b36dc8c23fb472bc8f
2020-02-04 12:23:36 -08:00

33 lines
955 B
YAML

- name: Verify repository names
when: |
docker_credentials.repository is defined
and not zj_image.repository | regex_search(docker_credentials.repository)
loop: "{{ docker_images }}"
loop_control:
loop_var: zj_image
fail:
msg: "{{ zj_image.repository }} not permitted by {{ docker_credentials.repository }}"
# This is used by the delete tasks
- name: Get dockerhub JWT token
no_log: true
uri:
url: "https://hub.docker.com/v2/users/login/"
body_format: json
body:
username: "{{ docker_credentials.username }}"
password: "{{ docker_credentials.password }}"
register: jwt_token
delay: 5
retries: 3
until: jwt_token and jwt_token.status==200
- name: Promote image
loop: "{{ docker_images }}"
loop_control:
loop_var: image
include_tasks: promote-retag.yaml
- name: Delete obsolete tags
loop: "{{ docker_images }}"
loop_control:
loop_var: image
include_tasks: promote-cleanup.yaml