Browse Source

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
changes/79/632979/3
Jean-Philippe Evrard 5 months ago
parent
commit
0e50a2bb89

+ 15
- 0
roles/build-docker-image/common.rst View File

@@ -42,6 +42,15 @@ using this role.
42 42
    The project directory.  Serves as the base for
43 43
    :zuul:rolevar:`build-docker-image.docker_images.context`.
44 44
 
45
+.. zuul:rolevar:: docker_dockerfile
46
+   :default: Dockerfile
47
+
48
+   The default Dockerfile name to use. Serves as the base for
49
+   :zuul:rolevar:`build-docker-image.docker_images.dockerfile`.
50
+   This allows a global overriding of Dockerfile name, for example
51
+   when building all images from different folders with similarily
52
+   named dockerfiles.
53
+
45 54
 .. zuul:rolevar:: docker_credentials
46 55
    :type: dict
47 56
 
@@ -75,6 +84,12 @@ using this role.
75 84
       The docker build context; this should be a directory underneath
76 85
       :zuul:rolevar:`build-docker-image.zuul_work_dir`.
77 86
 
87
+   .. zuul:rolevar:: dockerfile
88
+
89
+      The filename of the dockerfile, present in the context folder,
90
+      used for building the image. Provide this if you are using
91
+      a non-standard filename for a specific image.
92
+
78 93
    .. zuul:rolevar:: repository
79 94
 
80 95
       The name of the target repository in dockerhub for the

+ 1
- 0
roles/build-docker-image/defaults/main.yaml View File

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

+ 1
- 1
roles/build-docker-image/tasks/main.yaml View File

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

Loading…
Cancel
Save