This commit is contained in:
34
Dockerfile
Normal file
34
Dockerfile
Normal file
@@ -0,0 +1,34 @@
|
||||
# ---------- Build Stage ----------
|
||||
FROM golang:1.22-alpine AS build
|
||||
WORKDIR /src
|
||||
# System‑Deps nur für Build
|
||||
RUN apk add --no-cache git ca-certificates tzdata && update-ca-certificates
|
||||
|
||||
# Module separat cachen
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Quellcode
|
||||
COPY . .
|
||||
|
||||
# statisch bauen (kein CGO), mit kleinen Binaries
|
||||
ENV CGO_ENABLED=0
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
go build -trimpath -ldflags="-s -w" -o /out/dashboard ./cmd/dashboard
|
||||
|
||||
# ---------- Runtime Stage ----------
|
||||
# Distroless ist sehr klein/sicher; enthält CA‑Zertifikate für HTTPS‑Calls
|
||||
FROM gcr.io/distroless/base-debian12:nonroot
|
||||
WORKDIR /app
|
||||
|
||||
# Expose Port
|
||||
EXPOSE 8080
|
||||
|
||||
# Copy Binary + benötigte Zeitzonen/Certs sind in Distroless bereits enthalten
|
||||
COPY --from=build /out/dashboard /app/dashboard
|
||||
|
||||
# Security: läuft als nonroot User (Distroless nonroot UID 65532)
|
||||
USER nonroot:nonroot
|
||||
|
||||
# Healthcheck via Startkommando ist nicht möglich in Distroless – per Compose lösen
|
||||
ENTRYPOINT ["/app/dashboard"]
|
||||
Reference in New Issue
Block a user