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
This commit is contained in:
James E. Blair 2019-02-19 17:49:21 -08:00
parent 7edb42008f
commit cbff0cc355
3 changed files with 45 additions and 42 deletions

View File

@ -1,18 +1,3 @@
# This can be removed if we add this functionality to Zuul directly - name: Push images to intermediate registry
- name: Load information from zuul_return when: docker_images is defined
when: buildset_registry is not defined
set_fact:
buildset_registry: "{{ (lookup('file', zuul.executor.work_root + '/results.json') | from_json)['buildset_registry'] }}"
- name: Ensure registry cert directory exists
file:
path: "/etc/docker/certs.d/{{ buildset_registry.host }}:{{ buildset_registry.port }}/"
state: directory
- name: Write registry TLS certificate
copy:
content: "{{ buildset_registry.cert }}"
dest: "/etc/docker/certs.d/{{ buildset_registry.host }}:{{ buildset_registry.port }}/ca.crt"
- name: Push image to intermediate registry
include_tasks: push.yaml include_tasks: push.yaml
loop: "{{ docker_images }}"
loop_control:
loop_var: image

View File

@ -0,0 +1,26 @@
- name: Push tag to intermediate registry
command: >-
skopeo --insecure-policy copy
--src-creds={{ buildset_registry.username }}:{{ buildset_registry.password }}
--dest-creds={{ intermediate_registry.username }}:{{ intermediate_registry.password }}
docker://{{ buildset_registry.host }}:{{ buildset_registry.port }}/{{ image.repository }}:{{ image_tag }}
docker://{{ intermediate_registry.host }}:{{ intermediate_registry.port}}/{{ image.repository }}:{{ zuul.build }}_{{ image_tag }}
loop: "{{ image.tags | default(['latest']) }}"
loop_control:
loop_var: image_tag
# no_log: true TODO(corvus) replace
- name: Return artifact to Zuul
zuul_return:
data:
zuul:
artifacts:
- name: "image_{{ image.repository }}:{{ image_tag }}"
url: "docker://{{ intermediate_registry.host }}:{{ intermediate_registry.port}}/{{ image.repository }}:{{ zuul.build }}_{{ image_tag}}"
metadata:
type: container_image
repository: "{{ image.repository }}"
tag: "{{ image_tag }}"
loop: "{{ image.tags | default(['latest']) }}"
loop_control:
loop_var: image_tag

View File

@ -1,26 +1,18 @@
- name: Push tag to intermediate registry # This can be removed if we add this functionality to Zuul directly
command: >- - name: Load information from zuul_return
skopeo --insecure-policy copy when: buildset_registry is not defined
--src-creds={{ buildset_registry.username }}:{{ buildset_registry.password }} set_fact:
--dest-creds={{ intermediate_registry.username }}:{{ intermediate_registry.password }} buildset_registry: "{{ (lookup('file', zuul.executor.work_root + '/results.json') | from_json)['buildset_registry'] }}"
docker://{{ buildset_registry.host }}:{{ buildset_registry.port }}/{{ image.repository }}:{{ image_tag }} - name: Ensure registry cert directory exists
docker://{{ intermediate_registry.host }}:{{ intermediate_registry.port}}/{{ image.repository }}:{{ zuul.build }}_{{ image_tag }} file:
loop: "{{ image.tags | default(['latest']) }}" path: "/etc/docker/certs.d/{{ buildset_registry.host }}:{{ buildset_registry.port }}/"
state: directory
- name: Write registry TLS certificate
copy:
content: "{{ buildset_registry.cert }}"
dest: "/etc/docker/certs.d/{{ buildset_registry.host }}:{{ buildset_registry.port }}/ca.crt"
- name: Push image to intermediate registry
include_tasks: push-image.yaml
loop: "{{ docker_images }}"
loop_control: loop_control:
loop_var: image_tag loop_var: image
# no_log: true TODO(corvus) replace
- name: Return artifact to Zuul
zuul_return:
data:
zuul:
artifacts:
- name: "image_{{ image.repository }}:{{ image_tag }}"
url: "docker://{{ intermediate_registry.host }}:{{ intermediate_registry.port}}/{{ image.repository }}:{{ zuul.build }}_{{ image_tag}}"
metadata:
type: container_image
repository: "{{ image.repository }}"
tag: "{{ image_tag }}"
loop: "{{ image.tags | default(['latest']) }}"
loop_control:
loop_var: image_tag