From a57a99024ea8100b6b7f6e6901d93d3a0f051419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Anchieta=20Santiago?= Date: Mon, 6 Feb 2023 10:17:00 +0100 Subject: [PATCH] Enhance Dockerfile adding multistage build (#47) --- .goreleaser.yaml | 4 ++-- Dockerfile | 27 ++++++++++++++++++++++++--- Dockerfile.goreleaser | 7 +++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 Dockerfile.goreleaser diff --git a/.goreleaser.yaml b/.goreleaser.yaml index eb31d96..0284f0e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -26,7 +26,7 @@ release: dockers: - image_templates: - "ghcr.io/jetstack/dependency-track-exporter:{{.Version}}-amd64" - dockerfile: Dockerfile + dockerfile: Dockerfile.goreleaser use: buildx build_flag_templates: - "--pull" @@ -38,7 +38,7 @@ dockers: - "--platform=linux/amd64" - image_templates: - "ghcr.io/jetstack/dependency-track-exporter:{{.Version}}-arm64" - dockerfile: Dockerfile + dockerfile: Dockerfile.goreleaser use: buildx build_flag_templates: - "--pull" diff --git a/Dockerfile b/Dockerfile index 8cce9a4..9ed587b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,27 @@ +FROM golang:1.19-buster AS build + +WORKDIR /app + +COPY go.mod ./ + +COPY go.sum ./ + +RUN go mod download + +COPY *.go ./ + +COPY internal ./internal + +RUN go build -o /dependency-track-exporter + FROM gcr.io/distroless/static:nonroot -COPY dependency-track-exporter / +WORKDIR / + +COPY --from=build /dependency-track-exporter /dependency-track-exporter + +EXPOSE 9916 + +USER nonroot:nonroot -USER nonroot -ENTRYPOINT ["/dependency-track-exporter"] +ENTRYPOINT ["/dependency-track-exporter"] \ No newline at end of file diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000..64e3b52 --- /dev/null +++ b/Dockerfile.goreleaser @@ -0,0 +1,7 @@ +FROM gcr.io/distroless/static:nonroot + +COPY dependency-track-exporter / + +USER nonroot + +ENTRYPOINT ["/dependency-track-exporter"]