# Build stage 1

FROM openshift/golang-builder:1.13 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.5-de48c9c0.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 registry.redhat.io/ubi8/ubi-minimal

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

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.5"
LABEL release="42.de48c9c0.release_4.5"
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.5"
LABEL upstream-vcs-ref="de48c9c00f8964f0f8813d7b3ddd25f7bc318449"

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

RUN chmod +x "$OPBIN"

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