# Build stage 1

FROM openshift/golang-builder:1.13 AS builder

ENV GOPATH=/go
ENV GO111MODULE=off
ENV IMPORT_PATH=github.com/noobaa/noobaa-operator/v2

RUN rm -rf /go && mkdir -p /go/
COPY noobaa-operator-32.25a2937.2.3.tar.gz /operator.tar.gz
RUN \
    tar -C /go/ -xzf /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 go version
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '-extldflags "-static"' -a -v -x -o bin/noobaa-operator

# Build stage 2
FROM registry.redhat.io/ubi8/ubi-minimal

ENV OPERATOR=/usr/local/bin/noobaa-operator \
    USER_UID=1001 \
    USER_NAME=noobaa-operator

RUN microdnf update -y && \
    microdnf clean all

COPY --from=builder /go/build/bin/ /usr/local/bin
COPY --from=builder /go/bin/noobaa-operator ${OPERATOR}

RUN  /usr/local/bin/user_setup

ENTRYPOINT ["/usr/local/bin/entrypoint"]
CMD ["operator", "run"]
 
USER ${USER_UID}

LABEL maintainer="Boris Ranto (branto@redhat.com)"
LABEL com.redhat.component="noobaa-operator-container"
LABEL io.k8s.display-name="Noobaa Operator based on RHEL 8"
LABEL io.k8s.description="Noobaa Operator Container based on Red Hat Enterprise Linux 8 Image"
LABEL name="mcg-operator"
LABEL version="2.3.0"
LABEL release="32.25a2937.2.3"
LABEL summary="Provides the latest NooBaa Operator container for OpenShift Container Storage"
LABEL description="OpenShift Container Storage NooBaa Operator container"
LABEL io.openshift.tags="ocs"
LABEL ocs.tags="v4.5"
LABEL upstream-vcs-ref="25a29375c96d417c971131abc478650da5584c4f"
