ARG BUILD_DIR=/tmp/github.com/redhat-developer/service-binding-operator

# On CI, use
# FROM registry.svc.ci.openshift.org/ocp/builder:golang-1.13 AS builder

#FROM openshift/origin-release:golang-1.13 AS builder
#@follow_tag(rhel8/go-toolset:1.13)
FROM rhel8/go-toolset:1.14 AS builder

USER root
RUN dnf install -y jq

ARG BUILD_DIR

ENV LANG=en_US.utf8

# GOPATH-ish dir structure not needed anymore
WORKDIR $BUILD_DIR

# TODO: Use a RUN command to copy over specific files/dirs in a different PR
# Collapsing it into a single COPY to reduce layers, as of now.
COPY service-binding-operator-fff80ee02bc07d6092de475e2877bb1161ac695b.tar.gz .

RUN tar xf service-binding-operator-fff80ee02bc07d6092de475e2877bb1161ac695b.tar.gz --strip-components=1 && rm service-binding-operator-fff80ee02bc07d6092de475e2877bb1161ac695b.tar.gz 

RUN curl -Lo /usr/local/bin/operator-sdk http://pkgs.devel.redhat.com/repo/containers/service-binding-operator/operator-sdk-v0.15.1-x86_64-linux-gnu/f01af7292432e048580e69e413c55dce/operator-sdk-v0.15.1-x86_64-linux-gnu && \
    chmod +x /usr/local/bin/operator-sdk

ARG VERBOSE=2

ENV GOFLAGS="-mod=vendor"

RUN BUNDLE_VERSION="0.3.0" \
    OPERATOR_IMAGE_REF="registry.redhat.io/ocp-tools-4-tech-preview/service-binding-rhel8-operator:v0.3.0" \
    CSV_PACKAGE_NAME="rh-service-binding-operator" \
    make build push-to-manifest-repo


#--------------------------------------------------------------------

# On CI with pull secrets , use
# FROM registry.redhat.io/ubi8/ubi

#@follow_tag(ubi8-minimal:8-released)
FROM ubi8-minimal:8-released

ARG BUILD_DIR

ENV LANG=en_US.utf8

RUN microdnf install -y shadow-utils && \
    adduser --system --no-create-home -u 1001 sbo

ENTRYPOINT [ "/usr/local/bin/service-binding-operator" ]

COPY --from=builder $BUILD_DIR/out/operator /usr/local/bin/service-binding-operator
COPY --from=builder $BUILD_DIR/tmp/manifests /manifests

USER sbo


LABEL com.redhat.component="service-binding-operator-container" \
	name="ocp-tools-4-tech-preview/service-binding-rhel8-operator"

LABEL 	version="v0.3.0" \
      	io.k8s.display-name="The Service Binding Operator" \
      	io.openshift.build.source-location="https://github.com/redhat-developer/service-binding-operator" \
      	io.openshift.build.commit.url="https://github.com/redhat-developer/service-binding-operator/commit/fff80ee02bc07d6092de475e2877bb1161ac695b" \
      	io.openshift.build.commit.id="fff80ee02bc07d6092de475e2877bb1161ac695b" \
      	maintainer="devtools <devtools@redhat.com>"
