Skip to content

Commit

Permalink
chore: run tests in the buildkit itself
Browse files Browse the repository at this point in the history
This relies on two PRs to the buildkit, which aren't merged yet, so I
had to do some overrides to apply them:

* moby/buildkit#1081
* moby/buildkit#1085

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira committed Jul 18, 2019
1 parent c9f0dbb commit 127f4c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
17 changes: 10 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax = docker/dockerfile:1.1-experimental
# syntax = smira/dockerfile:master-experimental

ARG TOOLS
FROM $TOOLS AS tools
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion hack/golang/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 127f4c9

Please sign in to comment.