Skip to content

Commit

Permalink
Merge pull request #54 from ringerc/pr-clean-build-dockerfile
Browse files Browse the repository at this point in the history
dockerfile: Do a clean build in the dockerfile
  • Loading branch information
Vonng committed Jun 19, 2024
2 parents aa21bc1 + a77234c commit cc79005
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
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"]

0 comments on commit cc79005

Please sign in to comment.