# need the helm-cli from the helm image
FROM openshift/ose-metering-helm:v4.3.20.20200512.184737 AS helm
ENV __doozer=update BUILD_RELEASE=202005121847 BUILD_VERSION=v4.3.20 OS_GIT_MAJOR=4 OS_GIT_MINOR=3 OS_GIT_PATCH=20 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.3.20-202005121847 
ENV __doozer=merge OS_GIT_COMMIT=44d9b03 OS_GIT_VERSION=4.3.20-202005121847-44d9b03 SOURCE_DATE_EPOCH=1580854051 SOURCE_GIT_COMMIT=44d9b0329bf6ef52049f122e4760ef4e66e72e52 SOURCE_GIT_TAG=44d9b032 SOURCE_GIT_URL=https://github.com/kube-reporting/metering-operator 
# final image needs kubectl, so we copy `oc` from cli image to use as kubectl.
FROM openshift/ose-cli:v4.3.20.20200512.184737 AS cli
ENV __doozer=update BUILD_RELEASE=202005121847 BUILD_VERSION=v4.3.20 OS_GIT_MAJOR=4 OS_GIT_MINOR=3 OS_GIT_PATCH=20 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.3.20-202005121847 
ENV __doozer=merge OS_GIT_COMMIT=44d9b03 OS_GIT_VERSION=4.3.20-202005121847-44d9b03 SOURCE_DATE_EPOCH=1580854051 SOURCE_GIT_COMMIT=44d9b0329bf6ef52049f122e4760ef4e66e72e52 SOURCE_GIT_TAG=44d9b032 SOURCE_GIT_URL=https://github.com/kube-reporting/metering-operator 
# real base
FROM openshift/ose-ansible-operator:v4.3.20.20200512.184737
ENV __doozer=update BUILD_RELEASE=202005121847 BUILD_VERSION=v4.3.20 OS_GIT_MAJOR=4 OS_GIT_MINOR=3 OS_GIT_PATCH=20 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.3.20-202005121847 
ENV __doozer=merge OS_GIT_COMMIT=44d9b03 OS_GIT_VERSION=4.3.20-202005121847-44d9b03 SOURCE_DATE_EPOCH=1580854051 SOURCE_GIT_COMMIT=44d9b0329bf6ef52049f122e4760ef4e66e72e52 SOURCE_GIT_TAG=44d9b032 SOURCE_GIT_URL=https://github.com/kube-reporting/metering-operator 

USER root
RUN set -x; 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.display-name="OpenShift metering-ansible-operator" \
        io.k8s.description="This is a component of OpenShift Container Platform and manages installation and configuration of all other metering components." \
        io.openshift.tags="openshift" \
        com.redhat.delivery.appregistry="false" \
        maintainer="Chance Zibolski <sd-operator-metering@redhat.com>" \
        name="openshift/ose-metering-ansible-operator" \
        com.redhat.component="ose-metering-ansible-operator-container" \
        io.openshift.maintainer.product="OpenShift Container Platform" \
        io.openshift.maintainer.component="Metering Operator" \
        version="v4.3.20" \
        release="202005121847" \
        io.openshift.build.commit.id="44d9b0329bf6ef52049f122e4760ef4e66e72e52" \
        io.openshift.build.source-location="https://github.com/kube-reporting/metering-operator" \
        io.openshift.build.commit.url="https://github.com/kube-reporting/metering-operator/commit/44d9b0329bf6ef52049f122e4760ef4e66e72e52"

