summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2019-02-27 11:08:44 -0800
committerJames E. Blair <jeblair@redhat.com>2019-02-27 11:08:44 -0800
commit885f02e21712e2b12505abde88012e18b4cacb82 (patch)
tree529e4f19b89d6a98997b7d2fa3d8a6a90789041c
parent2428945c21a00dd458ba542cf6e0d70ce83f9912 (diff)
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
Notes
Notes (review): Code-Review+1: Jean-Philippe Evrard <jean-philippe@evrard.me> Code-Review+2: Andreas Jaeger <jaegerandi@gmail.com> Code-Review+2: Clark Boylan <cboylan@sapwetik.org> Workflow+1: Clark Boylan <cboylan@sapwetik.org> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 01 Mar 2019 16:36:50 +0000 Reviewed-on: https://review.openstack.org/639779 Project: openstack-infra/zuul-jobs Branch: refs/heads/master
-rw-r--r--roles/build-docker-image/tasks/main.yaml2
-rw-r--r--roles/promote-docker-image/tasks/promote-retag-inner.yaml28
-rw-r--r--roles/promote-docker-image/tasks/promote-retag.yaml32
-rw-r--r--roles/upload-docker-image/tasks/main.yaml6
-rw-r--r--roles/upload-docker-image/tasks/push.yaml5
5 files changed, 41 insertions, 32 deletions
diff --git a/roles/build-docker-image/tasks/main.yaml b/roles/build-docker-image/tasks/main.yaml
index 73156e1..4a09643 100644
--- a/roles/build-docker-image/tasks/main.yaml
+++ b/roles/build-docker-image/tasks/main.yaml
@@ -13,8 +13,8 @@
13 {% for build_arg in item.build_args | default([]) -%} 13 {% for build_arg in item.build_args | default([]) -%}
14 --build-arg {{ build_arg }} 14 --build-arg {{ build_arg }}
15 {% endfor -%} 15 {% endfor -%}
16 --tag {{ item.repository }}:change_{{ zuul.change }}
17 {% for tag in item.tags | default(['latest']) -%} 16 {% for tag in item.tags | default(['latest']) -%}
17 --tag {{ item.repository }}:change_{{ zuul.change }}_{{ tag }}
18 --tag {{ item.repository }}:{{ tag }} 18 --tag {{ item.repository }}:{{ tag }}
19 {% endfor -%} 19 {% endfor -%}
20 args: 20 args:
diff --git a/roles/promote-docker-image/tasks/promote-retag-inner.yaml b/roles/promote-docker-image/tasks/promote-retag-inner.yaml
new file mode 100644
index 0000000..5643fe2
--- /dev/null
+++ b/roles/promote-docker-image/tasks/promote-retag-inner.yaml
@@ -0,0 +1,28 @@
1- name: Get manifest
2 no_log: true
3 uri:
4 url: "https://registry.hub.docker.com/v2/{{ image.repository }}/manifests/change_{{ zuul.change }}_{{ image_tag }}"
5 status_code: 200
6 headers:
7 Accept: "application/vnd.docker.distribution.manifestv2+json"
8 Authorization: "Bearer {{ token.json.token }}"
9 return_content: true
10 register: manifest
11- name: Put manifest
12 no_log: true
13 uri:
14 url: "https://registry.hub.docker.com/v2/{{ image.repository }}/manifests/{{ image_tag }}"
15 method: PUT
16 status_code: 201
17 body: "{{ manifest.content | string }}"
18 headers:
19 Content-Type: "application/vnd.docker.distribution.manifestv2+json"
20 Authorization: "Bearer {{ token.json.token }}"
21- name: Delete the current change tag
22 no_log: true
23 uri:
24 url: "https://hub.docker.com/v2/repositories/{{ image.repository }}/tags/change_{{ zuul.change }}_{{ image_tag }}/"
25 method: DELETE
26 status_code: 204
27 headers:
28 Authorization: "JWT {{ jwt_token.json.token }}"
diff --git a/roles/promote-docker-image/tasks/promote-retag.yaml b/roles/promote-docker-image/tasks/promote-retag.yaml
index 255e4bd..8237dab 100644
--- a/roles/promote-docker-image/tasks/promote-retag.yaml
+++ b/roles/promote-docker-image/tasks/promote-retag.yaml
@@ -6,34 +6,8 @@
6 password: "{{ docker_credentials.password }}" 6 password: "{{ docker_credentials.password }}"
7 force_basic_auth: true 7 force_basic_auth: true
8 register: token 8 register: token
9- name: Get manifest 9- name: Retag image
10 no_log: true
11 uri:
12 url: "https://registry.hub.docker.com/v2/{{ image.repository }}/manifests/change_{{ zuul.change }}"
13 status_code: 200
14 headers:
15 Accept: "application/vnd.docker.distribution.manifestv2+json"
16 Authorization: "Bearer {{ token.json.token }}"
17 return_content: true
18 register: manifest
19- name: "Put manifest"
20 no_log: true
21 loop: "{{ image.tags | default(['latest']) }}" 10 loop: "{{ image.tags | default(['latest']) }}"
22 loop_control: 11 loop_control:
23 loop_var: new_tag 12 loop_var: image_tag
24 uri: 13 include_tasks: promote-retag-inner.yaml
25 url: "https://registry.hub.docker.com/v2/{{ image.repository }}/manifests/{{ new_tag }}"
26 method: PUT
27 status_code: 201
28 body: "{{ manifest.content | string }}"
29 headers:
30 Content-Type: "application/vnd.docker.distribution.manifestv2+json"
31 Authorization: "Bearer {{ token.json.token }}"
32- name: Delete the current change tag
33 no_log: true
34 uri:
35 url: "https://hub.docker.com/v2/repositories/{{ image.repository }}/tags/change_{{ zuul.change }}/"
36 method: DELETE
37 status_code: 204
38 headers:
39 Authorization: "JWT {{ jwt_token.json.token }}"
diff --git a/roles/upload-docker-image/tasks/main.yaml b/roles/upload-docker-image/tasks/main.yaml
index d7e8c81..1549090 100644
--- a/roles/upload-docker-image/tasks/main.yaml
+++ b/roles/upload-docker-image/tasks/main.yaml
@@ -8,6 +8,8 @@
8- name: Log in to dockerhub 8- name: Log in to dockerhub
9 command: "docker login -u {{ docker_credentials.username }} -p {{ docker_credentials.password }}" 9 command: "docker login -u {{ docker_credentials.username }} -p {{ docker_credentials.password }}"
10 no_log: true 10 no_log: true
11- name: Upload to dockerhub 11- name: Upload image to dockerhub
12 command: "docker push {{ item.repository }}:change_{{ zuul.change }}"
13 loop: "{{ docker_images }}" 12 loop: "{{ docker_images }}"
13 loop_control:
14 loop_var: image
15 include_tasks: push.yaml
diff --git a/roles/upload-docker-image/tasks/push.yaml b/roles/upload-docker-image/tasks/push.yaml
new file mode 100644
index 0000000..28f54e4
--- /dev/null
+++ b/roles/upload-docker-image/tasks/push.yaml
@@ -0,0 +1,5 @@
1- name: Upload tag to dockerhub
2 command: "docker push {{ item.repository }}:change_{{ zuul.change }}_{{ image_tag }}"
3 loop: "{{ image.tags | default(['latest']) }}"
4 loop_control:
5 loop_var: image_tag