From 94e9047dcb265ba0746bb2e2a4d5a2dc71abb22a Mon Sep 17 00:00:00 2001 From: Allan Lewis Date: Mon, 11 Apr 2022 15:36:24 +0100 Subject: [PATCH] Improve the Dockerfile (#26) * Dockerfile: Inline `APP_NAME` Since `merge-gatekeeper` is necessarily hard-coded in the entrypoint, there's little value in extracting it to an environment variable; if we changed it, the entrypoint wouldn't exist. This commit therefore inlines it. * Dockerfile: Declare env vars as args where possible We don't need `ORG` and `REPO` in the container environment. This commit therefore redefines them as build arguments. This has the side benefit of being able to change them at build time, which could be useful for people using forks of this repo. * Dockerfile: Combine env var definitions In order to reduce the number of image layers, this commit combines some environment variable definitions into a single step. --- Dockerfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 564c5a4..bb140c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,10 @@ ARG GO_VERSION=1.16.7 FROM golang:${GO_VERSION}-alpine -ENV GO111MODULE on -ENV LANG en_US.UTF-8 -ENV ORG upsidr -ENV REPO merge-gatekeeper -ENV APP_NAME merge-gatekeeper +ARG ORG=upsidr +ARG REPO=merge-gatekeeper + +ENV GO111MODULE=on LANG=en_US.UTF-8 RUN mkdir -p $GOPATH/src @@ -14,7 +13,7 @@ WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} COPY . . -RUN CGO_ENABLED=0 go build ./cmd/${APP_NAME} \ - && mv ${APP_NAME} /go/bin/ +RUN CGO_ENABLED=0 go build ./cmd/merge-gatekeeper \ + && mv merge-gatekeeper /go/bin/ ENTRYPOINT ["/go/bin/merge-gatekeeper"]