From 9414e01f7400a20e99be39bd1d40fbb72aa32dff Mon Sep 17 00:00:00 2001 From: Sebastian Gumprich Date: Thu, 27 Jul 2023 19:52:01 +0200 Subject: [PATCH] use separate dockerfile for building and running --- Dockerfile | 27 +++++++++++++++++++-------- goreleaser.dockerfile | 11 +++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 goreleaser.dockerfile diff --git a/Dockerfile b/Dockerfile index 712c279..671ed19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,22 @@ -ARG DISTROLESS_IMAGE=gcr.io/distroless/base +# syntax=docker/dockerfile:1 +FROM golang:1.19-alpine AS build-env +RUN mkdir -p /go/src/confluence-gardner -# using base nonroot image -# user:group is nobody:nobody, uid:gid = 65534:65534 -FROM ${DISTROLESS_IMAGE} +# Copy the module files first and then download the dependencies. If this +# doesn't change, we won't need to do this again in future builds. +WORKDIR /go/src/confluence-gardner -# Copy our static executable -COPY confluence-gardner /confluence-gardner +COPY go.* ./ +RUN go mod download -# Run the hello binary. -ENTRYPOINT ["/confluence-gardner"] +WORKDIR /go/src/confluence-gardner +ADD conf conf +COPY *.go ./ +RUN go build -o confluence-gardner + +# final stage +FROM alpine:latest +COPY --from=build-env /go/src/confluence-gardner/confluence-gardner /usr/local/bin/confluence-gardner +RUN mkdir -p /output +ENV DIRECTORY /output +ENTRYPOINT ["confluence-gardner"] diff --git a/goreleaser.dockerfile b/goreleaser.dockerfile new file mode 100644 index 0000000..712c279 --- /dev/null +++ b/goreleaser.dockerfile @@ -0,0 +1,11 @@ +ARG DISTROLESS_IMAGE=gcr.io/distroless/base + +# using base nonroot image +# user:group is nobody:nobody, uid:gid = 65534:65534 +FROM ${DISTROLESS_IMAGE} + +# Copy our static executable +COPY confluence-gardner /confluence-gardner + +# Run the hello binary. +ENTRYPOINT ["/confluence-gardner"]