ARG BUILDER
FROM ${BUILDER} as base
ARG REPO
COPY . "/root/app"
# Static build the binary so that we can add it to a scratch image
RUN cd "/root/app" && CGO_ENABLED=0 go test -mod vendor -ldflags '-extldflags "-static"' -c -o ./cmd/timotyenapp/timotyenapp_integration_test -tags=integration ./cmd/timotyenapp
RUN mkdir /user && \
    echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
    echo 'nobody:x:65534:' > /user/group

FROM scratch
ARG REPO

# Required for timezones
COPY --from=base /usr/local/go/lib/time/zoneinfo.zip /zoneinfo.zip
ENV ZONEINFO /zoneinfo.zip

# 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 /root/app/cmd/timotyenapp/timotyenapp_integration_test /timotyenapp_integration_test

USER nobody:nobody

ENTRYPOINT ["/timotyenapp_integration_test", "-test.v"]
