FROM ubi8-minimal:8.2-339 AS builder

ARG kubevirt_version=0.30.5
ARG kubevirt_commit=53b764825eb80321b18eb39a5767c25a77ea470b
ARG kubevirt_tar=kubevirt-53b764825eb80321b18eb39a5767c25a77ea470b.tar.gz

ENV GOPATH=/go

RUN 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 \
    GO111MODULE=off \
    bash -x ./hack/build-go.sh install cmd/virt-handler cmd/chroot


FROM ubi8-minimal:8.2-339

ARG project_dir=/go/src/kubevirt.io/kubevirt/cmd/virt-handler
ARG kubevirt_version=0.30.5

RUN microdnf -y install iproute iptables procps-ng && microdnf clean all

COPY --from=builder /go/src/kubevirt.io/kubevirt/_out/cmd/virt-handler/virt-handler-${kubevirt_version}-linux-amd64 /usr/bin/virt-handler
COPY --from=builder /go/src/kubevirt.io/kubevirt/_out/cmd/chroot/chroot-${kubevirt_version}-linux-amd64 /usr/bin/chroot
COPY --from=builder /go/src/kubevirt.io/kubevirt/_out/cmd/container-disk-v2alpha/container-disk /usr/bin/container-disk
COPY --from=builder ${project_dir}/base_container.cil /base_container.cil
COPY --from=builder ${project_dir}/virt_launcher.cil /virt_launcher.cil

ENTRYPOINT [ "/usr/bin/virt-handler" ]

LABEL com.redhat.component="virt-handler-container" \
    name="container-native-virtualization/virt-handler" \
    version="v2.4.0" \
    release="58" \
    upstream-version="0.30.5" \
    upstream-vcs-ref="53b764825eb80321b18eb39a5767c25a77ea470b" \
    upstream-vcs-type="git" \
    summary="Virtualization handler" \
    io.openshift.expose-services="" \
    io.openshift.tags="cnv,kubevirt" \
    io.k8s.display-name="virt-handler" \
    maintainer="sgott@redhat.com,ibezukh@redhat.com,dhiller@redhat.com,jlejosne@redhat.com" \
    description="Virtualization handler for CNV"
