2018-10-02 17:03:32 +00:00
|
|
|
#!/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
|
2019-03-14 14:33:02 +00:00
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
|
|
|
copysrc="/usr/bin/."
|
2019-03-14 14:33:02 +00:00
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
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")
|
2019-04-16 11:41:06 +00:00
|
|
|
docker build --iidfile $iidfile --build-arg BUILDKITD_TAGS="${BUILDKITD_TAGS}" --target buildctl.exe -f ./hack/dockerfiles/test.Dockerfile --force-rm .
|
2018-10-02 17:03:32 +00:00
|
|
|
copysrc="/out/."
|
|
|
|
;;
|
|
|
|
*)
|
2019-04-16 11:41:06 +00:00
|
|
|
docker build --iidfile $iidfile --build-arg BUILDKITD_TAGS="${BUILDKITD_TAGS}" --target buildkit-binaries -f ./hack/dockerfiles/test.Dockerfile --force-rm .
|
2018-10-02 17:03:32 +00:00
|
|
|
;;
|
|
|
|
esac
|
2019-03-14 14:33:02 +00:00
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
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
|
|
|
|
|
2019-04-16 11:41:06 +00:00
|
|
|
docker build $platformFlag --build-arg BUILDKITD_TAGS="${BUILDKITD_TAGS}" --target binaries-$target --iidfile $iidfile -f ./hack/dockerfiles/test.buildkit.Dockerfile --force-rm .
|
2018-10-02 17:03:32 +00:00
|
|
|
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
|
2019-03-20 10:18:16 +00:00
|
|
|
platformFlag="--opt platform=$TARGETPLATFORM"
|
2018-10-02 17:03:32 +00:00
|
|
|
fi
|
|
|
|
buildctl build $progressFlag --frontend=dockerfile.v0 \
|
|
|
|
--local context=. --local dockerfile=. \
|
2019-03-20 10:18:16 +00:00
|
|
|
--opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
|
2019-04-16 11:41:06 +00:00
|
|
|
--opt build-arg:BUILDKITD_TAGS="$BUILDKITD_TAGS" \
|
2019-03-20 10:18:16 +00:00
|
|
|
--opt target=binaries $platformFlag \
|
2019-03-19 03:16:27 +00:00
|
|
|
--output type=local,dest=./bin/
|
2018-10-02 17:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case $buildmode in
|
|
|
|
"buildkit")
|
|
|
|
binaries
|
|
|
|
;;
|
|
|
|
"docker-buildkit")
|
|
|
|
binariesDocker
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
binariesLegacy
|
|
|
|
;;
|
|
|
|
esac
|