52 lines
1.6 KiB
Bash
52 lines
1.6 KiB
Bash
#!/bin/sh
|
|
# vim: syntax=sh
|
|
|
|
set -euo pipefail
|
|
|
|
[[- range $k, $v := .docker.base_images ]]
|
|
function build_[[ $k ]] {
|
|
[[- $image := printf "%s/%s" ($.docker.repo | regexp.Replace "/$" "") $v.image ]]
|
|
if [ "${IMAGE_[[ $k | toUpper ]]_AVAILABLE:-0}" = "1" ]; then
|
|
echo "Image [[ $image ]] already available"
|
|
return
|
|
fi
|
|
[[- if has $v "depends_on" ]]
|
|
[[- if isKind "string" $v.depends_on ]]
|
|
# Image [[ $k ]] depends on [[ $v.depends_on ]]
|
|
build_[[ $v.depends_on ]]
|
|
[[- else if isKind "slice" $v.depends_on ]]
|
|
[[- range $dep := $v.depends_on ]]
|
|
# Image [[ $k ]] depends on [[ $dep ]]
|
|
build_[[ $dep ]]
|
|
[[- end ]]
|
|
[[- end ]]
|
|
[[- end ]]
|
|
if ! docker manifest inspect [[ $image ]] > /dev/null 2>&1; then
|
|
echo "Building [[ $v.image ]]"
|
|
export BUILDKIT_PROGRESS=plain
|
|
docker build -t [[ $image ]]
|
|
[[- if has $v "tags" ]]
|
|
[[- range $index, $tag := $v.tags ]] -t [[ $.docker.repo | regexp.Replace "/$" "" ]]/[[ $tag ]][[ end ]]
|
|
[[- end -]]
|
|
[[- if has $v "build_args" ]]
|
|
[[- range $arg, $val := $v.build_args ]] --build-arg=[[ $arg ]]=[[ $val ]][[ end ]]
|
|
[[- end ]] output/images/[[ $v.image | regexp.Replace ":.*" "" ]] &&\
|
|
docker push [[ $image ]] &&\
|
|
[[- if has $v "tags" ]]
|
|
[[- range $index, $tag := $v.tags ]]
|
|
docker push [[ $.docker.repo | regexp.Replace "/$" "" ]]/[[ $tag ]] &&\
|
|
[[- end ]]
|
|
[[- end ]]
|
|
echo "[[ $image ]] pushed to remote repo"
|
|
else
|
|
echo "Image [[ $image ]] already available"
|
|
fi
|
|
IMAGE_[[ $k | toUpper ]]_AVAILABLE=1
|
|
}
|
|
|
|
[[- end ]]
|
|
|
|
[[- range $k, $v := .docker.base_images ]]
|
|
build_[[ $k ]]
|
|
[[- end ]]
|