FROM registry.redhat.io/rhel8/go-toolset:latest AS builder
ENV SOURCE_GIT_COMMIT=${CI_SOURCE_TO_IMAGE_UPSTREAM_COMMIT} \
    SOURCE_DATE_EPOCH=1581603464 \
    BUILD_VERSION=${CI_CONTAINER_VERSION} \
    SOURCE_GIT_URL=${CI_SOURCE_TO_IMAGE_UPSTREAM_URL} \
    SOURCE_GIT_TAG=v1.3.1-11-geed2850f 

ENV S2I_GIT_VERSION=${CI_CONTAINER_VERSION} \
    S2I_GIT_MAJOR=${CI_X_VERSION} \
    S2I_GIT_MINOR=${CI_Y_VERSION}

USER root

WORKDIR /tmp/source-to-image
COPY ${CI_ARCHIVE_SOURCE_TO_IMAGE} .

RUN tar -xvzf ${CI_ARCHIVE_SOURCE_TO_IMAGE} --strip-components=1 && rm ${CI_ARCHIVE_SOURCE_TO_IMAGE}

ENV GOARCH="amd64"

RUN make

RUN cp _output/local/bin/$(go env GOHOSTOS)/$(go env GOHOSTARCH)/s2i _output/s2i
#
# Runner Image
#

FROM registry.redhat.io/ubi8/ubi-minimal:latest
ENV SOURCE_GIT_COMMIT=${CI_SOURCE_TO_IMAGE_UPSTREAM_COMMIT} \
    SOURCE_DATE_EPOCH=1581603464 \
    BUILD_VERSION=${CI_CONTAINER_VERSION} \
    SOURCE_GIT_URL=${CI_SOURCE_TO_IMAGE_UPSTREAM_URL} \
    SOURCE_GIT_TAG=v1.3.1-11-geed2850f 

COPY --from=builder /tmp/source-to-image/_output/s2i  /usr/local/bin/s2i

USER 1001

ENTRYPOINT [ "/usr/local/bin/s2i" ]

LABEL \
        io.k8s.description="source to image" \
        com.redhat.component="source-to-image-container" \
        name="ocp-tools-43-tech-preview/source-to-image-rhel8" \
        io.k8s.display-name="source to image" \
        io.openshift.build.source-location=${CI_SOURCE_TO_IMAGE_UPSTREAM_URL} \
        io.openshift.build.commit.url=${CI_SOURCE_TO_IMAGE_UPSTREAM_URL}/commit/${CI_SOURCE_TO_IMAGE_UPSTREAM_COMMIT} \
        version=${CI_CONTAINER_VERSION} \
        io.openshift.build.commit.id=${CI_SOURCE_TO_IMAGE_UPSTREAM_COMMIT} 
