Handle multiple docker images with the same repository

So that users can specify two docker image builds for the same
repository, but with different tags, ensure that the temporary
change_ tag attached to the image also includes the final tag
name.

This allows this configuration to work:

docker_images:
  - repository: foo/image
    context: opensuse
    tags:
      - opensuse-latest
  - repository: foo/image
    context: ubuntu
    tags:
      - ubuntu-latest

Change-Id: I917dcf8a74fc864ea06dc70bdb3e212dc170eb48
This commit is contained in:
James E. Blair 2019-02-27 11:08:44 -08:00
parent 2428945c21
commit 885f02e217
5 changed files with 41 additions and 32 deletions

View File

@ -13,8 +13,8 @@
{% for build_arg in item.build_args | default([]) -%}
--build-arg {{ build_arg }}
{% endfor -%}
--tag {{ item.repository }}:change_{{ zuul.change }}
{% for tag in item.tags | default(['latest']) -%}
--tag {{ item.repository }}:change_{{ zuul.change }}_{{ tag }}
--tag {{ item.repository }}:{{ tag }}
{% endfor -%}
args:

View File

@ -0,0 +1,28 @@
- name: Get manifest
no_log: true
uri:
url: "https://registry.hub.docker.com/v2/{{ image.repository }}/manifests/change_{{ zuul.change }}_{{ image_tag }}"
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
uri:
url: "https://registry.hub.docker.com/v2/{{ image.repository }}/manifests/{{ image_tag }}"
method: PUT
status_code: 201
body: "{{ manifest.content | string }}"
headers:
Content-Type: "application/vnd.docker.distribution.manifestv2+json"
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 }}_{{ image_tag }}/"
method: DELETE
status_code: 204
headers:
Authorization: "JWT {{ jwt_token.json.token }}"

View File

@ -6,34 +6,8 @@
password: "{{ docker_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
- name: Retag image
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 }}"
- 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 }}"
loop_var: image_tag
include_tasks: promote-retag-inner.yaml

View File

@ -8,6 +8,8 @@
- name: Log in to dockerhub
command: "docker login -u {{ docker_credentials.username }} -p {{ docker_credentials.password }}"
no_log: true
- name: Upload to dockerhub
command: "docker push {{ item.repository }}:change_{{ zuul.change }}"
- name: Upload image to dockerhub
loop: "{{ docker_images }}"
loop_control:
loop_var: image
include_tasks: push.yaml

View File

@ -0,0 +1,5 @@
- name: Upload tag to dockerhub
command: "docker push {{ item.repository }}:change_{{ zuul.change }}_{{ image_tag }}"
loop: "{{ image.tags | default(['latest']) }}"
loop_control:
loop_var: image_tag