@@ -11,6 +11,39 @@ RUN make -C /src install PREFIX=/pkg GOTOOLCHAIN=local GO_BUILDFLAGS='-mod vendo
1111
1212# ###############################################################################
1313
14+ # To only build the tests run: docker build . --target test
15+ # We can't do `FROM builder AS test` here, as then make prepare-static-check would not be cached during interactive use when developing
16+ # and caching all the tools, especially golangci-lint, takes a few minutes.
17+ FROM golang:1.25.4-alpine3.22 AS test
18+
19+ COPY Makefile /src/Makefile
20+
21+ # used below by USER
22+ RUN addgroup -g 4200 appgroup \
23+ && adduser -h /home/appuser -s /sbin/nologin -G appgroup -D -u 4200 appuser
24+
25+ RUN apk add --no-cache --no-progress git make py3-pip \
26+ && pip3 install --break-system-packages reuse \
27+ && make -C /src prepare-static-check
28+
29+
30+ # We only copy here because we want the "prepare-static-check" to be cacheable.
31+ # It is not a problem that we are overwriting the go cache from the earlier steps because we do not need to rebuild those tools.
32+ COPY --from=builder /go /go
33+ COPY --from=builder /src /src
34+
35+ RUN CHECK_SKIPS_FUNCTIONAL_TEST=true make -C /src static-check
36+
37+ # Some things like postgres do not like to run as root. For simplicity, just always run as an unprivileged user,
38+ # but for it to be able to read the go cache, we need to allow it.
39+ RUN chmod 777 -R /src/
40+ USER 4200:4200
41+ RUN cd /src \
42+ && git config --global --add safe.directory /src \
43+ && CHECK_SKIPS_FUNCTIONAL_TEST=true make build/cover.out
44+
45+ # ###############################################################################
46+
1447FROM alpine:3.22
1548
1649RUN addgroup -g 4200 appgroup \
0 commit comments