Files
prometheus-pg-adapter/Dockerfile

42 lines
1.1 KiB
Docker

# ───── Stage 1: Build the adapter binary ─────
FROM golang:1.22-alpine AS builder
RUN apk add --no-cache git make gcc musl-dev
WORKDIR /src
COPY . .
RUN go mod tidy
RUN make
# Verify binary
RUN ls -la postgresql-prometheus-adapter && \
./postgresql-prometheus-adapter --help > /dev/null
# ───── Stage 2: Runtime (Alpine for glibc/loader) ─────
FROM alpine:3.20
RUN apk add --no-cache libc6-compat bash # bash for start.sh, libc for binary
# Copy binary
COPY --from=builder /src/postgresql-prometheus-adapter /usr/local/bin/postgresql-prometheus-adapter
RUN chmod +x /usr/local/bin/postgresql-prometheus-adapter
# Copy and make start.sh executable
COPY start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh
# Non-root user
RUN addgroup -g 1001 -S appgroup && \
adduser -S -D -H -u 1001 -h /home/app -s /bin/bash -G appgroup -g appuser appuser
USER appuser
WORKDIR /home/app
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/start.sh"]