blob: 35fac92c24e9ee0b2f713191e31b22606c5b9d24 [file] [log] [blame]
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001# SPDX-FileCopyrightText: Andrei Gherzan <andrei.gherzan@huawei.com>
2#
3# SPDX-License-Identifier: MIT
4
5name: "Build a docker image"
6
7inputs:
8 docker_image:
9 required: true
10 description: "The name of the docker image"
11 id:
12 required: true
13 description: "Namespace for the image"
14
15runs:
16 using: "composite"
17 steps:
18 - name: Build the ${{ inputs.docker_image }} docker image
19 shell: bash
20 # We run this unconditinally even if the change doesn't touch the
21 # relevant docker files because there is a chance that another PR (or
22 # something else) rebuilt the local image. For example if the first
23 # version of the PR included change for the relevant docker image but a
24 # subsequent push to the PR branch dropped them. In this way we rebuild
25 # the image to avoid using the changes from the previous push.
26 run: |
27 cd .github/workflows/docker-images/
28 # We build a temporary image namespaced by the PR number so we can
29 # handle multiple runners on the same host using the same docker
30 # storage.
31 tries=3
32 n=1
33 until [ "$n" -gt "$tries" ]; do
34 echo "Building the docker image ${{ inputs.docker_image }}-${{ inputs.id }}... try $n..."
35 if docker build . -f "${{ inputs.docker_image }}/Dockerfile" -t "${{ inputs.docker_image }}-${{ inputs.id }}"; then
36 # This can fail if a dangling images cleaning job runs in
37 # parallel. So we try this a couple of times to minimize
38 # conflict. This is because while building, docker creates a
39 # untagged image first (dangling) before tagging it at the end.
40 # If between these two operations a dangling cleanup happens,
41 # build fails.
42 break
43 fi
44 n=$((n+1))
45 done
46 [ "$n" -lt "$tries" ]
47 echo "Temporary image built in ${{ inputs.docker_image }}."