FROM ubi8-minimal:8-released AS builder

ENV GOPATH=/go

# Catch US Dockerfile changes that need to be propagated DS
ENV US_DOCKERFILE_MD5=07d89734b5cc5621da654d630a4b3b00

RUN microdnf 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_DOCKERFILE_MD5  hack/build/docker/cdi-controller/Dockerfile" > .md5sums && \
    md5sum -c .md5sums && rm .md5sums && \
    ./hack/build/build-go.sh build cmd/cdi-controller


FROM ubi8-minimal:8-released
COPY --from=builder /go/src/kubevirt.io/containerized-data-importer/_out/cmd/cdi-controller/cdi-controller /usr/bin/virt-cdi-controller

# Create non-root user
RUN microdnf install -y shadow-utils
RUN useradd -u 1001 --create-home -s /bin/bash cdi-controller
WORKDIR /home/cdi-controller
USER 1001

ENTRYPOINT [ "/usr/bin/virt-cdi-controller", "-alsologtostderr" ]

LABEL com.redhat.component="virt-cdi-controller-container" \
      name="container-native-virtualization/virt-cdi-controller" \
      version="${CI_CONTAINER_VERSION}" \
      release="${CI_CONTAINER_RELEASE}" \
      summary="Controller for the data fetching service" \
      io.openshift.expose-services="" \
      io.openshift.tags="data,images" \
      io.k8s.display-name="virt-cdi-controller" \
      maintainer="The KubeVirt Project <kubevirt-dev@googlegroups.com" \
      description="Controller for the data fetching service for CNV images"
