#@follow_tag(registry.redhat.io/rhel8-2-els/rhel)
FROM registry.redhat.io/rhel8-2-els/rhel:8.2-16.1618969485
ENV VERSION=${CI_UPSTREAM_VERSION}

LABEL com.redhat.component="kubevirt-v2v-conversion-container" \
      name="container-native-virtualization/kubevirt-v2v-conversion" \
      version="${CI_CONTAINER_VERSION}" \
      summary="Worker for V2V conversions" \
      io.openshift.tags="cnv,kubevirt,VM" \
      io.k8s.display-name="kubevirt-v2v-conversion" \
      maintainer="Tomas Golembiovsky <tgolembi@redhat.com>" \
      description="Performs V2V conversions from VMware to Kubevirt"

RUN dnf -y module enable virt:8.2 llvm-toolset:rhel8 python36:3.6 && \
    dnf -y --setopt=tsflags=nodocs install \
        nbdkit \
        nbdkit-plugin-python3 \
        nbdkit-plugin-vddk \
        python3-openstackclient \
        python3-ovirt-engine-sdk4 \
        qemu-kvm \
        v2v-conversion-host-wrapper-$VERSION \
        virt-v2v \
        virtio-win && \
    dnf -y clean all

# NOTES:
# - The container image cannot handle sparse file properly. Keep --size to the
#   required minimum.
# - Don't try to remove guestfs directory and then rename guestfs.fixed. This
#   will confuse AUFS and one will end up with directory that contains both
#   deleted and new files/directories.
RUN /usr/bin/supermin \
        --build \
        --verbose \
        --copy-kernel \
        --format ext2 \
        --size 300M \
        --host-cpu x86_64 \
        /usr/lib64/guestfs/supermin.d \
        -o /usr/lib64/guestfs.fixed/ && \
    rm -frv /usr/lib64/guestfs/* && \
    mv -v /usr/lib64/guestfs.fixed/* /usr/lib64/guestfs && \
    touch /usr/lib64/guestfs/README.fixed && \
    LIBGUESTFS_BACKEND=direct libguestfs-test-tool

RUN install --mode=0775 --group=0 -d /data && \
    install --mode=0775 --group=0 -d /data/input && \
    install --mode=0775 --group=0 -d /data/vddklib && \
    install --mode=0775 --group=0 -d /data/vm && \
    ln -s /data/vddklib/vmware-vix-disklib-distrib /opt/vmware-vix-disklib-distrib && \
    true

COPY entrypoint /usr/local/bin/entrypoint

ENTRYPOINT ["/usr/local/bin/entrypoint"]
USER ${USER_UID}
