diff options
| author | kd <kdam0@localhost.localdomain> | 2020-07-16 15:45:55 +0000 |
|---|---|---|
| committer | kd <kdam0@localhost.localdomain> | 2020-07-16 15:45:55 +0000 |
| commit | 8d262109f418fbfce2bc25c68b6731567ae2f015 (patch) | |
| tree | 2216a700e065c5127eae8dea350906564f34aa9d /Dockerfile | |
Initial commit
Diffstat (limited to 'Dockerfile')
| -rw-r--r-- | Dockerfile | 48 |
1 files changed, 48 insertions, 0 deletions
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"] |
