##################################################
#
# go backend build
FROM openshift/golang-builder:1.12 AS gobuilder
ENV SOURCE_GIT_COMMIT=473c47a33e2eda6b9f3df59210e85ccfe4e8b4d6 SOURCE_GIT_TAG=473c47a3 SOURCE_GIT_URL=https://github.com/openshift/console SOURCE_DATE_EPOCH=1581674844 BUILD_VERSION=v4.3.3 BUILD_RELEASE=202002171705
RUN mkdir -p /go/src/github.com/openshift/console/
ADD . /go/src/github.com/openshift/console/
WORKDIR /go/src/github.com/openshift/console/
RUN ./build-backend.sh


##################################################
#
# nodejs frontend build
FROM rhscl/nodejs-8-rhel7:1 AS nodebuilder
ENV SOURCE_GIT_COMMIT=473c47a33e2eda6b9f3df59210e85ccfe4e8b4d6 SOURCE_GIT_TAG=473c47a3 SOURCE_GIT_URL=https://github.com/openshift/console SOURCE_DATE_EPOCH=1581674844 BUILD_VERSION=v4.3.3 BUILD_RELEASE=202002171705

ADD . .

USER 0
# extract the yarn dependencies that must be provided in the dist-git lookaside cache
RUN tar fx yarn-offline.tar

# bootstrap yarn so we can install and run the other tools.
RUN container-entrypoint npm install ./yarn-1.9.4.tgz

# prevent download of chromedriver, sass binary, and node headers as part of module installs
ENV CHROMEDRIVER_SKIP_DOWNLOAD=true \
    SKIP_SASS_BINARY_DOWNLOAD_FOR_CI=true \
    NPM_CONFIG_TARBALL=$HOME/node-v8.9.4-headers.tar.gz

# run the build
RUN container-entrypoint ./build-frontend.sh


##################################################
#
# actual base image for final product
FROM openshift/ose-base:v4.3.3.20200217.170535
ENV SOURCE_GIT_COMMIT=473c47a33e2eda6b9f3df59210e85ccfe4e8b4d6 SOURCE_GIT_TAG=473c47a3 SOURCE_GIT_URL=https://github.com/openshift/console SOURCE_DATE_EPOCH=1581674844 BUILD_VERSION=v4.3.3 BUILD_RELEASE=202002171705
RUN mkdir -p /opt/bridge/bin
COPY --from=gobuilder /go/src/github.com/openshift/console/bin/bridge /opt/bridge/bin
COPY --from=nodebuilder /opt/app-root/src/frontend/public/dist /opt/bridge/static

WORKDIR /
# doesn't require a root user.
USER 1001

CMD [ "/opt/bridge/bin/bridge", "--public-dir=/opt/bridge/static" ]

LABEL \
        io.k8s.description="This is a component of OpenShift Container Platform and provides a web console." \
        com.redhat.component="openshift-enterprise-console-container" \
        maintainer="Samuel Padgett <spadgett@redhat.com>" \
        name="openshift/ose-console" \
        License="GPLv2+" \
        io.k8s.display-name="OpenShift Console" \
        vendor="Red Hat" \
        io.openshift.tags="openshift,console" \
        version="v4.3.3" \
        release="202002171705" \
        io.openshift.build.commit.id="473c47a33e2eda6b9f3df59210e85ccfe4e8b4d6" \
        io.openshift.build.source-location="https://github.com/openshift/console" \
        io.openshift.build.commit.url="https://github.com/openshift/console/commit/473c47a33e2eda6b9f3df59210e85ccfe4e8b4d6"

