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
|
|
|
|
|
|
|
|
imageDockerCommon() {
|
|
|
|
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 $@ --platform=$PLATFORMS -t $REPO:$TAG .
|
|
|
|
docker build $@ --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
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
imageLegacy() {
|
|
|
|
imageDockerCommon -f ./hack/dockerfiles/test.Dockerfile
|
|
|
|
}
|
|
|
|
|
|
|
|
imageDocker() {
|
|
|
|
imageDockerCommon $progressFlag -f ./hack/dockerfiles/test.buildkit.Dockerfile
|
|
|
|
}
|
|
|
|
|
|
|
|
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=. \
|
|
|
|
--frontend-opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
|
|
|
|
--frontend-opt platform=$PLATFORMS \
|
2019-03-19 03:16:27 +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=. \
|
|
|
|
--frontend-opt target=rootless \
|
|
|
|
--frontend-opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
|
|
|
|
--frontend-opt platform=$PLATFORMS \
|
2019-03-19 03:16:27 +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
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
imageLegacy
|
|
|
|
;;
|
|
|
|
esac
|