buildkit/hack/binaries

85 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
. $(dirname $0)/util
: ${TARGETPLATFORM=}
: ${CONTINUOUS_INTEGRATION=}
set -ex
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
binariesLegacy() {
mkdir -p bin
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
copysrc="/usr/bin/."
case "$(echo "$TARGETPLATFORM" | cut -d"/" -f1)" in
"darwin")
docker build --iidfile $iidfile --target buildctl-darwin -f ./hack/dockerfiles/test.Dockerfile --force-rm .
copysrc="/out/."
;;
"windows")
docker build --iidfile $iidfile --build-arg BUILDKITD_TAGS="${BUILDKITD_TAGS}" --target buildctl.exe -f ./hack/dockerfiles/test.Dockerfile --force-rm .
copysrc="/out/."
;;
*)
docker build --iidfile $iidfile --build-arg BUILDKITD_TAGS="${BUILDKITD_TAGS}" --target buildkit-binaries -f ./hack/dockerfiles/test.Dockerfile --force-rm .
;;
esac
iid=$(cat $iidfile)
containerID=$(docker create $iid copy)
docker cp $containerID:$copysrc bin
docker rm $containerID
chmod +x bin/*
rm -f $iidfile
}
binariesDocker() {
mkdir -p bin/tmp
export DOCKER_BUILDKIT=1
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
target=$(echo "$TARGETPLATFORM" | cut -d"/" -f1)
if [ -z "$target" ]; then
target="linux"
fi
docker build $platformFlag --build-arg BUILDKITD_TAGS="${BUILDKITD_TAGS}" --target binaries-$target --iidfile $iidfile -f ./hack/dockerfiles/test.buildkit.Dockerfile --force-rm .
iid=$(cat $iidfile)
containerID=$(docker create $iid copy)
docker cp $containerID:/ bin/tmp
mv bin/tmp/build* bin/
rm -rf bin/tmp
docker rm $containerID
docker rmi -f $iid
rm -f $iidfile
}
binaries() {
platformFlag=""
if [ ! -z "$TARGETPLATFORM" ]; then
platformFlag="--opt platform=$TARGETPLATFORM"
fi
buildctl build $progressFlag --frontend=dockerfile.v0 \
--local context=. --local dockerfile=. \
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
--opt build-arg:BUILDKITD_TAGS="$BUILDKITD_TAGS" \
--opt target=binaries $platformFlag \
--output type=local,dest=./bin/
}
case $buildmode in
"buildkit")
binaries
;;
"docker-buildkit")
binariesDocker
;;
*)
binariesLegacy
;;
esac