Skip to content

Commit 7cef2ee

Browse files
mkolesniktpantelis
authored andcommitted
Convert env vars to args in build_image.sh
The Dockerfile and hash file and mandatory, so there's no real sense in receiving them as optional ENV vars, it's much easier to just recieve them as positional arguments. This shouldn't affect consuming project as they don't call this script directly. Signed-off-by: Mike Kolesnik <[email protected]>
1 parent 7c245cc commit 7cef2ee

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

Makefile.images

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ REPO ?= quay.io/submariner
1010
# Affecting multiple commands
1111
export REPO ?= quay.io/submariner
1212

13+
# Specific to `build_images.sh`
14+
export USE_CACHE ?= true
15+
1316
# Specific to `images`
14-
export DOCKERFILE HASHFILE OCIFILE PLATFORM
17+
export OCIFILE PLATFORM
1518

1619
# Specific to `release-images`
1720
export TAG ?= $(CUTTING_EDGE)
@@ -32,12 +35,12 @@ docker_deps = $(shell files=($(1) $$(awk '/COPY/ && substr($$2, 1, 7) != "--from
3235
# An empty file is used for make to figure out if dependencies changed or not
3336
.SECONDEXPANSION:
3437
package/.image.%: $$(call docker_deps,package/Dockerfile.$$*) $$(call force_image_rebuild,$$*)
35-
DOCKERFILE="$<" HASHFILE="$@" $(SCRIPTS_DIR)/build_image.sh $*
38+
$(SCRIPTS_DIR)/build_image.sh $* $< $@
3639

3740
# Build an OCI tarball from a Dockerfile
3841
.SECONDEXPANSION:
3942
package/%.tar: $$(call docker_deps,package/Dockerfile.$$*) $$(call force_image_rebuid,$$*)
40-
DOCKERFILE="$<" OCIFILE="$@" HASHFILE="package/.image.$*" $(SCRIPTS_DIR)/build_image.sh $*
43+
OCIFILE="$@" $(SCRIPTS_DIR)/build_image.sh $* $< package/.image.$*
4144

4245
# [images] builds all the container images for the project
4346
# Default target to build images based on IMAGES variable

scripts/shared/build_image.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22

33
set -e
44

5-
### Variables ###
6-
7-
[[ -n "${USE_CACHE}" ]] || USE_CACHE='true'
8-
[[ $# == 1 ]] || { echo "Exactly one image to build must be specified!"; exit 1; }
9-
[[ -n "${DOCKERFILE}" ]] || { echo "The DOCKERFILE to build from must be specified!"; exit 1; }
10-
[[ -n "${HASHFILE}" ]] || { echo "The HASHFILE to write the hash to must be specified!"; exit 1; }
5+
[[ $# == 3 ]] || { echo "You must specify exactly 3 arguments: The image name, the Dockerfile and a hash file to write to"; exit 1; }
116
if [[ "${PLATFORM}" =~ , && -z "${OCIFILE}" ]]; then
127
echo Multi-arch builds require OCI output, please set OCIFILE
138
exit 1
149
fi
1510

1611
source "${SCRIPTS_DIR}/lib/utils"
17-
print_env DOCKERFILE HASHFILE OCIFILE PLATFORM REPO
12+
print_env OCIFILE PLATFORM REPO
1813
source "${SCRIPTS_DIR}/lib/debug_functions"
1914

15+
### Arguments ###
16+
17+
image="$1"
18+
dockerfile="$2"
19+
hashfile="$3"
20+
2021
### Main ###
2122

22-
local_image="${REPO}/${1}:${DEV_VERSION}"
23-
cache_image="${REPO}/${1}:${CUTTING_EDGE}"
23+
local_image="${REPO}/${image}:${DEV_VERSION}"
24+
cache_image="${REPO}/${image}:${CUTTING_EDGE}"
2425

2526
# When using cache pull latest image from the repo, so that its layers may be reused.
2627
declare -a cache_flags
@@ -38,7 +39,7 @@ if [[ "${USE_CACHE}" = true ]]; then
3839
if (!($i ~ /^--platform/ || $i ~ /scratch/))
3940
print gensub("\\${BASE_BRANCH}", ENVIRON["BASE_BRANCH"], "g", $i)
4041
}
41-
}' "${DOCKERFILE}"); do
42+
}' "${dockerfile}"); do
4243
cache_flags+=(--cache-from "${parent}")
4344
docker pull "${parent}" || :
4445
done
@@ -60,13 +61,13 @@ fi
6061
buildargs_flags=(--build-arg BUILDKIT_INLINE_CACHE=1 --build-arg "BASE_BRANCH=${BASE_BRANCH}")
6162
if [[ "${PLATFORM}" != "${default_platform}" ]] && docker buildx version > /dev/null 2>&1; then
6263
docker buildx use buildx_builder || docker buildx create --name buildx_builder --use
63-
docker buildx build "${output_flag}" -t "${local_image}" "${cache_flags[@]}" -f "${DOCKERFILE}" --iidfile "${HASHFILE}" --platform "${PLATFORM}" "${buildargs_flags[@]}" .
64+
docker buildx build "${output_flag}" -t "${local_image}" "${cache_flags[@]}" -f "${dockerfile}" --iidfile "${hashfile}" --platform "${PLATFORM}" "${buildargs_flags[@]}" .
6465
else
6566
# Fall back to plain BuildKit
6667
if [[ "${PLATFORM}" != "${default_platform}" ]]; then
6768
echo "WARNING: buildx isn't available, cross-arch builds won't work as expected"
6869
fi
69-
DOCKER_BUILDKIT=1 docker build -t "${local_image}" "${cache_flags[@]}" -f "${DOCKERFILE}" --iidfile "${HASHFILE}" "${buildargs_flags[@]}" .
70+
DOCKER_BUILDKIT=1 docker build -t "${local_image}" "${cache_flags[@]}" -f "${dockerfile}" --iidfile "${hashfile}" "${buildargs_flags[@]}" .
7071
fi
7172

7273
# We can only tag the image in non-OCI mode

0 commit comments

Comments
 (0)