From 0e50a2bb89525874c6f12b458356a5f6feff78c2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 24 Jan 2019 11:28:02 +0100 Subject: [PATCH] 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 --- roles/build-docker-image/common.rst | 15 +++++++++++++++ roles/build-docker-image/defaults/main.yaml | 1 + roles/build-docker-image/tasks/main.yaml | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/roles/build-docker-image/common.rst b/roles/build-docker-image/common.rst index affb19fc4..95d37adcf 100644 --- a/roles/build-docker-image/common.rst +++ b/roles/build-docker-image/common.rst @@ -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 diff --git a/roles/build-docker-image/defaults/main.yaml b/roles/build-docker-image/defaults/main.yaml index 9739eb171..d702500de 100644 --- a/roles/build-docker-image/defaults/main.yaml +++ b/roles/build-docker-image/defaults/main.yaml @@ -1 +1,2 @@ zuul_work_dir: "{{ zuul.project.src_dir }}" +docker_dockerfile: "Dockerfile" diff --git a/roles/build-docker-image/tasks/main.yaml b/roles/build-docker-image/tasks/main.yaml index 5b8fe616b..653dc54c1 100644 --- a/roles/build-docker-image/tasks/main.yaml +++ b/roles/build-docker-image/tasks/main.yaml @@ -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 -%}