summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2019-02-19 17:49:21 -0800
committerJames E. Blair <jeblair@redhat.com>2019-02-19 17:49:21 -0800
commitcbff0cc355ad0e83557737e8f87e5eb45d70bd51 (patch)
treef15f9ce1b352697862e538457435aaae9226ae1f
parent7edb42008f5ddd761324d10b4d1fc1bd1cbfb0ed (diff)
push-to-registry: handle undefined docker_images
So that this role may be used unconditionally in jobs which may or may not actually build images, skip the tasks if the docker_images variable is undefined. Change-Id: I6ef0c80230de628f86f523878020c82ce81a1e60
Notes
Notes (review): Code-Review+2: Jeremy Stanley <fungi@yuggoth.org> Code-Review+2: Andreas Jaeger <jaegerandi@gmail.com> Workflow+1: Andreas Jaeger <jaegerandi@gmail.com> Code-Review+2: Monty Taylor <mordred@inaugust.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 20 Feb 2019 18:06:42 +0000 Reviewed-on: https://review.openstack.org/638057 Project: openstack-infra/zuul-jobs Branch: refs/heads/master
-rw-r--r--roles/push-to-intermediate-registry/tasks/main.yaml19
-rw-r--r--roles/push-to-intermediate-registry/tasks/push-image.yaml26
-rw-r--r--roles/push-to-intermediate-registry/tasks/push.yaml42
3 files changed, 45 insertions, 42 deletions
diff --git a/roles/push-to-intermediate-registry/tasks/main.yaml b/roles/push-to-intermediate-registry/tasks/main.yaml
index 740d88a..0d991a0 100644
--- a/roles/push-to-intermediate-registry/tasks/main.yaml
+++ b/roles/push-to-intermediate-registry/tasks/main.yaml
@@ -1,18 +1,3 @@
1# This can be removed if we add this functionality to Zuul directly 1- name: Push images to intermediate registry
2- name: Load information from zuul_return 2 when: docker_images is defined
3 when: buildset_registry is not defined
4 set_fact:
5 buildset_registry: "{{ (lookup('file', zuul.executor.work_root + '/results.json') | from_json)['buildset_registry'] }}"
6- name: Ensure registry cert directory exists
7 file:
8 path: "/etc/docker/certs.d/{{ buildset_registry.host }}:{{ buildset_registry.port }}/"
9 state: directory
10- name: Write registry TLS certificate
11 copy:
12 content: "{{ buildset_registry.cert }}"
13 dest: "/etc/docker/certs.d/{{ buildset_registry.host }}:{{ buildset_registry.port }}/ca.crt"
14- name: Push image to intermediate registry
15 include_tasks: push.yaml 3 include_tasks: push.yaml
16 loop: "{{ docker_images }}"
17 loop_control:
18 loop_var: image
diff --git a/roles/push-to-intermediate-registry/tasks/push-image.yaml b/roles/push-to-intermediate-registry/tasks/push-image.yaml
new file mode 100644
index 0000000..df922fd
--- /dev/null
+++ b/roles/push-to-intermediate-registry/tasks/push-image.yaml
@@ -0,0 +1,26 @@
1- name: Push tag to intermediate registry
2 command: >-
3 skopeo --insecure-policy copy
4 --src-creds={{ buildset_registry.username }}:{{ buildset_registry.password }}
5 --dest-creds={{ intermediate_registry.username }}:{{ intermediate_registry.password }}
6 docker://{{ buildset_registry.host }}:{{ buildset_registry.port }}/{{ image.repository }}:{{ image_tag }}
7 docker://{{ intermediate_registry.host }}:{{ intermediate_registry.port}}/{{ image.repository }}:{{ zuul.build }}_{{ image_tag }}
8 loop: "{{ image.tags | default(['latest']) }}"
9 loop_control:
10 loop_var: image_tag
11 # no_log: true TODO(corvus) replace
12
13- name: Return artifact to Zuul
14 zuul_return:
15 data:
16 zuul:
17 artifacts:
18 - name: "image_{{ image.repository }}:{{ image_tag }}"
19 url: "docker://{{ intermediate_registry.host }}:{{ intermediate_registry.port}}/{{ image.repository }}:{{ zuul.build }}_{{ image_tag}}"
20 metadata:
21 type: container_image
22 repository: "{{ image.repository }}"
23 tag: "{{ image_tag }}"
24 loop: "{{ image.tags | default(['latest']) }}"
25 loop_control:
26 loop_var: image_tag
diff --git a/roles/push-to-intermediate-registry/tasks/push.yaml b/roles/push-to-intermediate-registry/tasks/push.yaml
index df922fd..cd6d5e3 100644
--- a/roles/push-to-intermediate-registry/tasks/push.yaml
+++ b/roles/push-to-intermediate-registry/tasks/push.yaml
@@ -1,26 +1,18 @@
1- name: Push tag to intermediate registry 1# This can be removed if we add this functionality to Zuul directly
2 command: >- 2- name: Load information from zuul_return
3 skopeo --insecure-policy copy 3 when: buildset_registry is not defined
4 --src-creds={{ buildset_registry.username }}:{{ buildset_registry.password }} 4 set_fact:
5 --dest-creds={{ intermediate_registry.username }}:{{ intermediate_registry.password }} 5 buildset_registry: "{{ (lookup('file', zuul.executor.work_root + '/results.json') | from_json)['buildset_registry'] }}"
6 docker://{{ buildset_registry.host }}:{{ buildset_registry.port }}/{{ image.repository }}:{{ image_tag }} 6- name: Ensure registry cert directory exists
7 docker://{{ intermediate_registry.host }}:{{ intermediate_registry.port}}/{{ image.repository }}:{{ zuul.build }}_{{ image_tag }} 7 file:
8 loop: "{{ image.tags | default(['latest']) }}" 8 path: "/etc/docker/certs.d/{{ buildset_registry.host }}:{{ buildset_registry.port }}/"
9 state: directory
10- name: Write registry TLS certificate
11 copy:
12 content: "{{ buildset_registry.cert }}"
13 dest: "/etc/docker/certs.d/{{ buildset_registry.host }}:{{ buildset_registry.port }}/ca.crt"
14- name: Push image to intermediate registry
15 include_tasks: push-image.yaml
16 loop: "{{ docker_images }}"
9 loop_control: 17 loop_control:
10 loop_var: image_tag 18 loop_var: image
11 # no_log: true TODO(corvus) replace
12
13- name: Return artifact to Zuul
14 zuul_return:
15 data:
16 zuul:
17 artifacts:
18 - name: "image_{{ image.repository }}:{{ image_tag }}"
19 url: "docker://{{ intermediate_registry.host }}:{{ intermediate_registry.port}}/{{ image.repository }}:{{ zuul.build }}_{{ image_tag}}"
20 metadata:
21 type: container_image
22 repository: "{{ image.repository }}"
23 tag: "{{ image_tag }}"
24 loop: "{{ image.tags | default(['latest']) }}"
25 loop_control:
26 loop_var: image_tag