Upload an image to dockerhub with a change-specific tag in every gate job, and then, if the change lands, re-tag the image in dockerhub. Change-Id: Ie57fc342cbe29d261d33845829b77a0c1bae5ff4changes/57/629957/5
parent
83237bc01e
commit
899a2023d2
@ -0,0 +1,31 @@
|
||||
- name: Get dockerhub token
|
||||
no_log: true
|
||||
uri:
|
||||
url: "https://auth.docker.io/token?service=registry.docker.io&scope=repository:{{image.repository}}:pull,push"
|
||||
user: "{{ credentials.username }}"
|
||||
password: "{{ credentials.password }}"
|
||||
force_basic_auth: true
|
||||
register: token
|
||||
- name: Get manifest
|
||||
no_log: true
|
||||
uri:
|
||||
url: "https://registry.hub.docker.com/v2/{{image.repository}}/manifests/change_{{zuul.change}}"
|
||||
status_code: 200
|
||||
headers:
|
||||
Accept: "application/vnd.docker.distribution.manifestv2+json"
|
||||
Authorization: "Bearer {{ token.json.token }}"
|
||||
return_content: true
|
||||
register: manifest
|
||||
- name: "Put manifest"
|
||||
no_log: true
|
||||
loop: "{{ image.tags | default(['latest']) }}"
|
||||
loop_control:
|
||||
loop_var: new_tag
|
||||
uri:
|
||||
url: "https://registry.hub.docker.com/v2/{{image.repository}}/manifests/{{ new_tag }}"
|
||||
method: PUT
|
||||
status_code: 201
|
||||
body: "{{ manifest.content | string }}"
|
||||
headers:
|
||||
Content-Type: "application/vnd.docker.distribution.manifestv2+json"
|
||||
Authorization: "Bearer {{ token.json.token }}"
|
@ -0,0 +1,10 @@
|
||||
- hosts: all
|
||||
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
|
@ -1,7 +1,7 @@
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Build a docker image
|
||||
command: "docker build . {{ target | default(false) | ternary('--target ', '') }}{{ target | default('') }} --tag {{ item.repository }}"
|
||||
command: "docker build . {{ target | default(false) | ternary('--target ', '') }}{{ target | default('') }} --tag {{ item.repository }}:change_{{ zuul.change }}"
|
||||
args:
|
||||
chdir: "{{ zuul.project.src_dir }}/{{ item.context }}"
|
||||
loop: "{{ images }}"
|
Loading…
Reference in new issue