-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dockerfile: Do a clean build in the dockerfile
When building a docker container, perform a clean build of the component within the container instead of relying on the go toolchain on the invoking machine and whatever the latest (possibly stale) binary in the directory tree is. Build dependency caching is enabled to reduce download times. OCI container labels are added to provide standard container metadata. File locations, default invocation etc is the same as the original Dockerfile.
- Loading branch information
Showing
2 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |