ARG BUILDER
FROM ${BUILDER} as base
ARG REPO
COPY . "$GOPATH/src/$REPO"
# Static build the binary so that we can add it to a scratch image
RUN cd "$GOPATH/src/$REPO" && CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -o ./cmd/anotherone/anotherone ./cmd/anotherone
# Lots of good advice on https://medium.com/@pierreprinetti/the-go-1-11-dockerfile-a3218319d191
# Let's try to make this docker not run as root
RUN mkdir /user && \
    echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
    echo 'nobody:x:65534:' > /user/group


FROM scratch
ARG REPO

# Required for SSL
COPY --from=base /user/group /user/passwd /etc/
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=base /go/src/$REPO/cmd/anotherone/anotherone /anotherone

USER nobody:nobody

ENTRYPOINT ["/anotherone"]
