hack: add test target

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2019-03-22 18:52:36 -07:00
parent 252ab3e103
commit 5593257c38
4 changed files with 62 additions and 2 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
bin
cross-out

View File

@ -29,6 +29,9 @@ RUN --mount=target=. --mount=target=/root/.cache,type=cache \
set -x; go build -ldflags "$(cat /tmp/.ldflags)" -o /usr/bin/buildx ./cmd/buildx && \
file /usr/bin/buildx && file /usr/bin/buildx | egrep "statically linked|Mach-O|Windows"
FROM buildx-build AS integration-tests
COPY . .
FROM golang:1.12-alpine AS docker-cli-build
RUN apk add -U git bash coreutils gcc musl-dev
ENV CGO_ENABLED=0

View File

@ -14,10 +14,13 @@ install: binaries
lint:
./hack/lint
test:
./hack/test
validate-vendor:
./hack/validate-vendor
validate-all: lint validate-vendor
validate-all: lint test validate-vendor
vendor:
./hack/update-vendor

53
hack/test Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env bash
. $(dirname $0)/util
set -eu -o pipefail
: ${CONTINUOUS_INTEGRATION=}
: ${BUILDX_NOCACHE=}
progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
iid="buildx-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 \
--local context=. --local dockerfile=. \
--frontend-opt target=integration-tests \
--output type=docker,name=$iid,dest=$tmpfile
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 "docker with buildkit support is required"
exit 1
;;
esac
cacheVolume="buildx-cache"
if ! docker inspect "$cacheVolume" 2>&1 >/dev/null ; then
cacheVolume=$(docker create --name=buildx-cache -v /root/.cache -v /go/pkg/mod alpine)
fi
docker run --rm -v /tmp --volumes-from=$cacheVolume --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}
if [ -n "$BUILDX_NOCACHE" ]; then
docker rm -v $cacheVolume
fi
case $buildmode in
"docker-buildkit")
rm "$iidfile"
docker rmi $iid
;;
esac