Skip to content

Instantly share code, notes, and snippets.

@jrevillas
Created November 29, 2019 07:35
Show Gist options
  • Save jrevillas/bf642637f14d36ce5741dee721ce2ce4 to your computer and use it in GitHub Desktop.
Save jrevillas/bf642637f14d36ce5741dee721ce2ce4 to your computer and use it in GitHub Desktop.
ARG ALPINE_VERSION=3.10
ARG GOLANG_VERSION=1.13.4
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS builder
RUN mkdir /tmp/unprivileged && \
echo 'service:x:101:101:service:/:' > /tmp/unprivileged/passwd && \
echo 'service:x:101:' > /tmp/unprivileged/group
RUN apk update && \
apk add --no-cache ca-certificates git tzdata && \
update-ca-certificates
WORKDIR /go/src/app
COPY ./go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -installsuffix 'static' -o /app
FROM scratch
COPY --from=builder /tmp/unprivileged/group /tmp/unprivileged/passwd /etc/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /app /app
USER 101:101
ENTRYPOINT ["/app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment