##################################################
#
# go backend build
FROM openshift/golang-builder:rhel_8_golang_1.15 AS gobuilder
ENV __doozer=update BUILD_RELEASE=202110051546.p0.git.f60d27f.assembly.stream BUILD_VERSION=v4.7.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=7 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.7.0-202110051546.p0.git.f60d27f.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=f60d27fcc6bcd03c782aa67c910374ebbdef3c65 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=13+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.13.0+f60d27f OS_GIT_COMMIT=f60d27f OS_GIT_VERSION=4.7.0-202110051546.p0.git.f60d27f.assembly.stream-f60d27f SOURCE_DATE_EPOCH=1632335196 SOURCE_GIT_COMMIT=f60d27fcc6bcd03c782aa67c910374ebbdef3c65 SOURCE_GIT_TAG=v6.0.6-14528-gf60d27fcc6 SOURCE_GIT_URL=https://github.com/openshift/console 
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 openshift/base-nodejs:v4.7.0-202109210902.p0.git.0fb79a4.assembly.stream AS nodebuilder
ENV __doozer=update BUILD_RELEASE=202110051546.p0.git.f60d27f.assembly.stream BUILD_VERSION=v4.7.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=7 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.7.0-202110051546.p0.git.f60d27f.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=f60d27fcc6bcd03c782aa67c910374ebbdef3c65 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=13+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.13.0+f60d27f OS_GIT_COMMIT=f60d27f OS_GIT_VERSION=4.7.0-202110051546.p0.git.f60d27f.assembly.stream-f60d27f SOURCE_DATE_EPOCH=1632335196 SOURCE_GIT_COMMIT=f60d27fcc6bcd03c782aa67c910374ebbdef3c65 SOURCE_GIT_TAG=v6.0.6-14528-gf60d27fcc6 SOURCE_GIT_URL=https://github.com/openshift/console 

ADD . .

USER 0
# required for node-gyp
RUN yum install -y python3
# 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, geckodriver, sass, cypress binary, and node headers as part of module installs
ENV CHROMEDRIVER_SKIP_DOWNLOAD=true \
    GECKODRIVER_SKIP_DOWNLOAD=true \
    SKIP_SASS_BINARY_DOWNLOAD_FOR_CI=true \
    CYPRESS_INSTALL_BINARY=0 \
    NPM_CONFIG_TARBALL=$HOME/node-v14.16.0-headers.tar.gz

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


##################################################
#
# actual base image for final product
FROM openshift/ose-base:v4.7.0.20211005.155606
ENV __doozer=update BUILD_RELEASE=202110051546.p0.git.f60d27f.assembly.stream BUILD_VERSION=v4.7.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=7 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.7.0-202110051546.p0.git.f60d27f.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=f60d27fcc6bcd03c782aa67c910374ebbdef3c65 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=13+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.13.0+f60d27f OS_GIT_COMMIT=f60d27f OS_GIT_VERSION=4.7.0-202110051546.p0.git.f60d27f.assembly.stream-f60d27f SOURCE_DATE_EPOCH=1632335196 SOURCE_GIT_COMMIT=f60d27fcc6bcd03c782aa67c910374ebbdef3c65 SOURCE_GIT_TAG=v6.0.6-14528-gf60d27fcc6 SOURCE_GIT_URL=https://github.com/openshift/console 
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
COPY --from=gobuilder /go/src/github.com/openshift/console/pkg/graphql/schema.graphql /pkg/graphql/schema.graphql

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" \
        io.openshift.maintainer.product="OpenShift Container Platform" \
        io.openshift.maintainer.component="Management Console" \
        release="202110051546.p0.git.f60d27f.assembly.stream" \
        io.openshift.build.commit.id="f60d27fcc6bcd03c782aa67c910374ebbdef3c65" \
        io.openshift.build.source-location="https://github.com/openshift/console" \
        io.openshift.build.commit.url="https://github.com/openshift/console/commit/f60d27fcc6bcd03c782aa67c910374ebbdef3c65" \
        version="v4.7.0"

