Merge "Delete change tags from docker image repos"
This commit is contained in:
commit
8e3961d32f
@ -112,4 +112,4 @@ EXPOSE 22
|
|||||||
VOLUME ["/data"]
|
VOLUME ["/data"]
|
||||||
ENTRYPOINT ["/usr/bin/entrypoint"]
|
ENTRYPOINT ["/usr/bin/entrypoint"]
|
||||||
CMD ["/usr/sbin/sshd", "-D"]
|
CMD ["/usr/sbin/sshd", "-D"]
|
||||||
# this comment is here to perform a test run of the job...
|
# this comment is here to perform a test run of the job....
|
||||||
|
20
playbooks/zuul/build-image/promote-delete-tag.yaml
Normal file
20
playbooks/zuul/build-image/promote-delete-tag.yaml
Normal file
@ -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,7 +1,7 @@
|
|||||||
- name: Get dockerhub token
|
- name: Get dockerhub token
|
||||||
no_log: true
|
no_log: true
|
||||||
uri:
|
uri:
|
||||||
url: "https://auth.docker.io/token?service=registry.docker.io&scope=repository:{{image.repository}}:pull,push"
|
url: "https://auth.docker.io/token?service=registry.docker.io&scope=repository:{{ image.repository }}:pull,push"
|
||||||
user: "{{ credentials.username }}"
|
user: "{{ credentials.username }}"
|
||||||
password: "{{ credentials.password }}"
|
password: "{{ credentials.password }}"
|
||||||
force_basic_auth: true
|
force_basic_auth: true
|
||||||
@ -9,7 +9,7 @@
|
|||||||
- name: Get manifest
|
- name: Get manifest
|
||||||
no_log: true
|
no_log: true
|
||||||
uri:
|
uri:
|
||||||
url: "https://registry.hub.docker.com/v2/{{image.repository}}/manifests/change_{{zuul.change}}"
|
url: "https://registry.hub.docker.com/v2/{{ image.repository }}/manifests/change_{{ zuul.change }}"
|
||||||
status_code: 200
|
status_code: 200
|
||||||
headers:
|
headers:
|
||||||
Accept: "application/vnd.docker.distribution.manifestv2+json"
|
Accept: "application/vnd.docker.distribution.manifestv2+json"
|
||||||
@ -22,10 +22,18 @@
|
|||||||
loop_control:
|
loop_control:
|
||||||
loop_var: new_tag
|
loop_var: new_tag
|
||||||
uri:
|
uri:
|
||||||
url: "https://registry.hub.docker.com/v2/{{image.repository}}/manifests/{{ new_tag }}"
|
url: "https://registry.hub.docker.com/v2/{{ image.repository }}/manifests/{{ new_tag }}"
|
||||||
method: PUT
|
method: PUT
|
||||||
status_code: 201
|
status_code: 201
|
||||||
body: "{{ manifest.content | string }}"
|
body: "{{ manifest.content | string }}"
|
||||||
headers:
|
headers:
|
||||||
Content-Type: "application/vnd.docker.distribution.manifestv2+json"
|
Content-Type: "application/vnd.docker.distribution.manifestv2+json"
|
||||||
Authorization: "Bearer {{ token.json.token }}"
|
Authorization: "Bearer {{ token.json.token }}"
|
||||||
|
- name: Delete the current change tag
|
||||||
|
no_log: true
|
||||||
|
uri:
|
||||||
|
url: "https://hub.docker.com/v2/repositories/{{ image.repository }}/tags/change_{{ zuul.change }}/"
|
||||||
|
method: DELETE
|
||||||
|
status_code: 204
|
||||||
|
headers:
|
||||||
|
Authorization: "JWT {{ jwt_token.json.token }}"
|
||||||
|
@ -1,10 +1,22 @@
|
|||||||
- hosts: localhost
|
- hosts: localhost
|
||||||
tasks:
|
tasks:
|
||||||
- name: Promote dockerhub image
|
# This is used by the delete tasks
|
||||||
when: credentials is defined
|
- name: Get dockerhub JWT token
|
||||||
block:
|
no_log: true
|
||||||
- name: Promote image
|
uri:
|
||||||
loop: "{{ images }}"
|
url: "https://hub.docker.com/v2/users/login/"
|
||||||
loop_control:
|
body_format: json
|
||||||
loop_var: image
|
body:
|
||||||
include_tasks: promote-retag.yaml
|
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…
x
Reference in New Issue
Block a user