From 5593257c38019fd07e01faa802b28c8f294ea3d7 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Fri, 22 Mar 2019 18:52:36 -0700 Subject: [PATCH] hack: add test target Signed-off-by: Tonis Tiigi --- .gitignore | 3 ++- Dockerfile | 3 +++ Makefile | 5 ++++- hack/test | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100755 hack/test diff --git a/.gitignore b/.gitignore index c5e82d74..87ecb1e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -bin \ No newline at end of file +bin +cross-out \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e7e339a5..e59518b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile index 0992683e..464ba82a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/hack/test b/hack/test new file mode 100755 index 00000000..447acd05 --- /dev/null +++ b/hack/test @@ -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