Skip to content

Instantly share code, notes, and snippets.

@ferdinandosimonetti
Created April 28, 2020 18:44
Show Gist options
  • Save ferdinandosimonetti/fd924f0bde974a25a489931ae69a5e85 to your computer and use it in GitHub Desktop.
Save ferdinandosimonetti/fd924f0bde974a25a489931ae69a5e85 to your computer and use it in GitHub Desktop.
FROM golang:alpine3.11 AS builder
RUN apk update && apk add --no-cache git
ENV USER=appuser
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
RUN mkdir /static
COPY main.go /
WORKDIR /
RUN go get -d -v
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -a -o /main .
RUN chmod +x /main
###########
FROM scratch
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /static /static
COPY --from=builder /main /
USER appuser:appuser
ENTRYPOINT ["/main"]
EXPOSE 8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment