127 lines
3.7 KiB
Bash
Executable File
127 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
. $(dirname $0)/util
|
|
set -eu -o pipefail
|
|
|
|
: ${TEST_INTEGRATION=}
|
|
: ${TEST_GATEWAY=}
|
|
: ${TEST_DOCKERFILE=}
|
|
: ${DOCKERFILE_RELEASES=}
|
|
: ${CONTINUOUS_INTEGRATION=}
|
|
: ${BUILDKIT_REGISTRY_MIRROR_DIR=}
|
|
|
|
importCacheFlags=""
|
|
if [ -n "$cacheref" ]; then
|
|
importCacheFlags="--import-cache=type=registry,ref=$cacheref:integration-tests"
|
|
fi
|
|
|
|
progressFlag=""
|
|
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
|
|
|
|
if [ "$#" == 0 ]; then TEST_INTEGRATION=1; fi
|
|
|
|
while test $# -gt 0
|
|
do
|
|
case "$1" in
|
|
gateway)
|
|
TEST_GATEWAY=1
|
|
;;
|
|
dockerfile)
|
|
TEST_DOCKERFILE=1
|
|
;;
|
|
integration)
|
|
TEST_INTEGRATION=1
|
|
;;
|
|
*)
|
|
echo "unknown arg $1"
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
iid="buildkit-tests"
|
|
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
|
set -x
|
|
|
|
case $buildmode in
|
|
"buildkit")
|
|
tmpfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
|
buildctl build $progressFlag --frontend=dockerfile.v0 $currentcontextBuildctl \
|
|
--opt target=integration-tests \
|
|
--output type=docker,name=$iid,dest=$tmpfile \
|
|
--import-cache type=registry,ref=cicache.buildk.it/moby/buildkit/master:integration-tests $importCacheFlags
|
|
docker load -i $tmpfile
|
|
rm $tmpfile
|
|
;;
|
|
"docker-buildkit")
|
|
export DOCKER_BUILDKIT=1
|
|
docker build --iidfile $iidfile --target integration-tests --force-rm .
|
|
iid=$(cat $iidfile)
|
|
;;
|
|
*)
|
|
echo "Unsupported build mode: $buildmode" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
cacheVolume=$(docker create -v /root/.cache -v /root/.cache/registry -v /go/pkg/mod alpine)
|
|
|
|
if [ "$TEST_INTEGRATION" == 1 ]; then
|
|
docker run --rm -v /tmp --volumes-from=$cacheVolume -e SKIP_INTEGRATION_TESTS -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}
|
|
fi
|
|
|
|
|
|
if [ "$TEST_GATEWAY" == 1 ]; then
|
|
docker run --rm --volumes-from=$cacheVolume $iid go build -v ./frontend/gateway/client
|
|
fi
|
|
|
|
|
|
DOCKERFILE_RELEASES_CUSTOM=""
|
|
if [ "$TEST_DOCKERFILE" == 1 ]; then
|
|
if [ -z $DOCKERFILE_RELEASES ]; then
|
|
DOCKERFILE_RELEASES="mainline experimental mounts secrets ssh"
|
|
else
|
|
DOCKERFILE_RELEASES_CUSTOM=1
|
|
fi
|
|
|
|
|
|
for release in $DOCKERFILE_RELEASES; do
|
|
buildtags=$(cat ./frontend/dockerfile/release/$release/tags)
|
|
tarout=$(mktemp -t dockerfile-frontend.XXXXXXXXXX)
|
|
case $buildmode in
|
|
"buildkit")
|
|
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. \
|
|
--opt filename=./frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile \
|
|
--opt build-arg:BUILDTAGS="$buildtags" \
|
|
--output type=oci,dest=$tarout
|
|
;;
|
|
"docker-buildkit")
|
|
dfiidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
|
docker build --iidfile=$dfiidfile -f ./frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile --build-arg BUILDTAGS="$buildtags" .
|
|
dfiid=$(cat $dfiidfile)
|
|
docker save -o $tarout $dfiid
|
|
docker rmi $dfiid
|
|
rm $dfiidfile
|
|
;;
|
|
esac
|
|
|
|
if [ -s $tarout ]; then
|
|
if [ "$release" = "mainline" ] || [ "$release" = "experimental" ] || [ -n "$DOCKERFILE_RELEASES_CUSTOM" ] || [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then
|
|
cid=$(docker create -v /tmp --rm --privileged --volumes-from=$cacheVolume -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_WORKER_RANDOM=1 -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test --count=1 -tags "$buildtags" ${TESTFLAGS:--v} ./frontend/dockerfile)
|
|
docker cp $tarout $cid:/$release.tar
|
|
docker start -a $cid
|
|
fi
|
|
fi
|
|
rm $tarout
|
|
done
|
|
fi
|
|
|
|
docker rm -v $cacheVolume
|
|
|
|
case $buildmode in
|
|
"docker-buildkit")
|
|
rm "$iidfile"
|
|
docker rmi $iid
|
|
;;
|
|
esac
|