Browse Source

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
master
James E. Blair 3 months ago
parent
commit
cbff0cc355

+ 2
- 17
roles/push-to-intermediate-registry/tasks/main.yaml View File

@@ -1,18 +1,3 @@
1
-# This can be removed if we add this functionality to Zuul directly
2
-- name: Load information from zuul_return
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
1
+- name: Push images to intermediate registry
2
+  when: docker_images is defined
15 3
   include_tasks: push.yaml
16
-  loop: "{{ docker_images }}"
17
-  loop_control:
18
-    loop_var: image

+ 26
- 0
roles/push-to-intermediate-registry/tasks/push-image.yaml View File

@@ -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

+ 17
- 25
roles/push-to-intermediate-registry/tasks/push.yaml View File

@@ -1,26 +1,18 @@
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']) }}"
1
+# This can be removed if we add this functionality to Zuul directly
2
+- name: Load information from zuul_return
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-image.yaml
16
+  loop: "{{ docker_images }}"
9 17
   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
18
+    loop_var: image

Loading…
Cancel
Save