39 lines
1.7 KiB
Docker
39 lines
1.7 KiB
Docker
# Modules in their own layer and a persistent build cache keep the rebuild of
|
|
# a rolling update short.
|
|
FROM golang:1.27.1-alpine3.23@sha256:d9e2f2f07b10cc922da3e80e035c3058810b328d5aef82d2c63680967c5e2ec9 AS build
|
|
WORKDIR /src
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download && go mod verify
|
|
COPY cmd ./cmd
|
|
COPY internal ./internal
|
|
COPY migrations ./migrations
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
CGO_ENABLED=0 GOFLAGS=-mod=readonly go build -trimpath -ldflags="-s -w" -o /out/ ./cmd/server ./cmd/migrate ./cmd/reconcile ./cmd/s3init
|
|
|
|
# The load generator gets an image of its own; the API image does not carry it.
|
|
FROM build AS loadgen-build
|
|
COPY tools ./tools
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
CGO_ENABLED=0 GOFLAGS=-mod=readonly go build -trimpath -ldflags="-s -w" -o /out/loadgen ./tools/loadgen
|
|
|
|
FROM alpine:3.23@sha256:fd791d74b68913cbb027c6546007b3f0d3bc45125f797758156952bc2d6daf40 AS loadgen
|
|
RUN adduser -D -H -u 10001 app
|
|
COPY --from=loadgen-build /out/loadgen /usr/local/bin/loadgen
|
|
USER app
|
|
ENTRYPOINT ["/usr/local/bin/loadgen"]
|
|
|
|
# Last, so that `build: .` builds it; it also runs the migrate service.
|
|
FROM alpine:3.23@sha256:fd791d74b68913cbb027c6546007b3f0d3bc45125f797758156952bc2d6daf40
|
|
RUN adduser -D -H -u 10001 app
|
|
COPY --from=build /out/server /out/migrate /out/reconcile /out/s3init /usr/local/bin/
|
|
USER app
|
|
ENV APP_HOST=0.0.0.0 \
|
|
APP_PORT=8080 \
|
|
APP_ENV=lab
|
|
EXPOSE 8080
|
|
# The start interval lets a rolling update see a new replica healthy within
|
|
# about a second.
|
|
HEALTHCHECK --interval=5s --timeout=2s --start-period=15s --start-interval=1s --retries=3 \
|
|
CMD wget -qO- "http://127.0.0.1:${APP_PORT:-8080}/health/ready" >/dev/null || exit 1
|
|
ENTRYPOINT ["/usr/local/bin/server"]
|