From 8d262109f418fbfce2bc25c68b6731567ae2f015 Mon Sep 17 00:00:00 2001 From: kd Date: Thu, 16 Jul 2020 11:45:55 -0400 Subject: Initial commit --- Dockerfile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Dockerfile (limited to 'Dockerfile') diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4adbe71 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +# STEP 1 build executable binary +FROM golang:1.14-alpine AS build-env + +# Create new user devops +ENV USER=devops +ENV UID=10001 + +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + "${USER}" + +# Get git. +RUN apk update && apk add --no-cache git + +WORKDIR /go/src/app + +# Add source code. +COPY src/ ./ + +# Get the dependencies. +RUN go get -d -v + +# Build the binary. +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ + -ldflags='-w -s -extldflags "-static"' -a \ + -o /go/bin/app . + + +# STEP 2 build a small image +#FROM scratch +FROM gcr.io/distroless/static + +ENV TZ=America/Toronto + +COPY --from=build-env /etc/passwd /etc/passwd +COPY --from=build-env /etc/group /etc/group +COPY --from=build-env /go/bin/app /go/bin/app + +# Use an unprivileged user. +USER devops:devops + +#CMD ["/go/bin/app"] +ENTRYPOINT ["/go/bin/app"] -- cgit v1.2.3