From 599954715effa2550a190cdeec52a6a377ef5d02 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 6 Dec 2019 14:31:10 +1100 Subject: [PATCH] build-docker-image: fix up siblings copy There are a number of issues with this. Firstly, it needs to copy the parent directories to make a heirarchy in the .zuul-siblings directory. The current "cp -r" was only copying the final directory. Switch into the source directory and use "--parent" to do this. Also, it should be copying into the context dir. Add the {{ item.context }} to the path where appropriate. Make new testing image that copies in files from the siblings. Because COPY will fail if the sources aren't there, this is like an assert that we copied it correctly. Change-Id: I9f3b0a1f71d20cf7511f224648dd2fa51a039015 --- roles/build-docker-image/tasks/build.yaml | 8 +++++--- .../registry/docker-siblings/Dockerfile | 6 ++++++ test-playbooks/registry/test-registry.yaml | 15 +++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 test-playbooks/registry/docker-siblings/Dockerfile diff --git a/roles/build-docker-image/tasks/build.yaml b/roles/build-docker-image/tasks/build.yaml index 99eac9b19..b0ba340f3 100644 --- a/roles/build-docker-image/tasks/build.yaml +++ b/roles/build-docker-image/tasks/build.yaml @@ -1,6 +1,6 @@ - name: Check sibling directory stat: - path: '{{ zuul_work_dir }}/.zuul-siblings' + path: '{{ zuul_work_dir }}/{{ item.context }}/.zuul-siblings' register: _dot_zuul_siblings # This should have been cleaned up; multiple builds may specify @@ -11,7 +11,7 @@ - name: Create sibling source directory file: - path: '{{ zuul_work_dir }}/.zuul-siblings' + path: '{{ zuul_work_dir }}/{{ item.context }}/.zuul-siblings' state: directory mode: 0755 when: item.siblings is defined @@ -19,7 +19,9 @@ # NOTE(ianw): could use recursive copy: with remote_src, but it's # Ansible 2.8 only. take the simple approach. - name: Copy sibling source directories - command: 'cp -r ~/src/{{ sibling }} {{ zuul_work_dir }}/.zuul-siblings/' + command: + cmd: 'cp --parents -r {{ sibling }} /home/zuul/{{ zuul_work_dir }}/{{ item.context }}/.zuul-siblings' + chdir: '~/src' loop: '{{ item.siblings }}' loop_control: loop_var: sibling diff --git a/test-playbooks/registry/docker-siblings/Dockerfile b/test-playbooks/registry/docker-siblings/Dockerfile new file mode 100644 index 000000000..8907b1e30 --- /dev/null +++ b/test-playbooks/registry/docker-siblings/Dockerfile @@ -0,0 +1,6 @@ +FROM docker.io/library/debian:testing +ARG ZUUL_SIBLINGS="" +RUN echo "Zuul siblings: ${ZUUL_SIBLINGS}" +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 diff --git a/test-playbooks/registry/test-registry.yaml b/test-playbooks/registry/test-registry.yaml index 408629c61..b45734ab8 100644 --- a/test-playbooks/registry/test-registry.yaml +++ b/test-playbooks/registry/test-registry.yaml @@ -125,23 +125,22 @@ - name: Create fake sibling projects command: >- - mkdir -p src/opendev.org/fake-sibling-1 && - mkdir -p src/opendev.org/fake-sibling-2 && - touch src/opendev.org/fake-sibling-1/file && - touch src/opendev.org/fake-sibling-2/file + mkdir -p src/opendev.org/project/fake-sibling && + mkdir -p src/openstack.org/project/fake-sibling && + touch src/opendev.org/project/fake-sibling/file && + touch src/openstack.org/project/fake-sibling/file - name: Build docker image include_role: name: "build-{{ (container_command == 'docker') | ternary('docker', 'container') }}-image" vars: docker_images: - - context: test-playbooks/registry/docker + - context: test-playbooks/registry/docker-siblings repository: downstream/image siblings: - - opendev.org/fake-sibling-1 - - opendev.org/fake-sibling-2 + - opendev.org/project/fake-sibling + - openstack.org/project/fake-sibling container_images: "{{ docker_images }}" - - hosts: executor name: Test pushing to the intermediate registry tasks: