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

ARG operator_tar=vm-import-operator-51c3f04e3acd5cccb047c8e396589f5a2de0b56c.tar.gz
ARG operator_commit=51c3f04e3acd5cccb047c8e396589f5a2de0b56c

ENV GOPATH=/go

RUN echo -e "[go-toolset]\nname=go-toolset\nprofiles=\nstate=enabled\nstream=rhel8" > /etc/dnf/modules.d/go-toolset.module \
    && dnf install -y tar gzip go-compilers-golang-compiler

COPY ${operator_tar} /
RUN tar -xvzf ${operator_tar} && \
    mkdir -p ${GOPATH}/src/github.com/kubevirt/vm-import-operator/ && \
    mv vm-import-operator-${operator_commit}/* ${GOPATH}/src/github.com/kubevirt/vm-import-operator

WORKDIR ${GOPATH}/src/github.com/kubevirt/vm-import-operator
RUN \
    GOFLAGS=-mod=vendor \
    go build -o build/_output/bin/vm-import-operator cmd/operator/operator.go
RUN \
    GOFLAGS=-mod=vendor \
    go build -o build/_output/bin/csv-generator tools/csv-generator/csv-generator.go

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

ENV OPERATOR=/usr/bin/vm-import-operator \
    USER_UID=1001 \
    USER_NAME=vm-import-operator \
    CSV_GENERATOR=/usr/bin/csv-generator

COPY --from=builder build/_output/bin/vm-import-operator ${OPERATOR}
COPY --from=builder build/_output/bin/csv-generator ${CSV_GENERATOR}
COPY --from=builder build/bin /usr/bin
RUN  /usr/bin/user_setup

USER ${USER_UID}

ENTRYPOINT [ "/usr/bin/entrypoint" ]

LABEL com.redhat.component="vm-import-operator-container" \
      name="container-native-virtualization/vm-import-operator-rhel8" \
      version="v2.5.8" \
      release="2" \
      upstream-version="0.3.0-29-g51c3f04e" \
      upstream-vcs-ref="51c3f04e3acd5cccb047c8e396589f5a2de0b56c" \
      upstream-vcs-type="git" \
      summary="VM Import Operator" \
      io.openshift.expose-services="" \
      io.openshift.tags="cnv,kubevirt,operator,rhv,import" \
      io.k8s.display-name="vm-import-operator" \
      maintainer="jdzon@redhat.com,masayag@redhat.com,omachace@redhat.com,pkliczew@redhat.com" \
      description="CNV VM Import Operator"
