2
2
3
3
set -e
4
4
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; }
11
6
if [[ " ${PLATFORM} " =~ , && -z " ${OCIFILE} " ]]; then
12
7
echo Multi-arch builds require OCI output, please set OCIFILE
13
8
exit 1
14
9
fi
15
10
16
11
source " ${SCRIPTS_DIR} /lib/utils"
17
- print_env DOCKERFILE HASHFILE OCIFILE PLATFORM REPO
12
+ print_env OCIFILE PLATFORM REPO
18
13
source " ${SCRIPTS_DIR} /lib/debug_functions"
19
14
15
+ # ## Arguments ###
16
+
17
+ image=" $1 "
18
+ dockerfile=" $2 "
19
+ hashfile=" $3 "
20
+
20
21
# ## Main ###
21
22
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} "
24
25
25
26
# When using cache pull latest image from the repo, so that its layers may be reused.
26
27
declare -a cache_flags
@@ -38,7 +39,7 @@ if [[ "${USE_CACHE}" = true ]]; then
38
39
if (!($i ~ /^--platform/ || $i ~ /scratch/))
39
40
print gensub("\\${BASE_BRANCH}", ENVIRON["BASE_BRANCH"], "g", $i)
40
41
}
41
- }' " ${DOCKERFILE } " ) ; do
42
+ }' " ${dockerfile } " ) ; do
42
43
cache_flags+=(--cache-from " ${parent} " )
43
44
docker pull " ${parent} " || :
44
45
done
60
61
buildargs_flags=(--build-arg BUILDKIT_INLINE_CACHE=1 --build-arg " BASE_BRANCH=${BASE_BRANCH} " )
61
62
if [[ " ${PLATFORM} " != " ${default_platform} " ]] && docker buildx version > /dev/null 2>&1 ; then
62
63
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[@]} " .
64
65
else
65
66
# Fall back to plain BuildKit
66
67
if [[ " ${PLATFORM} " != " ${default_platform} " ]]; then
67
68
echo " WARNING: buildx isn't available, cross-arch builds won't work as expected"
68
69
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[@]} " .
70
71
fi
71
72
72
73
# We can only tag the image in non-OCI mode
0 commit comments