35 lines
1.2 KiB
Docker
35 lines
1.2 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# --- 1. Frontend : React + Vite -> /src/web/dist
|
|
FROM node:22-alpine AS frontend
|
|
WORKDIR /src/frontend
|
|
COPY frontend/package.json frontend/package-lock.json ./
|
|
RUN --mount=type=cache,target=/root/.npm npm ci --no-audit --no-fund
|
|
COPY frontend/ ./
|
|
RUN npm run build
|
|
|
|
# --- 2. Backend : binaire Go statique embarquant le frontend
|
|
FROM golang:1.24-alpine AS backend
|
|
ARG VERSION=dev
|
|
WORKDIR /src
|
|
COPY go.mod ./
|
|
COPY cmd ./cmd
|
|
COPY web/embed.go ./web/
|
|
COPY --from=frontend /src/web/dist ./web/dist
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
CGO_ENABLED=0 go test ./... && \
|
|
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/server ./cmd/server
|
|
|
|
# --- 3. Binaire garage (CLI) : image officielle, même version que le serveur à piloter
|
|
FROM dxflrs/garage:v2.3.0 AS garage
|
|
|
|
# --- 4. Image finale : distroless, non-root
|
|
FROM gcr.io/distroless/static-debian12:nonroot
|
|
COPY --from=backend /out/server /server
|
|
COPY --from=garage /garage /garage
|
|
ENV LISTEN_ADDR=:8080 GARAGE_BIN=/garage
|
|
EXPOSE 8080
|
|
USER nonroot:nonroot
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD ["/server", "healthcheck"]
|
|
ENTRYPOINT ["/server"]
|