#@follow_tag(registry-proxy.engineering.redhat.com/rh-osbs/openshift-golang-builder:1.13)
FROM registry-proxy.engineering.redhat.com/rh-osbs/openshift-golang-builder:v1.13.0-202011132013.el7 AS builder
ENV GOPATH=/go

COPY ${CI_ARCHIVE_NODE_MAINTENANCE_OPERATOR} /
RUN mkdir -p /go/src/kubevirt.io/node-maintenance-operator && \
    tar -xzf ${CI_ARCHIVE_NODE_MAINTENANCE_OPERATOR} --strip-components 1 \
        -C /go/src/kubevirt.io/node-maintenance-operator && \
    rm ${CI_ARCHIVE_NODE_MAINTENANCE_OPERATOR}

WORKDIR /go/src/kubevirt.io/node-maintenance-operator/
RUN CI_UPSTREAM_VERSION=$CI_UPSTREAM_VERSION CI_UPSTREAM_COMMIT=$CI_UPSTREAM_COMMIT make build

#@follow_tag(registry.redhat.io/rhel8-2-els/rhel)
FROM registry.redhat.io/rhel8-2-els/rhel:8.2-4

ENV OPERATOR=/usr/local/bin/node-maintenance-operator \
    USER_UID=1001 \
    USER_NAME=node-maintenance-operator

# install operator binary
COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/_out/node-maintenance-operator ${OPERATOR}

# install scripts
COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/build/bin /usr/local/bin
RUN  /usr/local/bin/user_setup

# needed for HCO
LABEL org.kubevirt.hco.csv-generator.v1="/usr/local/bin/csv-generator"
COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/build/hco/csv-generator /usr/local/bin/
COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/manifests/node-maintenance-operator/v9.9.9/manifests /manifests

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

USER ${USER_UID}

LABEL com.redhat.component="node-maintenance-operator-container" \
      name="container-native-virtualization/node-maintenance-operator" \
      version="${CI_CONTAINER_VERSION}" \
      summary="Node Maintenance Operator" \
      io.openshift.expose-services="" \
      io.openshift.tags="cnv,operator,maintenance" \
      io.k8s.display-name="Node Maintenance Operator" \
      maintainer="The KubeVirt Project <kubevirt-dev@googlegroups.com>" \
      description="Node Maintenance Operator" \
      upstream-version="${CI_UPSTREAM_VERSION}" \
      upstream-vcs-ref="${CI_UPSTREAM_COMMIT}" \
      upstream-vcs-type="git"
