#@follow_tag(ubi8-minimal:8-released)
FROM ubi8-minimal:8.1-279 AS builder
ENV GOPATH=/go
RUN microdnf install -y tar sed gzip go-compilers-golang-compiler

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 GOOS=linux GOARCH=amd64 go build -i -o /node-maintenance-operator ./cmd/manager

#@follow_tag(ubi8-minimal:8-released)
FROM ubi8-minimal:8.1-279
ENV ENTRYPOINT=/entrypoint \
    OPERATOR=/node-maintenance-operator \
    USER_UID=1001 \
    USER_NAME=node-maintenance-operator

LABEL org.kubevirt.hco.csv-generator.v1="/usr/bin/csv-generator"

COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/build/bin/user_setup /user_setup
RUN /user_setup

COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/deploy/crds /deploy/crds
COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/manifests/generated /manifests/generated
COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/build/csv-generator.sh /usr/bin/csv-generator

COPY --from=builder /node-maintenance-operator ${OPERATOR}
COPY --from=builder /go/src/kubevirt.io/node-maintenance-operator/build/bin/entrypoint ${ENTRYPOINT}
ENTRYPOINT ${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"
