#@follow_tag(registry.redhat.io/ubi8/ubi-minimal:8.2)
FROM registry.redhat.io/ubi8/ubi-minimal:8.2-349 AS builder

ARG version=${CI_UPSTREAM_VERSION}

ENV GOPATH=/go


RUN echo -e "[go-toolset]\nname=go-toolset\nprofiles=\nstate=enabled\nstream=rhel8" > /etc/dnf/modules.d/go-toolset.module \
    && microdnf install -y tar gzip go-compilers-golang-compiler
COPY ${CI_ARCHIVE_KUBEVIRT_VMWARE} /
RUN mkdir -p /operator ${GOPATH}/src/github.com/ManageIQ/manageiq-v2v-conversion_host/ && \
    tar -xvzf /${CI_ARCHIVE_KUBEVIRT_VMWARE} \
        --strip-components 1 \
        -C ${GOPATH}/src/github.com/ManageIQ/manageiq-v2v-conversion_host
WORKDIR ${GOPATH}/src/github.com/ManageIQ/manageiq-v2v-conversion_host/kubevirt-vmware
RUN GOFLAGS=-mod=vendor go build -o /operator/kubevirt-vmware cmd/manager/main.go && \
    cp -v build/bin/* /operator/ && \
    ls -lR /operator

# ======================

#@follow_tag(registry.redhat.io/ubi8/ubi-minimal:8.2)
FROM registry.redhat.io/ubi8/ubi-minimal:8.2-349

ENV OPERATOR=/usr/local/bin/kubevirt-vmware \
    USER_UID=1001 \
    USER_NAME=kubevirt-vmware

ADD manifests /manifests

COPY --from=builder /operator /usr/local/bin
RUN  /usr/local/bin/user_setup

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

USER ${USER_UID}

LABEL com.redhat.component="kubevirt-vmware-container" \
      license="ASL 2.0" \
      io.k8s.description="Operator providing information from VMware" \
      io.k8s.display-name="kubevirt-vmware" \
      io.openshift.tags="openshift,vmware,kubevirt,cnv,operator" \
      maintainer="Tomas Golembiovsky <tgolembi@redhat.com>" \
      name="container-native-virtualization/kubevirt-vmware" \
      summary="Operator providing information from VMware" \
      version="${CI_CONTAINER_VERSION}"
