#@follow_tag(registry.redhat.io/rhel8-2-els/rhel)
FROM registry.redhat.io/rhel8-2-els/rhel:8.2-7 AS builder

ENV GOPATH=/go

# Catch US Bazel changes that need to be propagated DS
ENV US_BAZEL_MD5=4e79c74e093f384975782ee200270805

RUN echo -e "[go-toolset]\nname=go-toolset\nprofiles=\nstate=enabled\nstream=rhel8" > /etc/dnf/modules.d/go-toolset.module \
    && dnf install -y tar git sed go-compilers-golang-compiler

COPY containerized-data-importer-*.tar.gz /
RUN mkdir -p /go/src/kubevirt.io/containerized-data-importer && \
    tar -xzf containerized-data-importer-*.tar.gz --strip-components 1 \
        -C /go/src/kubevirt.io/containerized-data-importer && \
    cd /go/src/kubevirt.io/containerized-data-importer && \
    echo "$US_BAZEL_MD5 cmd/cdi-cloner/BUILD.bazel" > .md5sums && \
    md5sum -c .md5sums && rm .md5sums && \
    GOFLAGS=-mod=vendor ./hack/build/build-go.sh build cmd/cdi-cloner

#@follow_tag(registry.redhat.io/rhel8-2-els/rhel)
FROM registry.redhat.io/rhel8-2-els/rhel:8.2-7

RUN dnf install -y tar util-linux

COPY --from=builder /go/src/kubevirt.io/containerized-data-importer/cmd/cdi-cloner/cloner_startup.sh /usr/bin/cloner_startup.sh
COPY --from=builder /go/src/kubevirt.io/containerized-data-importer/_out/cmd/cdi-cloner/cdi-cloner /usr/bin/cdi-cloner
RUN chmod +x /usr/bin/cloner_startup.sh

ENTRYPOINT [ "/usr/bin/cloner_startup.sh" ]

LABEL com.redhat.component="virt-cdi-cloner-container" \
      name="container-native-virtualization/virt-cdi-cloner" \
      version="${CI_CONTAINER_VERSION}" \
      release="${CI_CONTAINER_RELEASE}" \
      summary="cloner for host assisted cloning" \
      io.openshift.expose-services="" \
      io.openshift.tags="data,images" \
      io.k8s.display-name="virt-cdi-cloner" \
      maintainer="The KubeVirt Project <kubevirt-dev@googlegroups.com" \
      description="Source and Target cloner image for host assisted cloning"
