FROM openshift/golang-builder:1.13 AS builder
ENV __doozer=update BUILD_RELEASE=202103270246.p0 BUILD_VERSION=v4.5.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=5 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.5.0-202103270246.p0 SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=bc4c9f8f967736a6ff774c52845e8a3ed28e7072 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=13+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.13.0+bc4c9f8 OS_GIT_COMMIT=bc4c9f8 OS_GIT_VERSION=4.5.0-202103270246.p0-bc4c9f8 SOURCE_DATE_EPOCH=1607122973 SOURCE_GIT_COMMIT=bc4c9f8f967736a6ff774c52845e8a3ed28e7072 SOURCE_GIT_TAG=v1.12.5-17-gbc4c9f8f SOURCE_GIT_URL=https://github.com/operator-framework/operator-registry 

RUN yum update -y && \
    yum install -y make git sqlite glibc-static openssl-static zlib-static && \
    yum groupinstall -y "Development Tools" "Development Libraries"

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

WORKDIR /src

COPY OPM_VERSION OPM_VERSION
COPY vendor vendor
COPY cmd cmd
COPY pkg pkg
COPY Makefile go.mod go.sum ./
RUN make build

# copy and build vendored grpc_health_probe
RUN mkdir -p /go/src/github.com/grpc-ecosystem && \
    cp -R vendor/github.com/grpc-ecosystem/grpc-health-probe /go/src/github.com/grpc-ecosystem/grpc_health_probe && \
    cp -R vendor/ /go/src/github.com/grpc-ecosystem/grpc_health_probe && \
    rm -rf /go/src/github.com/grpc-ecosystem/grpc_health_probe/vendor/github.com/grpc-ecosystem/grpc-health-probe && \
    cd /go/src/github.com/grpc-ecosystem/grpc_health_probe && \
    CGO_ENABLED=0 go install -a -tags netgo -ldflags "-w"

FROM openshift/ose-base:v4.5.0.20210327.031006
ENV __doozer=update BUILD_RELEASE=202103270246.p0 BUILD_VERSION=v4.5.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=5 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.5.0-202103270246.p0 SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=bc4c9f8f967736a6ff774c52845e8a3ed28e7072 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=13+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.13.0+bc4c9f8 OS_GIT_COMMIT=bc4c9f8 OS_GIT_VERSION=4.5.0-202103270246.p0-bc4c9f8 SOURCE_DATE_EPOCH=1607122973 SOURCE_GIT_COMMIT=bc4c9f8f967736a6ff774c52845e8a3ed28e7072 SOURCE_GIT_TAG=v1.12.5-17-gbc4c9f8f SOURCE_GIT_URL=https://github.com/operator-framework/operator-registry 

RUN mkdir /registry
WORKDIR /registry

COPY --from=builder /src/bin/initializer /bin/initializer
COPY --from=builder /src/bin/registry-server /bin/registry-server
COPY --from=builder /src/bin/configmap-server /bin/configmap-server
COPY --from=builder /src/bin/appregistry-server /bin/appregistry-server
COPY --from=builder /src/bin/opm /bin/opm
COPY --from=builder /go/bin/grpc-health-probe /bin/grpc_health_probe

RUN chgrp -R 0 /registry && \
    chmod -R g+rwx /registry

# This image doesn't need to run as root user
USER 1001

EXPOSE 50051

ENTRYPOINT ["/bin/registry-server"]
CMD ["--database", "/bundles.db"]

LABEL \
        io.k8s.display-name="OpenShift Operator Registry" \
        io.k8s.description="This is a component of OpenShift Operator Lifecycle Manager and is the base for operator catalog API containers." \
        maintainer="Odin Team <aos-odin@redhat.com>" \
        summary="Operator Registry runs in a Kubernetes or OpenShift cluster to provide operator catalog data to Operator Lifecycle Manager." \
        name="openshift/ose-operator-registry" \
        com.redhat.component="operator-registry-container" \
        io.openshift.maintainer.product="OpenShift Container Platform" \
        io.openshift.maintainer.component="OLM" \
        release="202103270246.p0" \
        io.openshift.build.commit.id="bc4c9f8f967736a6ff774c52845e8a3ed28e7072" \
        io.openshift.build.source-location="https://github.com/operator-framework/operator-registry" \
        io.openshift.build.commit.url="https://github.com/operator-framework/operator-registry/commit/bc4c9f8f967736a6ff774c52845e8a3ed28e7072" \
        version="v4.5.0"

