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

ARG kubevirt_version=0.34.1-4-g48956f6
ARG kubevirt_commit=48956f60864ece98118d7894327caf7513c5b942
ARG kubevirt_tar=kubevirt-48956f60864ece98118d7894327caf7513c5b942.tar.gz

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 \
        rsync \
        sed \
        go-compilers-golang-compiler \
        glibc-static
COPY ${kubevirt_tar} /
RUN tar xf ${kubevirt_tar} && \
    mkdir -p /go/src/kubevirt.io/ && \
    mv kubevirt-${kubevirt_commit} /go/src/kubevirt.io/kubevirt
WORKDIR ${GOPATH}/src/kubevirt.io/kubevirt

RUN KUBEVIRT_VERSION=${kubevirt_version} \
    KUBEVIRT_SOURCE_DATE_EPOCH="$(date +%s)" \
    KUBEVIRT_GIT_COMMIT=${kubevirt_commit} \
    KUBEVIRT_GIT_VERSION=v${kubevirt_version} \
    KUBEVIRT_GIT_TREE_STATE=clean \
    GOFLAGS=-mod=vendor \
    bash -x ./hack/build-go.sh install cmd/virt-controller


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

ARG kubevirt_version=0.34.1-4-g48956f6

RUN microdnf install -y shadow-utils
# Create non-root user
RUN useradd -u 1001 --create-home -s /bin/bash virt-controller
COPY --from=builder /go/src/kubevirt.io/kubevirt/_out/cmd/virt-controller/virt-controller-${kubevirt_version}-linux-amd64 /usr/bin/virt-controller
WORKDIR /home/virt-controller
USER 1001
ENTRYPOINT [ "/usr/bin/virt-controller" ]

LABEL com.redhat.component="virt-controller-container" \
    name="container-native-virtualization/virt-controller" \
    version="v2.5.1" \
    release="1" \
    upstream-version="0.34.1-4-g48956f6" \
    upstream-vcs-ref="48956f60864ece98118d7894327caf7513c5b942" \
    upstream-vcs-type="git" \
    summary="Virtualization controller" \
    io.openshift.expose-services="" \
    io.openshift.tags="cnv,kubevirt" \
    io.k8s.display-name="virt-controller" \
    maintainer="sgott@redhat.com,ibezukh@redhat.com,dhiller@redhat.com,jlejosne@redhat.com" \
    description="Virtualization controller for CNV"
