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
This commit is contained in:
Ian Wienand 2019-12-06 14:31:10 +11:00
parent 29d55cbf17
commit 599954715e
3 changed files with 18 additions and 11 deletions

View File

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

View File

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

View File

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