# Build stage 1

FROM rhceph:4-32 AS builder

ENV GOPATH=/go
ENV IMPORT_PATH=github.com/ceph/ceph-csi

RUN rm -rf /go && mkdir -p /go/
COPY cephcsi-release_4.5-dad7c0373.tar.gz /cephcsi.tar.gz
RUN \
    mkdir -p "/go/src/$IMPORT_PATH" && \
    tar -C "/go/src/$IMPORT_PATH/" -xzmf /cephcsi.tar.gz && \
    rm -rf "/go/src/$IMPORT_PATH/vendor/$IMPORT_PATH" && \
    cp -r "/go/src/$IMPORT_PATH/vendor/"* /go/src/ && \
    rm -rf "/go/src/$IMPORT_PATH/vendor"

RUN \
    dnf module enable -y 'go-toolset:rhel8' && \
    dnf install -y golang librados-devel librbd-devel

WORKDIR /go
RUN CGO_ENABLED=1 GOOS=linux go build -a -ldflags "-X $IMPORT_PATH/pkg/util.GitCommit=dad7c0373e384a2c20970881c16b1618e25b20ab -X $IMPORT_PATH/pkg/util.DriverVersion=release-4.5 " -o bin/cephcsi "$IMPORT_PATH/cmd/"

# Build stage 2
FROM rhceph:4-32

# Update the image to get the latest CVE updates
RUN \
    dnf update -y

ENV CSIBIN=/usr/local/bin/cephcsi

COPY --from=builder /go/bin/cephcsi "$CSIBIN"

LABEL maintainer="Boris Ranto <branto@redhat.com>"
LABEL com.redhat.component="cephcsi-container"
LABEL name="cephcsi"
LABEL version="4.5"
LABEL release="36.dad7c0373.release_4.5"
LABEL description="OpenShift Container Storage Ceph CSI container"
LABEL summary="Provides the latest Ceph CSI package for OpenShift Container Storage."
LABEL io.k8s.display-name="OCS Ceph CSI based on RHEL 8"
LABEL io.k8s.description="OpenShift Container Storage Ceph CSI container based on Red Hat Enterprise Linux 8 Image"
LABEL io.openshift.tags="ocs"
LABEL ocs.tags="v4.5"
LABEL upstream-vcs-ref="dad7c0373e384a2c20970881c16b1618e25b20ab"

RUN echo "OpenShift Container Storage Ceph CSI 4.5 (Container)" > /etc/redhat-storage-release

RUN chmod +x "$CSIBIN"

ENTRYPOINT ["/usr/local/bin/cephcsi"]
