Allow different filenames for Dockerfiles

In certain build projects, multiple Dockerfiles exist (for example,
one per distro) to simplify reading. However, this role is hardwired
to use dockerfiles only named "Dockerfile".

This is a problem, as you can't override the filename neither per
image, or globally.

This should fix the problem, allowing certain images to be build
by providing the dockerfile argument in docker_images, but also
have a globally overridable flag if you are using a different
convention (for example Dockerfile.distro_minordistroversion).

Change-Id: I075c365bc9f4f85f9ada832d22d1f1e213e68e21
This commit is contained in:
Jean-Philippe Evrard 2019-01-24 11:28:02 +01:00
parent caebca1387
commit 0e50a2bb89
3 changed files with 17 additions and 1 deletions

View File

@ -42,6 +42,15 @@ using this role.
The project directory. Serves as the base for
:zuul:rolevar:`build-docker-image.docker_images.context`.
.. zuul:rolevar:: docker_dockerfile
:default: Dockerfile
The default Dockerfile name to use. Serves as the base for
:zuul:rolevar:`build-docker-image.docker_images.dockerfile`.
This allows a global overriding of Dockerfile name, for example
when building all images from different folders with similarily
named dockerfiles.
.. zuul:rolevar:: docker_credentials
:type: dict
@ -75,6 +84,12 @@ using this role.
The docker build context; this should be a directory underneath
:zuul:rolevar:`build-docker-image.zuul_work_dir`.
.. zuul:rolevar:: dockerfile
The filename of the dockerfile, present in the context folder,
used for building the image. Provide this if you are using
a non-standard filename for a specific image.
.. zuul:rolevar:: repository
The name of the target repository in dockerhub for the

View File

@ -1 +1,2 @@
zuul_work_dir: "{{ zuul.project.src_dir }}"
docker_dockerfile: "Dockerfile"

View File

@ -1,6 +1,6 @@
- name: Build a docker image
command: >-
docker build {{ item.path | default('.') }} -f Dockerfile
docker build {{ item.path | default('.') }} -f {{ item.dockerfile | default(docker_dockerfile) }}
{% if item.target | default(false) -%}
--target {{ item.target }}
{% endif -%}