FROM openshift/golang-builder:1.11 AS builder

ARG version=v1.4.0-11-1-gd72b966
ARG us_version=0.13.3
ARG commit=79a47ba545327ae424f5ae17d18cb29494970395
ENV GOPATH=/go

RUN yum install -y rsync sed
COPY kubevirt-${version}.tar.gz /
RUN tar xf /kubevirt-${version}.tar.gz && \
    mkdir -p /go/src/kubevirt.io/ && \
    mv kubevirt-${commit} /go/src/kubevirt.io/kubevirt
WORKDIR ${GOPATH}/src/kubevirt.io/kubevirt

RUN KUBEVIRT_VERSION=${us_version} \
    KUBEVIRT_SOURCE_DATE_EPOCH="$(date +%s)" \
    KUBEVIRT_GIT_COMMIT=${commit} \
    KUBEVIRT_GIT_VERSION=v${us_version} \
    KUBEVIRT_GIT_TREE_STATE=clean \
    ./hack/build-go.sh install cmd/virt-handler

FROM rhel7:7-released

ARG version=v1.4.0-11-1-gd72b966

RUN yum -y install iproute && yum clean all

COPY --from=builder /go/src/kubevirt.io/kubevirt/_out/cmd/virt-handler/virt-handler-${us_version}-linux-amd64 /usr/bin/virt-handler
ENTRYPOINT [ "/usr/bin/virt-handler" ]

LABEL com.redhat.component="virt-handler-container" \
      name="cnv-tech-preview/virt-handler" \
      version="v1.4.0" \
      summary="Virtualization handler" \
      io.openshift.expose-services="" \
      io.openshift.tags="cnv,kubevirt" \
      io.k8s.display-name="virt-handler" \
      maintainer="The KubeVirt Project <kubevirt-dev@googlegroups.com>" \
      description="Virtualization handler for CNV"
