| 1 |
|
| 2 |
# syntax=docker/dockerfile:1 |
| 3 |
|
| 4 |
ARG GO_VERSION=1.23 |
| 5 |
ARG XX_VERSION=1.5.0 |
| 6 |
|
| 7 |
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx |
| 8 |
|
| 9 |
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base |
| 10 |
RUN apk add --no-cache git |
| 11 |
COPY --from=xx / / |
| 12 |
WORKDIR /src |
| 13 |
|
| 14 |
FROM base AS build |
| 15 |
ARG TARGETPLATFORM |
| 16 |
RUN --mount=target=. --mount=target=/go/pkg/mod,type=cache \ |
| 17 |
--mount=target=/root/.cache,type=cache \ |
| 18 |
xx-go build ./... |
| 19 |
|
| 20 |
FROM base AS test |
| 21 |
ARG TESTFLAGS |
| 22 |
RUN --mount=target=. --mount=target=/go/pkg/mod,type=cache \ |
| 23 |
--mount=target=/root/.cache,type=cache \ |
| 24 |
xx-go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic ${TESTFLAGS} ./... |
| 25 |
|
| 26 |
FROM scratch AS test-coverage |
| 27 |
COPY --from=test /tmp/coverage.txt /coverage-root.txt |
| 28 |
|
| 29 |
FROM build |