#!/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 --target buildctl.exe -f ./hack/dockerfiles/test.Dockerfile --force-rm . copysrc="/out/." ;; *) docker build --iidfile $iidfile --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 --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="--frontend-opt=platform=$TARGETPLATFORM" fi buildctl build $progressFlag --frontend=dockerfile.v0 \ --local context=. --local dockerfile=. \ --frontend-opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \ --frontend-opt target=binaries $platformFlag \ --exporter=local --exporter-opt output=./bin/ } case $buildmode in "buildkit") binaries ;; "docker-buildkit") binariesDocker ;; *) binariesLegacy ;; esac