zuul-jobs/roles/promote-docker-image/tasks/promote-cleanup.yaml
James E. Blair 2dc89d8347 Reinstate docker tag cleanup
This uses a new method of calculating the cutoff time which does not
require executing code on the executor.

Change-Id: I92e71727e24281a31cb7caf0b78dd17a5aaae129
Co-Authored-By: Clark Boylan <clark.boylan@gmail.com>
2020-07-22 08:39:54 -07:00

21 lines
857 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: Delete all change tags older than the cutoff
no_log: true
loop: "{{ tags.json.results }}"
loop_control:
loop_var: zj_docker_tag
when:
- zj_docker_tag.name.startswith('change_')
# 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 }}"