FROM openshift/golang-builder:rhel_8_golang_1.15 AS builder
ENV __doozer=update BUILD_RELEASE=202201111855.p0.gd13e51c.assembly.stream BUILD_VERSION=v4.6.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=6 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.6.0-202201111855.p0.gd13e51c.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge OS_GIT_COMMIT=d13e51c OS_GIT_VERSION=4.6.0-202201111855.p0.gd13e51c.assembly.stream-d13e51c SOURCE_DATE_EPOCH=1624562969 SOURCE_GIT_COMMIT=d13e51ceec5f7379de64aabce2c0befc094a3e7b SOURCE_GIT_TAG=v1.14.3-36-gd13e51ce SOURCE_GIT_URL=https://github.com/operator-framework/operator-registry 

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

WORKDIR /src

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

# copy and build vendored grpc_health_probe
RUN CGO_ENABLED=0 go build -mod=vendor -tags netgo -ldflags "-w" ./vendor/github.com/grpc-ecosystem/grpc-health-probe/...

FROM openshift/ose-base:v4.6.0-202201111633.p0.g618b71d.assembly.stream
ENV __doozer=update BUILD_RELEASE=202201111855.p0.gd13e51c.assembly.stream BUILD_VERSION=v4.6.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=6 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.6.0-202201111855.p0.gd13e51c.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge OS_GIT_COMMIT=d13e51c OS_GIT_VERSION=4.6.0-202201111855.p0.gd13e51c.assembly.stream-d13e51c SOURCE_DATE_EPOCH=1624562969 SOURCE_GIT_COMMIT=d13e51ceec5f7379de64aabce2c0befc094a3e7b SOURCE_GIT_TAG=v1.14.3-36-gd13e51ce SOURCE_GIT_URL=https://github.com/operator-framework/operator-registry 

COPY --from=builder /src/bin/* /bin/registry/
COPY --from=builder /src/grpc-health-probe /bin/grpc_health_probe

RUN ln -s /bin/registry/* /bin

RUN mkdir /registry
RUN chgrp -R 0 /registry && \
    chmod -R g+rwx /registry
WORKDIR /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="202201111855.p0.gd13e51c.assembly.stream" \
        io.openshift.build.commit.id="d13e51ceec5f7379de64aabce2c0befc094a3e7b" \
        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/d13e51ceec5f7379de64aabce2c0befc094a3e7b" \
        version="v4.6.0"

