From f449ae20fb574a829a19dcf1bebc8f8f5353472b Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 5 May 2020 16:12:31 -0500 Subject: [PATCH] Set up siblings dirs for each build in the loop The buildx patch unfortunately changed the logic associated with siblings to set up siblings in a loop one time, rather than to do a loop of "set up siblings, build, cleanup siblings". This causes builds to fail when they're using siblings with an error about siblings dir not having been cleaned up. Change-Id: I3c45bfa77ec9f2609689e04044c18f066adc9741 --- roles/build-container-image/tasks/build.yaml | 2 +- roles/build-docker-image/tasks/build.yaml | 6 ++++++ roles/build-docker-image/tasks/buildx.yaml | 6 ++++++ .../build-docker-image/tasks/clean-siblings.yaml | 4 ++++ roles/build-docker-image/tasks/main.yaml | 6 ------ .../registry/docker-siblings/Dockerfile | 5 ++++- test-playbooks/registry/test-registry.yaml | 15 +++++++++++++++ 7 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 roles/build-docker-image/tasks/clean-siblings.yaml diff --git a/roles/build-container-image/tasks/build.yaml b/roles/build-container-image/tasks/build.yaml index ca763eed9..3261be4b9 100644 --- a/roles/build-container-image/tasks/build.yaml +++ b/roles/build-container-image/tasks/build.yaml @@ -50,5 +50,5 @@ - name: Cleanup sibling source directory file: - path: '{{ zuul_work_dir }}/.zuul-siblings' + path: '{{ zuul_work_dir }}/{{ zj_image.context }}/.zuul-siblings' state: absent diff --git a/roles/build-docker-image/tasks/build.yaml b/roles/build-docker-image/tasks/build.yaml index 7aa2e38cb..d61aca355 100644 --- a/roles/build-docker-image/tasks/build.yaml +++ b/roles/build-docker-image/tasks/build.yaml @@ -1,3 +1,6 @@ +- name: Set up siblings + include_tasks: siblings.yaml + - name: Build a docker image command: >- docker build {{ zj_image.path | default('.') }} -f {{ zj_image.dockerfile | default(docker_dockerfile) }} @@ -23,3 +26,6 @@ --label "org.zuul-ci.change_url={{ zuul.change_url }}" args: chdir: "{{ zuul_work_dir }}/{{ zj_image.context }}" + +- name: Cleanup sibling source directory + include_tasks: clean-siblings.yaml diff --git a/roles/build-docker-image/tasks/buildx.yaml b/roles/build-docker-image/tasks/buildx.yaml index 1268b25e7..99cab76b9 100644 --- a/roles/build-docker-image/tasks/buildx.yaml +++ b/roles/build-docker-image/tasks/buildx.yaml @@ -1,3 +1,6 @@ +- name: Set up siblings + include_tasks: siblings.yaml + - name: Build a docker image command: >- docker buildx build {{ zj_image.path | default('.') }} -f {{ zj_image.dockerfile | default(docker_dockerfile) }} @@ -34,3 +37,6 @@ loop: "{{ zj_image.tags | default(['latest']) }}" loop_control: loop_var: zj_image_tag + +- name: Cleanup sibling source directory + include_tasks: clean-siblings.yaml diff --git a/roles/build-docker-image/tasks/clean-siblings.yaml b/roles/build-docker-image/tasks/clean-siblings.yaml new file mode 100644 index 000000000..0c59e0335 --- /dev/null +++ b/roles/build-docker-image/tasks/clean-siblings.yaml @@ -0,0 +1,4 @@ +- name: Cleanup sibling source directory + file: + path: '{{ zuul_work_dir }}/{{ zj_image.context }}/.zuul-siblings' + state: absent diff --git a/roles/build-docker-image/tasks/main.yaml b/roles/build-docker-image/tasks/main.yaml index 8510a86dc..dfd091c1e 100644 --- a/roles/build-docker-image/tasks/main.yaml +++ b/roles/build-docker-image/tasks/main.yaml @@ -14,12 +14,6 @@ - result_json_stat.stat.size > 0 - "'buildset_registry' in (lookup('file', zuul.executor.work_root + '/results.json') | from_json)" -- name: Set up siblings - include_tasks: siblings.yaml - loop: "{{ docker_images }}" - loop_control: - loop_var: zj_image - # Docker doesn't understand docker push [1234:5678::]:5000/image/path:tag # so we set up /etc/hosts with a registry alias name to support ipv6 and 4. - name: Configure /etc/hosts for buildset_registry to workaround docker not understanding ipv6 addresses diff --git a/test-playbooks/registry/docker-siblings/Dockerfile b/test-playbooks/registry/docker-siblings/Dockerfile index 18e777555..061d84aec 100644 --- a/test-playbooks/registry/docker-siblings/Dockerfile +++ b/test-playbooks/registry/docker-siblings/Dockerfile @@ -1,7 +1,10 @@ -FROM docker.io/upstream/image +FROM docker.io/upstream/image as first ARG ZUUL_SIBLINGS="" RUN echo "Zuul siblings: ${ZUUL_SIBLINGS}" RUN cp /test-nonce /test-nonce-is-there COPY .zuul-siblings/opendev.org/project/fake-sibling/file /target COPY .zuul-siblings/openstack.org/project/fake-sibling/file /target CMD echo "Zuul container test"; sleep infinity + +FROM first as second +RUN echo "This is just to test that loops with siblings work" diff --git a/test-playbooks/registry/test-registry.yaml b/test-playbooks/registry/test-registry.yaml index 727334e3a..91031d51b 100644 --- a/test-playbooks/registry/test-registry.yaml +++ b/test-playbooks/registry/test-registry.yaml @@ -140,9 +140,24 @@ siblings: - opendev.org/project/fake-sibling - openstack.org/project/fake-sibling + target: first + - context: test-playbooks/registry/docker-siblings + repository: downstream/image2 + target: second + siblings: + - opendev.org/project/fake-sibling + - openstack.org/project/fake-sibling _arch_docker_images: - context: test-playbooks/registry/docker-siblings repository: downstream/image + target: first + siblings: + - opendev.org/project/fake-sibling + - openstack.org/project/fake-sibling + arch: ['linux/amd64', 'linux/arm64'] + - context: test-playbooks/registry/docker-siblings + repository: downstream/image2 + target: second siblings: - opendev.org/project/fake-sibling - openstack.org/project/fake-sibling