FROM openshift/golang-builder:1.10 AS builder
ENV SOURCE_GIT_COMMIT=1fadbac661adbc4584c27b0eb28ea50c9ee7893c SOURCE_DATE_EPOCH=1567594105 BUILD_VERSION=v4.1.16 SOURCE_GIT_URL=https://github.com/operator-framework/operator-registry SOURCE_GIT_TAG=v1.1.0-23-g1fadbac BUILD_RELEASE=201909100604

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 /go/src/github.com/operator-framework/operator-registry

COPY vendor vendor
COPY cmd cmd
COPY pkg pkg
COPY Makefile Makefile
RUN make static-rh

# 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 && \
    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.1.16.20190910.060423
ENV SOURCE_GIT_COMMIT=1fadbac661adbc4584c27b0eb28ea50c9ee7893c SOURCE_DATE_EPOCH=1567594105 BUILD_VERSION=v4.1.16 SOURCE_GIT_URL=https://github.com/operator-framework/operator-registry SOURCE_GIT_TAG=v1.1.0-23-g1fadbac BUILD_RELEASE=201909100604

RUN mkdir /registry
WORKDIR /registry

COPY --from=builder /go/src/github.com/operator-framework/operator-registry/bin/initializer /bin/initializer
COPY --from=builder /go/src/github.com/operator-framework/operator-registry/bin/registry-server /bin/registry-server
COPY --from=builder /go/src/github.com/operator-framework/operator-registry/bin/configmap-server /bin/configmap-server
COPY --from=builder /go/src/github.com/operator-framework/operator-registry/bin/appregistry-server /bin/appregistry-server
COPY --from=builder /go/bin/grpc_health_probe /bin/grpc_health_probe

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

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

EXPOSE 50051

LABEL \
        io.k8s.description="This is a component of OpenShift Operator Lifecycle Manager and is the base for operator catalog API containers." \
        com.redhat.component="operator-registry-container" \
        maintainer="Odin Team <aos-odin@redhat.com>" \
        name="openshift/ose-operator-registry" \
        io.k8s.display-name="OpenShift Operator Registry" \
        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/1fadbac661adbc4584c27b0eb28ea50c9ee7893c" \
        version="v4.1.16" \
        io.openshift.build.commit.id="1fadbac661adbc4584c27b0eb28ea50c9ee7893c" \
        release="201909100604"

