# Build stage 1

FROM openshift/golang-builder:1.11 AS builder

ENV GOPATH=/go
ENV IMPORT_PATH=github.com/openshift/ocs-operator
ENV GO111MODULE=off

RUN rm -rf /go && mkdir -p /go/
COPY ocs-operator-release_4.4-3e9b7a50.tar.gz /ocs-operator.tar.gz
RUN \
    tar -C /go/ -xzmf /ocs-operator.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 '-extldflags "-static"' -o bin/ocs-operator "$IMPORT_PATH/cmd/manager/"

# Build stage 2
FROM ubi8-minimal:8-released

ENV OPBIN=/usr/local/bin/ocs-operator

COPY --from=builder /go/bin/ocs-operator "$OPBIN"

LABEL maintainer="Boris Ranto <branto@redhat.com>"
LABEL com.redhat.component="ocs-operator-container"
LABEL name="ocs-operator"
LABEL version="4.4"
LABEL release="24.3e9b7a50.release_4.4"
LABEL description="OpenShift Container Storage Operator container"
LABEL summary="Provides the latest Operator package for OpenShift Container Storage."
LABEL io.k8s.display-name="OCS Operator based on RHEL 8"
LABEL io.k8s.description="OpenShift Container Storage Operator container based on Red Hat Enterprise Linux 8 Image"
LABEL io.openshift.tags="ocs"
LABEL ocs.tags="v4.4"
LABEL upstream-vcs-ref="3e9b7a502f9d7ecd311cffe47400ad89d4c2b16c"

RUN echo "OpenShift Container Storage Operator 4.4 (Container)" > /etc/redhat-storage-release

RUN chmod +x "$OPBIN"

ENTRYPOINT ["/usr/local/bin/ocs-operator"]
