2019-03-01 08:04:59 +00:00
|
|
|
#!/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
|
|
|
|
|
2019-10-18 07:36:14 +00:00
|
|
|
imageDocker() {
|
2019-03-01 08:04:59 +00:00
|
|
|
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
|
2019-10-18 07:36:14 +00:00
|
|
|
docker build $progressFlag --platform=$PLATFORMS -t $REPO:$TAG .
|
|
|
|
docker build $progressFlag --platform=$PLATFORMS -t $REPO:$TAG-rootless --target rootless .
|
2019-03-01 08:04:59 +00:00
|
|
|
set +x
|
|
|
|
|
|
|
|
if [ "$PUSH" = "push" ]; then
|
|
|
|
set -x
|
|
|
|
docker push $REPO:$TAG
|
|
|
|
docker push $REPO:$TAG-rootless
|
|
|
|
set +x
|
|
|
|
fi
|
2019-03-14 23:15:41 +00:00
|
|
|
if [[ "$gitTag" == "$TAG" ]]; then
|
2019-03-01 08:04:59 +00:00
|
|
|
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
|
2019-03-19 03:16:27 +00:00
|
|
|
pushFlag="push=true"
|
2019-03-01 08:04:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
tagLatest=""
|
|
|
|
tagLatestRootless=""
|
2019-03-14 23:15:41 +00:00
|
|
|
if [[ "$gitTag" == "$TAG" ]]; then
|
2019-03-01 08:04:59 +00:00
|
|
|
tagLatest=",$REPO:latest"
|
|
|
|
tagLatestRootless=",$REPO:rootless"
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
buildctl build $progressFlag --frontend=dockerfile.v0 \
|
|
|
|
--local context=. --local dockerfile=. \
|
2019-03-20 10:18:16 +00:00
|
|
|
--opt platform=$PLATFORMS \
|
2019-08-08 00:50:00 +00:00
|
|
|
--export-cache type=inline \
|
2019-04-26 23:58:28 +00:00
|
|
|
--output type=image,\"name=$REPO:$TAG$tagLatest\",$pushFlag
|
2019-03-01 08:04:59 +00:00
|
|
|
|
|
|
|
buildctl build $progressFlag --frontend=dockerfile.v0 \
|
|
|
|
--local context=. --local dockerfile=. \
|
2019-03-20 10:18:16 +00:00
|
|
|
--opt target=rootless \
|
|
|
|
--opt platform=$PLATFORMS \
|
2019-08-08 00:50:00 +00:00
|
|
|
--export-cache type=inline \
|
2019-04-26 23:58:28 +00:00
|
|
|
--output type=image,\"name=$REPO:$TAG-rootless$tagLatestRootless\",$pushFlag
|
2019-03-01 08:04:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case $buildmode in
|
|
|
|
"buildkit")
|
|
|
|
image
|
|
|
|
;;
|
|
|
|
"docker-buildkit")
|
|
|
|
imageDocker
|
|
|
|
;;
|
|
|
|
*)
|
2019-10-12 15:03:30 +00:00
|
|
|
echo "Unsupported build mode: $buildmode" >&2
|
|
|
|
exit 1
|
2019-03-01 08:04:59 +00:00
|
|
|
;;
|
|
|
|
esac
|