# need the helm-cli from the helm image
FROM openshift/ose-metering-helm:v4.2.9.20191126.113339 AS helm
ENV SOURCE_GIT_COMMIT=9f5405975f6120dec750fa781052747e9b8d1843 SOURCE_DATE_EPOCH=1573452898 BUILD_VERSION=v4.2.9 SOURCE_GIT_URL=https://github.com/operator-framework/operator-metering SOURCE_GIT_TAG=9f54059 BUILD_RELEASE=201911261133
# final image needs kubectl, so we copy `oc` from cli image to use as kubectl.
FROM openshift/ose-cli:v4.2.9.20191126.113339 AS cli
ENV SOURCE_GIT_COMMIT=9f5405975f6120dec750fa781052747e9b8d1843 SOURCE_DATE_EPOCH=1573452898 BUILD_VERSION=v4.2.9 SOURCE_GIT_URL=https://github.com/operator-framework/operator-metering SOURCE_GIT_TAG=9f54059 BUILD_RELEASE=201911261133
# real base
FROM openshift/ose-ansible-operator:v4.2.9.20191126.113339
ENV SOURCE_GIT_COMMIT=9f5405975f6120dec750fa781052747e9b8d1843 SOURCE_DATE_EPOCH=1573452898 BUILD_VERSION=v4.2.9 SOURCE_GIT_URL=https://github.com/operator-framework/operator-metering SOURCE_GIT_TAG=9f54059 BUILD_RELEASE=201911261133

USER root
RUN INSTALL_PKGS="curl bash ca-certificates less which inotify-tools tini python-boto3 python2-openshift python2-cryptography openssl" \
    && yum install --setopt=skip_missing_names_on_install=False -y \
        $INSTALL_PKGS  \
    && yum clean all \
    && rm -rf /var/cache/yum

COPY --from=helm /usr/local/bin/helm /usr/local/bin/helm
COPY --from=cli /usr/bin/oc /usr/bin/oc
RUN ln -f -s /usr/bin/oc /usr/bin/kubectl

RUN yum -y update python2-openshift python2-cryptography

ENV HOME /opt/ansible
ENV HELM_CHART_PATH ${HOME}/charts/openshift-metering

COPY images/metering-ansible-operator/roles/ ${HOME}/roles/
COPY images/metering-ansible-operator/watches.yaml ${HOME}/watches.yaml
COPY images/metering-ansible-operator/scripts ${HOME}/scripts
COPY images/metering-ansible-operator/ansible.cfg /etc/ansible/ansible.cfg
COPY charts/openshift-metering ${HELM_CHART_PATH}

COPY manifests/deploy/openshift/olm/bundle /manifests

# to allow running as non-root
RUN chown -R 1001:0 $HOME && \
    chmod -R 774 $HOME /etc/passwd

ENTRYPOINT ["/opt/ansible/scripts/entrypoint.sh"]

USER 1001

LABEL \
        io.k8s.description="This is a component of OpenShift Container Platform and manages installation and configuration of all other metering components." \
        com.redhat.component="ose-metering-ansible-operator-container" \
        maintainer="Chance Zibolski <sd-operator-metering@redhat.com>" \
        name="openshift/ose-metering-ansible-operator" \
        com.redhat.delivery.appregistry="false" \
        io.k8s.display-name="OpenShift metering-ansible-operator" \
        io.openshift.build.source-location="https://github.com/operator-framework/operator-metering" \
        io.openshift.build.commit.url="https://github.com/operator-framework/operator-metering/commit/9f5405975f6120dec750fa781052747e9b8d1843" \
        version="v4.2.9" \
        io.openshift.build.commit.id="9f5405975f6120dec750fa781052747e9b8d1843" \
        release="201911261133" \
        io.openshift.tags="openshift"

