FROM ubi8-minimal:8-released AS builder

ENV OPERATOR=/usr/local/bin/hyperconverged-cluster-operator \
    USER_UID=1001 \
    USER_NAME=hyperconverged-cluster-operator
ARG hco_shortcommit=a9b6802
ARG hco_targz=hyperconverged-cluster-operator-${hco_shortcommit}.tar.gz
ENV GOPATH=/go
ENV SRC_DIR=${GOPATH}/src/github.com/kubevirt/hyperconverged-cluster-operator

RUN microdnf install -y tar gzip rsync sed go-compilers-golang-compiler make
COPY ${hco_targz} /
RUN tar xzf ${hco_targz} && \
    mkdir -p ${SRC_DIR} && \
    cp -r kubevirt-hyperconverged-cluster-operator-${hco_shortcommit}/* ${SRC_DIR}
WORKDIR ${SRC_DIR}

RUN make build

FROM ubi8-minimal:8-released

ENV OPERATOR=/usr/local/bin/hyperconverged-cluster-operator \
    USER_UID=1001 \
    USER_NAME=hyperconverged-cluster-operator

RUN microdnf install -y shadow-utils

COPY --from=builder /go/src/github.com/kubevirt/hyperconverged-cluster-operator/_out/hyperconverged-cluster-operator ${OPERATOR}
COPY --from=builder /go/src/github.com/kubevirt/hyperconverged-cluster-operator/build/bin /usr/local/bin
RUN  /usr/local/bin/user_setup

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

USER ${USER_UID}

LABEL com.redhat.component="hyperconverged-cluster-operator-container" \
      name="container-native-virtualization/hyperconverged-cluster-operator" \
      version="v2.0.0" \
      release="32" \
      upstream-version="v0.2.5" \
      upstream-vcs-ref="a9b6802e2954e354093921210f36b1a482be2782" \
      upstream-vcs-type="git" \
      summary="CNV HyperConverged Cluster Operator" \
      io.openshift.expose-services="" \
      io.openshift.tags="cnv,kubevirt,operator" \
      io.k8s.display-name="hyperconverged-cluster-operator" \
      maintainer="Ryan Hallisey <rhallise@redhat.com>" \
      description="CNV HyperConverged Cluster Operator"
