#@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=0b9b8092fbd8cd0c705a68e3f1acbecb

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-uploadproxy/BUILD.bazel" > .md5sums && \
    md5sum -c .md5sums && rm .md5sums && \
    GOFLAGS=-mod=vendor ./hack/build/build-go.sh build cmd/cdi-uploadproxy


#@follow_tag(registry.redhat.io/rhel8-2-els/rhel)
FROM registry.redhat.io/rhel8-2-els/rhel:8.2-7
COPY --from=builder /go/src/kubevirt.io/containerized-data-importer/_out/cmd/cdi-uploadproxy/cdi-uploadproxy /usr/bin/virt-cdi-uploadproxy

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

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

LABEL com.redhat.component="virt-cdi-uploadproxy-container" \
      name="container-native-virtualization/virt-cdi-uploadproxy" \
      version="v2.4.5" \
      release="2" \
      summary="Upload proxy for the data fetching service" \
      io.openshift.expose-services="" \
      io.openshift.tags="data,images" \
      io.k8s.display-name="virt-cdi-uploadproxy" \
      maintainer="The KubeVirt Project <kubevirt-dev@googlegroups.com" \
      description="Upload proxy for the data fetching service for CNV images"
