zuul-jobs/roles/build-container-image/tasks/build.yaml
Ian Wienand 29d55cbf17 build-container-image: support sibling copy
Add support for "siblings:" to the build-container-image role.  This
is a port of change I079d823e7194e15b1b496aea0f53f70f6b563f02 from the
build-docker-image role.

Note that we found a couple of issues with this role, fixed with
I9f3b0a1f71d20cf7511f224648dd2fa51a039015.  However,
build-container-image has merged before this fix, so thess fixes now
follow this change.  To avoid squashing this into something confusing
this update incorporates those fixes.  However testing is left to the
follow-on change because the extant build-docker-image role would fail
the corrected testing.  They should be merged roughly together.

One minor thing is the removal of an additional duplicated "tags:"
entry from the variable documentation.

Change-Id: I71e2f2ab29446bd113644ce8c75378b8d3ef8ba6
2019-12-09 11:13:42 +11:00

51 lines
1.6 KiB
YAML

- name: Check sibling directory
stat:
path: '{{ zuul_work_dir }}/{{ item.context }}/.zuul-siblings'
register: _dot_zuul_siblings
# This should have been cleaned up; multiple builds may specify
# different siblings to include so we need to start fresh.
- name: Check for clean build
assert:
that: not _dot_zuul_siblings.stat.exists
- name: Create sibling source directory
file:
path: '{{ zuul_work_dir }}/{{ item.context }}/.zuul-siblings'
state: directory
mode: 0755
when: item.siblings is defined
- name: Copy sibling source directories
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
when: item.siblings is defined
- name: Build a container image
command: >-
{{ container_command }} build {{ item.path | default('.') }} {% if containerfile %}-f {{ containerfile }}{% endif %}
{% if item.target | default(false) -%}
--target {{ item.target }}
{% endif -%}
{% for build_arg in item.build_args | default([]) -%}
--build-arg {{ build_arg }}
{% endfor -%}
{% if items.siblings | default(false) -%}
--build-arg "ZUUL_SIBLINGS={{ item.siblings | join(' ') }}"
{% endif -%}
{% for tag in item.tags | default(['latest']) -%}
--tag {{ item.repository }}:change_{{ zuul.change }}_{{ tag }}
--tag {{ item.repository }}:{{ tag }}
{% endfor -%}
args:
chdir: "{{ zuul_work_dir }}/{{ item.context }}"
- name: Cleanup sibling source directory
file:
path: '{{ zuul_work_dir }}/.zuul-siblings'
state: absent