diff --git a/.drone.yml b/.drone.yml index fdc17f78e..b34b4d68d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -145,6 +145,20 @@ steps: depends_on: - build.Lint + - name: test.UnitTestRace + image: autonomy/build-container:latest + pull: always + environment: + BUILDKIT_HOST: tcp://buildkitd.ci.svc:1234 + BINDIR: /usr/local/bin + commands: + - make test-race + volumes: + - name: dockersock + path: /var/run/ + depends_on: + - build.Lint + # Phase 3 - name: build.Rootfs image: autonomy/build-container:latest diff --git a/Dockerfile b/Dockerfile index cc31b1d0e..f4e72656a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,12 @@ # syntax = docker/dockerfile-upstream:1.1.2-experimental +# Meta args applied to stage base names. + ARG TOOLS +ARG GO_VERSION + +# The tools target provides base toolchain for the build. + FROM $TOOLS AS tools ENV PATH /toolchain/bin RUN ["/toolchain/bin/mkdir", "/bin", "/tmp"] @@ -267,6 +273,16 @@ RUN --security=insecure --mount=type=cache,id=testspace,target=/tmp --mount=type FROM scratch AS test COPY --from=test-runner /src/coverage.txt /coverage.txt +# The test-race target performs tests with race detector. + +FROM golang:${GO_VERSION} AS test-race +COPY --from=base /src /src +COPY --from=base /go/pkg/mod /go/pkg/mod +WORKDIR /src +ENV GO111MODULE on +ARG TESTPKGS +RUN --mount=type=cache,target=/root/.cache/go-build go test -v -race ${TESTPKGS} + # The lint target performs linting on the source code. FROM base AS lint diff --git a/Makefile b/Makefile index 07f039ee1..67828c538 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ TOOLS ?= autonomy/tools:b473afb # TODO(andrewrynhard): Move this logic to a shell script. BUILDKIT_VERSION ?= v0.6.0 KUBECTL_VERSION ?= v1.14.1 +GO_VERSION ?= 1.12 BUILDKIT_IMAGE ?= moby/buildkit:$(BUILDKIT_VERSION) BUILDKIT_HOST ?= tcp://0.0.0.0:1234 BUILDKIT_CONTAINER_NAME ?= talos-buildkit @@ -47,6 +48,7 @@ COMMON_ARGS += --local dockerfile=. COMMON_ARGS += --opt build-arg:TOOLS=$(TOOLS) COMMON_ARGS += --opt build-arg:SHA=$(SHA) COMMON_ARGS += --opt build-arg:TAG=$(TAG) +COMMON_ARGS += --opt build-arg:GO_VERSION=$(GO_VERSION) DOCKER_ARGS ?= # to allow tests to run containerd @@ -229,7 +231,6 @@ e2e-integration: .PHONY: test test: buildkitd - @mkdir -p build @$(BINDIR)/buildctl --addr $(BUILDKIT_HOST) \ build \ --opt target=$@ \ @@ -237,6 +238,14 @@ test: buildkitd --opt build-arg:TESTPKGS=$(TESTPKGS) \ $(COMMON_ARGS) +.PHONY: test-race +test-race: buildkitd + @$(BINDIR)/buildctl --addr $(BUILDKIT_HOST) \ + build \ + --opt target=$@ \ + --opt build-arg:TESTPKGS=$(TESTPKGS) \ + $(COMMON_ARGS) + .PHONY: lint lint: buildkitd @$(BINDIR)/buildctl --addr $(BUILDKIT_HOST) \