From 127f4c98deea2816052004e471ea91b04bd5ddcd Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 18 Jul 2019 23:05:26 +0300 Subject: [PATCH] chore: run tests in the buildkit itself This relies on two PRs to the buildkit, which aren't merged yet, so I had to do some overrides to apply them: * https://github.com/moby/buildkit/pull/1081 * https://github.com/moby/buildkit/pull/1085 Signed-off-by: Andrey Smirnov --- Dockerfile | 17 ++++++++++------- Makefile | 14 ++++++-------- hack/golang/test.sh | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 70250e25144..bb12c77e4f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# syntax = docker/dockerfile:1.1-experimental +# syntax = smira/dockerfile:master-experimental ARG TOOLS FROM $TOOLS AS tools @@ -71,7 +71,7 @@ ARG SHA ARG TAG ARG VERSION_PKG="github.com/talos-systems/talos/internal/pkg/version" WORKDIR /src/internal/app/machined -RUN --mount=type=cache,target=/root/.cache go build -a -ldflags "-s -w -X ${VERSION_PKG}.Name=Server -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /machined +RUN --mount=type=cache,target=/root/.cache go build -a -ldflags "-s -w -X ${VERSION_PKG}.Name=Server -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /machined RUN chmod +x /machined FROM scratch AS machined COPY --from=machined-build /machined /machined @@ -109,7 +109,7 @@ ARG SHA ARG TAG ARG VERSION_PKG="github.com/talos-systems/talos/internal/pkg/version" WORKDIR /src/internal/app/proxyd -RUN go build -a -ldflags "-s -w -X ${VERSION_PKG}.Name=Server -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /proxyd +RUN --mount=type=cache,target=/root/.cache go build -a -ldflags "-s -w -X ${VERSION_PKG}.Name=Server -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /proxyd RUN chmod +x /proxyd FROM scratch AS proxyd COPY --from=proxyd-build /proxyd /proxyd @@ -135,7 +135,7 @@ ARG SHA ARG TAG ARG VERSION_PKG="github.com/talos-systems/talos/internal/pkg/version" WORKDIR /src/cmd/osctl -RUN GOOS=linux GOARCH=amd64 go build -a -ldflags "-s -w -X ${VERSION_PKG}.Name=Client -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /osctl-linux-amd64 +RUN --mount=type=cache,target=/root/.cache GOOS=linux GOARCH=amd64 go build -a -ldflags "-s -w -X ${VERSION_PKG}.Name=Client -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /osctl-linux-amd64 RUN chmod +x /osctl-linux-amd64 FROM scratch AS osctl-linux COPY --from=osctl-linux-build /osctl-linux-amd64 /osctl-linux-amd64 @@ -145,7 +145,7 @@ ARG SHA ARG TAG ARG VERSION_PKG="github.com/talos-systems/talos/internal/pkg/version" WORKDIR /src/cmd/osctl -RUN GOOS=darwin GOARCH=amd64 go build -a -ldflags "-s -w -X ${VERSION_PKG}.Name=Client -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /osctl-darwin-amd64 +RUN --mount=type=cache,target=/root/.cache GOOS=darwin GOARCH=amd64 go build -a -ldflags "-s -w -X ${VERSION_PKG}.Name=Client -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /osctl-darwin-amd64 RUN chmod +x /osctl-darwin-amd64 FROM scratch AS osctl-darwin COPY --from=osctl-darwin-build /osctl-darwin-amd64 /osctl-darwin-amd64 @@ -254,13 +254,16 @@ ENTRYPOINT ["entrypoint.sh"] # The test target performs tests on the source code. -FROM base AS test +FROM base AS test-runner RUN unlink /etc/ssl COPY --from=rootfs-base / / COPY hack/golang/test.sh /bin +RUN --security=insecure --mount=type=cache,target=/tmp --mount=type=cache,target=/root/.cache /bin/test.sh +FROM scratch AS test +COPY --from=test-runner /src/coverage.txt /coverage.txt # The lint target performs linting on the source code. FROM base AS lint COPY hack/golang/golangci-lint.yaml . -RUN golangci-lint run --config golangci-lint.yaml +RUN --mount=type=cache,target=/root/.cache golangci-lint run --config golangci-lint.yaml diff --git a/Makefile b/Makefile index ca234a24666..e8862a8a168 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ TOOLS ?= autonomy/tools:b4e3778 # TODO(andrewrynhard): Move this logic to a shell script. -BUILDKIT_VERSION ?= v0.5.0 +BUILDKIT_VERSION ?= sysfs KUBECTL_VERSION ?= v1.14.1 -BUILDKIT_IMAGE ?= moby/buildkit:$(BUILDKIT_VERSION) +BUILDKIT_IMAGE ?= smira/buildkit:$(BUILDKIT_VERSION) BUILDKIT_HOST ?= tcp://0.0.0.0:1234 BUILDKIT_CONTAINER_NAME ?= talos-buildkit BUILDKIT_CONTAINER_STOPPED := $(shell docker ps --filter name=$(BUILDKIT_CONTAINER_NAME) --filter status=exited --format='{{.Names}}' 2>/dev/null) @@ -41,6 +41,7 @@ TAG := $(shell $(BINDIR)/gitmeta image tag) COMMON_ARGS = --progress=plain COMMON_ARGS += --frontend=dockerfile.v0 +COMMON_ARGS += --allow security.insecure COMMON_ARGS += --local context=. COMMON_ARGS += --local dockerfile=. COMMON_ARGS += --opt build-arg:TOOLS=$(TOOLS) @@ -99,7 +100,8 @@ ifneq ($(BUILDKIT_CONTAINER_RUNNING),$(BUILDKIT_CONTAINER_NAME)) -p 1234:1234 \ $(BUILDKIT_CACHE) \ $(BUILDKIT_IMAGE) \ - --addr $(BUILDKIT_HOST) + --addr $(BUILDKIT_HOST) \ + --allow-insecure-entitlement security.insecure @echo "Wait for buildkitd to become available" @sleep 5 endif @@ -209,13 +211,9 @@ test: buildkitd @mkdir -p build @$(BINDIR)/buildctl --addr $(BUILDKIT_HOST) \ build \ - --output type=docker,dest=/tmp/$@.tar,name=docker.io/autonomy/$@:$(TAG) \ --opt target=$@ \ + --output type=local,dest=./ \ $(COMMON_ARGS) - @docker load < /tmp/$@.tar - @trap "rm -rf ./.artifacts" EXIT; mkdir -p ./.artifacts && \ - docker run -i --rm $(DOCKER_TEST_ARGS) -v $(PWD)/.artifacts:/src/artifacts autonomy/$@:$(TAG) /bin/$@.sh && \ - cp ./.artifacts/coverage.txt coverage.txt .PHONY: dev-test dev-test: diff --git a/hack/golang/test.sh b/hack/golang/test.sh index e9b58908258..096b736e769 100755 --- a/hack/golang/test.sh +++ b/hack/golang/test.sh @@ -6,7 +6,7 @@ CGO_ENABLED=1 perform_tests() { echo "Performing tests" - go test -v -covermode=atomic -coverprofile=artifacts/coverage.txt ./... + go test -v -covermode=atomic -coverprofile=coverage.txt ./... } perform_short_tests() {