# Build stage 1 -- build rook

FROM openshift/golang-builder:1.11 AS builder

ENV GOPATH=/go
ENV IMPORT_PATH=github.com/rook/rook
ENV VERSION=4.4-29.ea33cd0a.release_4.4

RUN rm -rf /go && mkdir -p /go/
COPY rook-release_4.4-ea33cd0a.tar.gz /rook.tar.gz
RUN \
    tar -C /go/ -xzmf /rook.tar.gz && \
    cd /go/ && \
    mv -f vendor src && \
    mkdir -p "src/$IMPORT_PATH" && \
    rm -rf "src/$IMPORT_PATH" && \
    ln -s /go/ "src/$IMPORT_PATH"

WORKDIR /go
RUN CGO_ENABLED=0 GOOS=linux go build -compiler gc -ldflags "-v -n -X github.com/rook/rook/pkg/version.Version=${VERSION} -extldflags '-static'" -a -v -x -o bin/rook ${IMPORT_PATH}/cmd/rook
RUN CGO_ENABLED=0 GOOS=linux go build -compiler gc -ldflags "-v -n -X github.com/rook/rook/pkg/version.Version=${VERSION} -extldflags '-static'" -a -v -x -o bin/rookflex ${IMPORT_PATH}/cmd/rookflex

# Build stage 2 -- create rook container
FROM rhceph:4-28

COPY --from=builder /go/bin/rook /go/bin/rookflex /go/images/ceph/toolbox.sh /usr/local/bin/
COPY --from=builder /go/cluster/examples/kubernetes/ceph/csi/template /etc/ceph-csi
COPY --from=builder /go/cluster/examples/kubernetes/ceph/monitoring /etc/ceph-monitoring
COPY --from=builder /go/cluster/olm/ceph/templates /etc/ceph-csv-templates

RUN \
    dnf update -y && \
    dnf install -y tini

RUN ln -s /usr/bin/tini /tini

LABEL maintainer="Boris Ranto <branto@redhat.com>"
LABEL com.redhat.component="rook-ceph-operator-container"
LABEL name="rook-ceph"
LABEL version="4.4"
LABEL release="29.ea33cd0a.release_4.4"
LABEL description="OpenShift Container Storage Rook container"
LABEL summary="Provides the latest Rook package for OpenShift Container Storage."
LABEL io.k8s.display-name="Rook Ceph Orchestrator"
LABEL io.openshift.tags="rhceph ceph rook"
LABEL upstream-vcs-ref="ea33cd0a5a0c98a5ef07d044db0d65f461b74205"
LABEL ocs.tags="v4.4"

ENTRYPOINT ["/tini", "--", "/usr/local/bin/rook"]
CMD [""]
