Files
prometheus-pg-adapter/Dockerfile
2025-12-02 15:00:57 +01:00

41 lines
1.1 KiB
Docker

# ───── Stage 1: Build the Go binary ─────
FROM golang:1.22-alpine AS builder
LABEL 12ww1160 <12ww1160@confdroid.com>
# Install build tools
RUN apk add --no-cache git make gcc musl-dev
# Workdir = your local source
WORKDIR /src
COPY . .
# Build exactly like the original Makefile does
RUN make binary
# Verify it works
RUN /src/postgresql-prometheus-adapter --help
# ───── Stage 2: Tiny runtime image ─────
# Option A: Alpine (has glibc, easy debugging)
# FROM alpine:3.20
# Option B: Distroless (smallest & most secure) ← recommended
FROM gcr.io/distroless/static-debian12
# Copy only the binary
COPY --from=builder /src/postgresql-prometheus-adapter /usr/local/bin/postgresql-prometheus-adapter
# Optional: copy CA certificates if you use HTTPS to reach the adapter
# (distroless already includes them)
# Non-root user (same UID/GID as original Crunchy image)
USER 1001
EXPOSE 9201
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9201/health"] || exit 1
ENTRYPOINT ["/usr/local/bin/postgresql-prometheus-adapter"]