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
This commit is contained in:
Ian Wienand 2023-02-07 16:45:14 +11:00
parent 1c85809ab1
commit 4340c8d473
No known key found for this signature in database
2 changed files with 26 additions and 8 deletions

View File

@ -0,0 +1,12 @@
- name: Show the tag we are about to delete
debug:
var: zj_docker_tag
- name: Make delete call
no_log: true
uri:
url: "https://hub.docker.com/v2/repositories/{{ zj_image.repository }}/tags/{{ zj_docker_tag.name }}/"
method: DELETE
status_code: [200, 204]
headers:
Authorization: "JWT {{ jwt_token.json.token }}"

View File

@ -3,18 +3,24 @@
url: "https://hub.docker.com/v2/repositories/{{ zj_image.repository }}/tags?page_size=1000"
status_code: 200
register: tags
- name: Delete all change tags older than the cutoff
no_log: true
- 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"
uri:
url: "https://hub.docker.com/v2/repositories/{{ zj_image.repository }}/tags/{{ zj_docker_tag.name }}/"
method: DELETE
status_code: [200, 204]
headers:
Authorization: "JWT {{ jwt_token.json.token }}"
- name: Delete all change tags older than the cutoff
loop: "{{ _old_tags }}"
loop_control:
loop_var: zj_docker_tag
include_tasks: delete-tag.yaml