Update vendor and binaries script

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-12-07 17:14:35 +01:00
parent 35a60b8e04
commit 48f15dcf3d
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 19 additions and 88 deletions

View File

@ -1,56 +1,16 @@
#!/usr/bin/env bash
. $(dirname $0)/util
set -eu
: ${TARGETPLATFORM=$CLI_PLATFORM}
: ${CONTINUOUS_INTEGRATION=}
set -ex
platformFlag=""
if [ -n "$TARGETPLATFORM" ]; then
platformFlag="--platform $TARGETPLATFORM"
fi
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
binariesDocker() {
mkdir -p bin/tmp
export DOCKER_BUILDKIT=1
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
platformFlag=""
if [ -n "$TARGETPLATFORM" ]; then
platformFlag="--build-arg=TARGETPLATFORM=$TARGETPLATFORM"
fi
docker build $platformFlag --target=binaries --iidfile $iidfile --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 target=binaries $platformFlag \
--output type=local,dest=./bin/
}
case $buildmode in
"buildkit")
binaries
;;
"docker-buildkit")
binariesDocker
;;
*)
echo "buildctl or docker with buildkit support is required"
exit 1
;;
esac
buildxCmd build $platformFlag \
--target "binaries" \
--output "type=local,dest=./bin/" \
.

View File

@ -1,45 +1,16 @@
#!/usr/bin/env bash
. $(dirname $0)/util
set -eu -o pipefail -x
set -eu
: ${CONTINUOUS_INTEGRATION=}
output=$(mktemp -d -t buildx-output.XXXXXXXXXX)
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
buildxCmd build \
--target "update" \
--output "type=local,dest=$output" \
--file "./hack/dockerfiles/vendor.Dockerfile" \
.
case $buildmode in
"buildkit")
output=$(mktemp -d -t buildctl-output.XXXXXXXXXX)
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. \
--frontend-opt target=update \
--frontend-opt filename=./hack/dockerfiles/vendor.Dockerfile \
--output type=local,dest=$output
rm -rf ./vendor
cp -R "$output/out/" .
rm -rf $output
;;
*)
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
case $buildmode in
"docker-buildkit")
export DOCKER_BUILDKIT=1
docker build --iidfile $iidfile -f ./hack/dockerfiles/vendor.Dockerfile --target update --force-rm .
;;
*)
echo "buildctl or docker with buildkit support is required"
exit 1
;;
esac
iid=$(cat $iidfile)
cid=$(docker create $iid noop)
rm -rf ./vendor
docker cp $cid:/out/go.mod .
docker cp $cid:/out/go.sum .
docker cp $cid:/out/vendor .
docker rm $cid
rm -f $iidfile
;;
esac
rm -rf ./vendor
cp -R "$output"/out/* .
rm -rf $output