# Build stage 1

FROM openshift/golang-builder:1.11 AS builder

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

RUN rm -rf /go && mkdir -p /go/
COPY cephcsi-release_4.3-6057d566.tar.gz /cephcsi.tar.gz
RUN \
    tar -C /go/ -xzmf /cephcsi.tar.gz && \
    cd /go/ && \
    mv -f vendor src && \
    mkdir -p "src/$IMPORT_PATH" && \
    rm -rf "src/$IMPORT_PATH" && \
    ln -s /go/ "src/$IMPORT_PATH" && \
    ls -l "/go/src/$IMPORT_PATH"

WORKDIR /go
RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-X $IMPORT_PATH/pkg/util.GitCommit=b812ec26df5c7519c400aeba0d23339c618a550b -X $IMPORT_PATH/pkg/util.DriverVersion=canary -extldflags '-static'" -o bin/cephcsi "$IMPORT_PATH/cmd/"

# Build stage 2
FROM rhceph:4-20

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.3"
LABEL release="34.6057d566.release_4.3"
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.3"
LABEL upstream-vcs-ref="6057d566b2d94c19a996869613ec7eb7530275e4"

RUN yum update -y && yum clean all;
RUN echo "OpenShift Container Storage Ceph CSI 4.3 (Container)" > /etc/redhat-storage-release

RUN chmod +x "$CSIBIN"

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