buildkit/hack/images

99 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
. $(dirname $0)/util
TAG=$1
REPO=$2
PUSH=$3
set -eu -o pipefail
: ${PLATFORMS=linux/amd64}
: ${CONTINUOUS_INTEGRATION=}
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
gitTag=$(git describe --tags --match "v[0-9]*")
usage() {
echo "usage: $0 <tag> <repo> [push]"
exit 1
}
if [ -z "$TAG" ] || [ -z "$REPO" ]; then
usage
fi
imageDocker() {
if echo $PLATFORMS | grep , >/dev/null; then
echo "PREFER_BUILDCTL=1 needs to be set to build images for $PLATFORMS"
exit 1
fi
set -x
docker build $progressFlag --platform=$PLATFORMS -t $REPO:$TAG .
docker build $progressFlag --platform=$PLATFORMS -t $REPO:$TAG-rootless --target rootless .
set +x
if [ "$PUSH" = "push" ]; then
set -x
docker push $REPO:$TAG
docker push $REPO:$TAG-rootless
set +x
fi
if [[ "$gitTag" == "$TAG" ]]; then
set -x
docker tag $REPO:$TAG $REPO:latest
docker tag $REPO:$TAG-rootless $REPO:rootless
set +x
if [ "$PUSH" = "push" ]; then
set -x
docker push $REPO:latest
docker push $REPO:rootless
set +x
fi
fi
}
image() {
pushFlag=""
if [ "$PUSH" = "push" ]; then
pushFlag="push=true"
fi
tagLatest=""
tagLatestRootless=""
if [[ "$gitTag" == "$TAG" ]]; then
tagLatest=",$REPO:latest"
tagLatestRootless=",$REPO:rootless"
fi
set -x
buildctl build $progressFlag --frontend=dockerfile.v0 \
--local context=. --local dockerfile=. \
--opt platform=$PLATFORMS \
--export-cache type=inline \
--output type=image,\"name=$REPO:$TAG$tagLatest\",$pushFlag
buildctl build $progressFlag --frontend=dockerfile.v0 \
--local context=. --local dockerfile=. \
--opt target=rootless \
--opt platform=$PLATFORMS \
--export-cache type=inline \
--output type=image,\"name=$REPO:$TAG-rootless$tagLatestRootless\",$pushFlag
}
case $buildmode in
"buildkit")
image
;;
"docker-buildkit")
imageDocker
;;
*)
echo "Unsupported build mode: $buildmode" >&2
exit 1
;;
esac