#@follow_tag(ubi8-minimal:8-released)
FROM ubi8-minimal:8.1-279 AS builder

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

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 hyperconverged-cluster-operator-1d355c3bffff7c049580a3a8717e2a056678a5a7.tar.gz /
RUN mkdir -p "$SRC_DIR" \
    && tar -xzf "hyperconverged-cluster-operator-1d355c3bffff7c049580a3a8717e2a056678a5a7.tar.gz" \
        --strip-components 1 \
        -C "$SRC_DIR" \
    && cd "$SRC_DIR" \
    && make build

#@follow_tag(ubi8-minimal:8-released)
FROM ubi8-minimal:8.1-279

ENV OPERATOR=/usr/local/bin/hyperconverged-cluster-operator \
    USER_UID=1001 \
    USER_NAME=hyperconverged-cluster-operator \
    CSV_MERGER=/usr/local/bin/csv-merger \
    CSV_TEMPLATE=/var/hco-csv-template.yaml.in

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
COPY --from=builder /go/src/github.com/kubevirt/hyperconverged-cluster-operator/_out/csv-merger $CSV_MERGER
COPY --from=builder /go/src/github.com/kubevirt/hyperconverged-cluster-operator/templates/olm-catalog/kubevirt-hyperconverged/VERSION/kubevirt-hyperconverged-operator.VERSION.clusterserviceversion_merger.yaml.in $CSV_TEMPLATE
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.2.0" \
      release="12" \
      upstream-version="v0.4.0-45-g1d355c3" \
      upstream-vcs-ref="1d355c3bffff7c049580a3a8717e2a056678a5a7" \
      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"
