zuul-jobs/roles/promote-docker-image/tasks/promote-cleanup.yaml
Ian Wienand 4340c8d473
promote-docker-image: improve failure debugability
Currently this no_logs the entire selection and delete loop, which is
probably maximal efficiency but makes it very hard to debug on failure
(which we are seeing).  This extracts the list creation and uri call
so we can see the tags it is trying to delete.

Change-Id: I93fd19aedaa9fc328a1a347986a5f0c20439d476
2023-02-08 08:26:07 +11:00

27 lines
927 B
YAML

- name: List tags
uri:
url: "https://hub.docker.com/v2/repositories/{{ zj_image.repository }}/tags?page_size=1000"
status_code: 200
register: tags
- name: Create old tags list
set_fact:
_old_tags: []
- name: Build list of old tags
loop: "{{ tags.json.results }}"
loop_control:
loop_var: zj_docker_tag
set_fact:
_old_tags: '{{ _old_tags.append(zj_docker_tag) }}'
when:
- zj_docker_tag.name.startswith('change_') or zj_docker_tag.name.startswith(zuul.pipeline)
# Was updated > 24 hours ago:
- "((ansible_date_time.iso8601 | regex_replace('^(....-..-..)T(..:..:..).*Z', '\\\\1 \\\\2') | to_datetime) - (zj_docker_tag.last_updated | regex_replace('^(....-..-..)T(..:..:..).*Z', '\\\\1 \\\\2') | to_datetime)).seconds > 86400"
- name: Delete all change tags older than the cutoff
loop: "{{ _old_tags }}"
loop_control:
loop_var: zj_docker_tag
include_tasks: delete-tag.yaml