Dockerfile35 lines, 1.4 KB
| 1 | # syntax=docker/dockerfile:1 |
| 2 | # One Dockerfile for all five services: docker build --build-arg SERVICE=wallet . |
| 3 | |
| 4 | # Stage 1 builds, with the whole Go toolchain. None of it ships. |
| 5 | FROM golang:1.26.11-alpine AS build |
| 6 | WORKDIR /src |
| 7 | |
| 8 | # Modules first, in a step of their own: it runs again only when go.mod or |
| 9 | # go.sum change. The cache mount keeps modules between builds, so even then, |
| 10 | # only the new ones are downloaded. |
| 11 | COPY go.mod go.sum ./ |
| 12 | RUN --mount=type=cache,target=/go/pkg/mod go mod download |
| 13 | |
| 14 | # Then our code. The build cache mount means a rebuild compiles only the |
| 15 | # packages that changed. Static, with no paths from this machine, stripped of |
| 16 | # debug symbols, and stamped with its version. |
| 17 | COPY . . |
| 18 | ARG SERVICE |
| 19 | ARG VERSION=dev |
| 20 | RUN --mount=type=cache,target=/go/pkg/mod \ |
| 21 | --mount=type=cache,target=/root/.cache/go-build \ |
| 22 | CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" \ |
| 23 | -o /out/service ./cmd/${SERVICE} |
| 24 | |
| 25 | # Stage 2 is what ships: our binary, CA certificates, time zones, and a user |
| 26 | # who isn't root. No shell, no package manager. |
| 27 | FROM gcr.io/distroless/static-debian12:nonroot |
| 28 | COPY --from=build /out/service /service |
| 29 | USER nonroot:nonroot |
| 30 | ENTRYPOINT ["/service"] |
| 31 | |
| 32 | # Docker asks the binary itself: there's no curl in here. Every second while |
| 33 | # the service starts up, then every ten. |
| 34 | HEALTHCHECK --interval=10s --timeout=3s --start-period=30s --start-interval=1s \ |
| 35 | CMD ["/service", "-healthcheck"] |