2017-05-27 05:10:26 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
. $(dirname $0)/util
|
|
|
|
set -eu -o pipefail
|
2017-05-27 05:10:26 +00:00
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
: ${TEST_INTEGRATION=}
|
|
|
|
: ${TEST_GATEWAY=}
|
|
|
|
: ${TEST_DOCKERFILE=}
|
2018-10-12 20:58:56 +00:00
|
|
|
: ${DOCKERFILE_RELEASES=}
|
2018-10-02 17:03:32 +00:00
|
|
|
: ${CONTINUOUS_INTEGRATION=}
|
2018-10-12 20:58:56 +00:00
|
|
|
: ${BUILDKIT_REGISTRY_MIRROR_DIR=}
|
2018-10-02 17:03:32 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-10-12 20:58:56 +00:00
|
|
|
mirrorCreated=""
|
|
|
|
if [ -z $BUILDKIT_REGISTRY_MIRROR_DIR ]; then
|
|
|
|
BUILDKIT_REGISTRY_MIRROR_DIR=$(mktemp -t buildkit.mirror.XXXXXXXXXX)
|
|
|
|
mirrorCreated="1"
|
|
|
|
fi
|
2018-10-02 17:03:32 +00:00
|
|
|
|
|
|
|
iid="buildkit-tests"
|
2017-12-28 08:17:42 +00:00
|
|
|
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
2018-10-02 17:03:32 +00:00
|
|
|
set -x
|
|
|
|
|
|
|
|
case $buildmode in
|
|
|
|
"buildkit")
|
|
|
|
tmpfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
|
|
|
|
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. \
|
|
|
|
--frontend-opt target=integration-tests \
|
|
|
|
--frontend-opt filename=./hack/dockerfiles/test.buildkit.Dockerfile \
|
|
|
|
--exporter=docker --exporter-opt name=$iid --exporter-opt output=$tmpfile
|
|
|
|
docker load -i $tmpfile
|
|
|
|
rm $tmpfile
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
case $buildmode in
|
|
|
|
"docker-buildkit")
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
docker build --iidfile $iidfile -f ./hack/dockerfiles/test.buildkit.Dockerfile --target integration-tests --force-rm .
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
docker build --iidfile $iidfile -f ./hack/dockerfiles/test.Dockerfile --target integration-tests --force-rm .
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
iid=$(cat $iidfile)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$TEST_INTEGRATION" == 1 ]; then
|
|
|
|
docker run --rm -v /tmp --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}
|
|
|
|
fi
|
2017-11-30 01:41:44 +00:00
|
|
|
|
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
if [ "$TEST_GATEWAY" == 1 ]; then
|
|
|
|
docker run --rm $iid go build ./frontend/gateway/client
|
|
|
|
fi
|
2017-12-20 07:22:19 +00:00
|
|
|
|
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
if [ "$TEST_DOCKERFILE" == 1 ]; then
|
2018-10-12 20:58:56 +00:00
|
|
|
if [ -z $DOCKERFILE_RELEASES ]; then
|
|
|
|
DOCKERFILE_RELEASES="mainline experimental mounts secrets ssh"
|
|
|
|
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=. \
|
|
|
|
--frontend-opt filename=./frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile \
|
|
|
|
--frontend-opt build-arg:BUILDTAGS="$buildtags" \
|
|
|
|
--exporter=oci --exporter-opt output=$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
|
2018-10-15 21:50:15 +00:00
|
|
|
cid=$(docker create -v /tmp --rm --privileged -e BUILDKIT_WORKER_RANDOM=1 -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test -tags "$buildtags" ${TESTFLAGS:--v} ./frontend/dockerfile)
|
|
|
|
docker cp $tarout $cid:/$release.tar
|
2018-10-12 20:58:56 +00:00
|
|
|
docker start -a $cid
|
|
|
|
fi
|
|
|
|
rm $tarout
|
|
|
|
done
|
2018-10-02 17:03:32 +00:00
|
|
|
fi
|
2018-10-02 17:13:34 +00:00
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
case $buildmode in
|
|
|
|
"docker-buildkit")
|
|
|
|
rm "$iidfile"
|
|
|
|
docker rmi $iid
|
|
|
|
;;
|
|
|
|
"legacy")
|
|
|
|
rm "$iidfile"
|
|
|
|
;;
|
2018-10-12 20:58:56 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
if [ ! -z $mirrorCreated ] && [ ! -z $BUILDKIT_REGISTRY_MIRROR_DIR ]; then
|
|
|
|
rm -rf $BUILDKIT_REGISTRY_MIRROR_DIR
|
|
|
|
fi
|