Merge "build-container-image: support sibling copy"
This commit is contained in:
@@ -133,10 +133,15 @@ role to install Docker or Podman before using these roles.
|
|||||||
|
|
||||||
A list of tags to be added to the image when promoted.
|
A list of tags to be added to the image when promoted.
|
||||||
|
|
||||||
.. zuul:rolevar:: tags
|
.. zuul:rolevar:: siblings
|
||||||
:type: list
|
:type: list
|
||||||
:default: ['latest']
|
:default: []
|
||||||
|
|
||||||
A list of tags to be added to the image when promoted.
|
A list of sibling projects to be copied into
|
||||||
|
``{{zuul_work_dir}}/.zuul-siblings``. This can be useful to
|
||||||
|
collect multiple projects to be installed within the same Docker
|
||||||
|
context. A ``-build-arg`` called ``ZUUL_SIBLINGS`` will be
|
||||||
|
added with each sibling project. Note that projects here must
|
||||||
|
be listed in ``required-projects``.
|
||||||
|
|
||||||
.. _anchors: https://yaml.org/spec/1.2/spec.html#&%20anchor//
|
.. _anchors: https://yaml.org/spec/1.2/spec.html#&%20anchor//
|
||||||
|
|||||||
50
roles/build-container-image/tasks/build.yaml
Normal file
50
roles/build-container-image/tasks/build.yaml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
- 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
|
||||||
@@ -4,25 +4,15 @@
|
|||||||
set_fact:
|
set_fact:
|
||||||
buildset_registry: "{{ (lookup('file', zuul.executor.work_root + '/results.json') | from_json)['buildset_registry'] }}"
|
buildset_registry: "{{ (lookup('file', zuul.executor.work_root + '/results.json') | from_json)['buildset_registry'] }}"
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Set container filename arg
|
- name: Set container filename arg
|
||||||
set_fact:
|
set_fact:
|
||||||
containerfile: "{{ item.container_filename|default(container_filename|default('')) }}"
|
containerfile: "{{ item.container_filename|default(container_filename|default('')) }}"
|
||||||
- name: Build a container image
|
|
||||||
command: >-
|
- name: Build container images
|
||||||
{{ container_command }} build {{ item.path | default('.') }} {% if containerfile %}-f {{ containerfile }}{% endif %}
|
include_tasks: build.yaml
|
||||||
{% if item.target | default(false) -%}
|
|
||||||
--target {{ item.target }}
|
|
||||||
{% endif -%}
|
|
||||||
{% for build_arg in item.build_args | default([]) -%}
|
|
||||||
--build-arg {{ build_arg }}
|
|
||||||
{% endfor -%}
|
|
||||||
{% 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 }}"
|
|
||||||
loop: "{{ container_images }}"
|
loop: "{{ container_images }}"
|
||||||
|
|
||||||
# Docker, and therefore skopeo and podman, don't understand docker
|
# Docker, and therefore skopeo and podman, don't understand docker
|
||||||
# push [1234:5678::]:5000/image/path:tag so we set up /etc/hosts with
|
# push [1234:5678::]:5000/image/path:tag so we set up /etc/hosts with
|
||||||
# a registry alias name to support ipv6 and 4.
|
# a registry alias name to support ipv6 and 4.
|
||||||
|
|||||||
Reference in New Issue
Block a user