Whenever we promote an image, delete the change tag for that image in Docker Hub, and also delete any change tags older than 24 hours in order to keep the Docker Hub image registry tidy. Change-Id: Id4654c893963bdb0a364b1132793fe4fb152bf27changes/82/630782/3
parent
d7c6c4e746
commit
a546e25e76
@ -0,0 +1,20 @@
|
||||
- name: List tags
|
||||
uri:
|
||||
url: "https://hub.docker.com/v2/repositories/{{ image.repository }}/tags?page_size=1000"
|
||||
status_code: 200
|
||||
register: tags
|
||||
- name: Set cutoff timestamp to 24 hours ago
|
||||
command: "python3 -c \"import datetime; print((datetime.datetime.utcnow()-datetime.timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%fZ'))\""
|
||||
register: cutoff
|
||||
- name: Delete all change tags older than the cutoff
|
||||
no_log: true
|
||||
loop: "{{ tags.json.results }}"
|
||||
loop_control:
|
||||
loop_var: docker_tag
|
||||
when: docker_tag.last_updated < cutoff.stdout and docker_tag.name.startswith('change_')
|
||||
uri:
|
||||
url: "https://hub.docker.com/v2/repositories/{{ image.repository }}/tags/{{ docker_tag.name }}/"
|
||||
method: DELETE
|
||||
status_code: 204
|
||||
headers:
|
||||
Authorization: "JWT {{ jwt_token.json.token }}"
|
@ -1,10 +1,22 @@
|
||||
- hosts: localhost
|
||||
tasks:
|
||||
- name: Promote dockerhub image
|
||||
when: credentials is defined
|
||||
block:
|
||||
- name: Promote image
|
||||
loop: "{{ images }}"
|
||||
loop_control:
|
||||
loop_var: image
|
||||
include_tasks: promote-retag.yaml
|
||||
# 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: "{{ credentials.username }}"
|
||||
password: "{{ credentials.password }}"
|
||||
register: jwt_token
|
||||
- name: Promote image
|
||||
loop: "{{ images }}"
|
||||
loop_control:
|
||||
loop_var: image
|
||||
include_tasks: promote-retag.yaml
|
||||
- name: Delete obsolete tags
|
||||
loop: "{{ images }}"
|
||||
loop_control:
|
||||
loop_var: image
|
||||
include_tasks: promote-delete-tag.yaml
|
||||
|
Loading…
Reference in new issue