tiny-url-ex/Dockerfile

39 lines
832 B
Docker
Raw Normal View History

FROM golang:alpine as builder
2020-03-09 17:40:01 +00:00
RUN apk add --no-cache git
ADD . /app
WORKDIR /app
2020-03-09 17:40:01 +00:00
# create appuser
ENV USER=appuser
ENV UID=10001
# See https://stackoverflow.com/a/55757473/12429735RUN
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
2020-03-08 15:34:00 +00:00
RUN go mod download
2020-03-09 17:40:01 +00:00
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o binary
2020-03-09 17:40:01 +00:00
FROM scratch as production
# import the user and group files from the builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
# copy executable & config
COPY --from=builder /app/binary /app/
COPY --from=builder /app/api.json /app/
# Use an unprivileged user.
USER appuser:appuser
WORKDIR /app/
EXPOSE 4242/tcp
2020-03-09 17:40:01 +00:00
CMD ["/app/binary"]