chore: run tests in the buildkit itself

This relies on two PRs to the buildkit:

* https://github.com/moby/buildkit/pull/1081
* https://github.com/moby/buildkit/pull/1085

Sysfs fix was merged to upstream, so updated tag, while using
`Dockerfile` slug I can switch to dockerfile2llb with support for
`--security=insecure`.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
This commit is contained in:
Andrey Smirnov 2019-07-18 23:05:26 +03:00 committed by Andrew Rynhard
parent a15499d25a
commit 9f9acf1f05
3 changed files with 16 additions and 24 deletions

View File

@ -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

View File

@ -1,7 +1,7 @@
TOOLS ?= autonomy/tools:b4e3778
# TODO(andrewrynhard): Move this logic to a shell script.
BUILDKIT_VERSION ?= v0.5.0
BUILDKIT_VERSION ?= master@sha256:455f06ede03149051ce2734d9639c28aed1b6e8b8a0c607cb813e29b469a07d6
KUBECTL_VERSION ?= v1.14.1
BUILDKIT_IMAGE ?= moby/buildkit:$(BUILDKIT_VERSION)
BUILDKIT_HOST ?= tcp://0.0.0.0:1234
@ -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,22 +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:
@docker run -i --rm $(DOCKER_TEST_ARGS) \
-v $(PWD)/internal:/src/internal:ro \
-v $(PWD)/pkg:/src/pkg:ro \
-v $(PWD)/cmd:/src/cmd:ro \
autonomy/test:$(TAG) \
go test -v ./...
.PHONY: lint
lint: buildkitd

View File

@ -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() {