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=}
|
2020-04-08 19:06:42 +00:00
|
|
|
: ${TEST_DOCKERD=}
|
|
|
|
: ${TEST_DOCKERD_BINARY=$(which dockerd)}
|
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
|
|
|
|
2020-04-16 22:26:53 +00:00
|
|
|
if [ "$TEST_DOCKERD" == "1" ] && ! file $TEST_DOCKERD_BINARY | grep "statically linked" >/dev/null; then
|
2020-04-08 19:06:42 +00:00
|
|
|
echo "dockerd binary needs to be statically linked"
|
2020-04-16 22:26:53 +00:00
|
|
|
exit 1
|
2020-04-08 19:06:42 +00:00
|
|
|
fi
|
|
|
|
|
2019-08-08 00:50:00 +00:00
|
|
|
importCacheFlags=""
|
|
|
|
if [ -n "$cacheref" ]; then
|
|
|
|
importCacheFlags="--import-cache=type=registry,ref=$cacheref:integration-tests"
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
|
2020-07-25 03:36:55 +00:00
|
|
|
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
|
2018-10-02 17:03:32 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
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
|
2020-07-25 03:36:55 +00:00
|
|
|
"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
|
|
|
|
;;
|
2018-10-02 17:03:32 +00:00
|
|
|
esac
|
|
|
|
|
2019-01-26 06:29:13 +00:00
|
|
|
cacheVolume=$(docker create -v /root/.cache -v /root/.cache/registry -v /go/pkg/mod alpine)
|
2018-10-15 22:34:28 +00:00
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
if [ "$TEST_INTEGRATION" == 1 ]; then
|
2020-04-08 19:06:42 +00:00
|
|
|
cid=$(docker create --rm -v /tmp --volumes-from=$cacheVolume -e TEST_DOCKERD -e SKIP_INTEGRATION_TESTS -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...})
|
|
|
|
if [ "$TEST_DOCKERD" = "1" ]; then
|
|
|
|
docker cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/
|
|
|
|
fi
|
|
|
|
docker start -a $cid
|
2018-10-02 17:03:32 +00:00
|
|
|
fi
|
2017-11-30 01:41:44 +00:00
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
if [ "$TEST_GATEWAY" == 1 ]; then
|
2020-07-30 13:06:31 +00:00
|
|
|
# Build-test "github.com/moby/buildkit/frontend/gateway/client", which isn't otherwise built by CI
|
|
|
|
# It really only needs buildkit-base. We have integration-tests in $iid, which is a direct child of buildkit-base.
|
|
|
|
cid=$(docker create --rm --volumes-from=$cacheVolume $iid go build -v ./frontend/gateway/client)
|
2020-04-08 19:06:42 +00:00
|
|
|
docker start -a $cid
|
2018-10-02 17:03:32 +00:00
|
|
|
fi
|
2017-12-20 07:22:19 +00:00
|
|
|
|
2019-08-08 00:50:00 +00:00
|
|
|
DOCKERFILE_RELEASES_CUSTOM=""
|
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"
|
2019-08-08 00:50:00 +00:00
|
|
|
else
|
|
|
|
DOCKERFILE_RELEASES_CUSTOM=1
|
2018-10-12 20:58:56 +00:00
|
|
|
fi
|
2019-03-14 14:33:02 +00:00
|
|
|
|
2018-10-12 20:58:56 +00:00
|
|
|
for release in $DOCKERFILE_RELEASES; do
|
|
|
|
buildtags=$(cat ./frontend/dockerfile/release/$release/tags)
|
|
|
|
tarout=$(mktemp -t dockerfile-frontend.XXXXXXXXXX)
|
|
|
|
case $buildmode in
|
2020-07-25 03:36:55 +00:00
|
|
|
"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
|
|
|
|
;;
|
2018-10-12 20:58:56 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -s $tarout ]; then
|
2019-08-08 00:50:00 +00:00
|
|
|
if [ "$release" = "mainline" ] || [ "$release" = "experimental" ] || [ -n "$DOCKERFILE_RELEASES_CUSTOM" ] || [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then
|
2020-04-08 19:06:42 +00:00
|
|
|
cid=$(docker create -v /tmp --rm --privileged --volumes-from=$cacheVolume -e TEST_DOCKERD -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)
|
2019-08-08 00:50:00 +00:00
|
|
|
docker cp $tarout $cid:/$release.tar
|
2020-04-08 19:06:42 +00:00
|
|
|
if [ "$TEST_DOCKERD" = "1" ]; then
|
|
|
|
docker cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/
|
|
|
|
fi
|
2019-08-08 00:50:00 +00:00
|
|
|
docker start -a $cid
|
|
|
|
fi
|
2018-10-12 20:58:56 +00:00
|
|
|
fi
|
|
|
|
rm $tarout
|
|
|
|
done
|
2018-10-02 17:03:32 +00:00
|
|
|
fi
|
2018-10-02 17:13:34 +00:00
|
|
|
|
2018-10-15 22:34:28 +00:00
|
|
|
docker rm -v $cacheVolume
|
|
|
|
|
2018-10-02 17:03:32 +00:00
|
|
|
case $buildmode in
|
2020-07-25 03:36:55 +00:00
|
|
|
"docker-buildkit")
|
|
|
|
rm "$iidfile"
|
|
|
|
docker rmi $iid
|
|
|
|
;;
|
2018-10-12 20:58:56 +00:00
|
|
|
esac
|