Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockerfile: Do a clean build in the dockerfile #54

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*
!pg_exporter
!pg_exporter.yml
!go.mod
!go.sum
!main.go
!exporter
!pg_exporter.yml
39 changes: 35 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
# syntax=docker/dockerfile:1
FROM golang:1.22-alpine AS builder-env

# Build a self-contained pg_exporter container with a clean environment and no
# dependencies.
#
# build with
#
# docker buildx build -f Dockerfile --tag pg_exporter .
#

WORKDIR /build

COPY go.mod go.sum ./
RUN \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux go mod download

COPY . /build
RUN \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux go build -a -o /pg_exporter .

FROM scratch
LABEL maintainer="Vonng <[email protected]>"
LABEL org.opencontainers.image.authors="Vonng <[email protected]>, Craig Ringer <[email protected]>" \
org.opencontainers.image.url="https://github.com/Vonng/pg_exporter" \
org.opencontainers.image.source="https://github.com/Vonng/pg_exporter" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.title="pg_exporter" \
org.opencontainers.image.description="PostgreSQL metrics exporter for Prometheus"

COPY pg_exporter /bin/pg_exporter
WORKDIR /bin
COPY --from=builder-env /pg_exporter /bin/pg_exporter
COPY pg_exporter.yml /etc/pg_exporter.yml

ENTRYPOINT ["/bin/pg_exporter"]
EXPOSE 9630/tcp
ENTRYPOINT ["/bin/pg_exporter"]