# need the helm-cli from the helm image
FROM openshift/ose-metering-helm:v4.8.0.20211026.222920 AS helm
ENV __doozer=update BUILD_RELEASE=202110262219.p0.git.0d7ecfb.assembly.stream BUILD_VERSION=v4.8.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=8 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.8.0-202110262219.p0.git.0d7ecfb.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=0d7ecfb5f9ca4603990bb264eae4d998da0e1060 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=13+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.13.0+0d7ecfb OS_GIT_COMMIT=0d7ecfb OS_GIT_VERSION=4.8.0-202110262219.p0.git.0d7ecfb.assembly.stream-0d7ecfb SOURCE_DATE_EPOCH=1616532080 SOURCE_GIT_COMMIT=0d7ecfb5f9ca4603990bb264eae4d998da0e1060 SOURCE_GIT_TAG=0.14.0-1727-g0d7ecfb5 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.8.0.20211026.222920 AS cli
ENV __doozer=update BUILD_RELEASE=202110262219.p0.git.0d7ecfb.assembly.stream BUILD_VERSION=v4.8.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=8 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.8.0-202110262219.p0.git.0d7ecfb.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=0d7ecfb5f9ca4603990bb264eae4d998da0e1060 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=13+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.13.0+0d7ecfb OS_GIT_COMMIT=0d7ecfb OS_GIT_VERSION=4.8.0-202110262219.p0.git.0d7ecfb.assembly.stream-0d7ecfb SOURCE_DATE_EPOCH=1616532080 SOURCE_GIT_COMMIT=0d7ecfb5f9ca4603990bb264eae4d998da0e1060 SOURCE_GIT_TAG=0.14.0-1727-g0d7ecfb5 SOURCE_GIT_URL=https://github.com/kube-reporting/metering-operator 
# real base
FROM openshift/ose-ansible-operator:v4.8.0.20211026.222920
ENV __doozer=update BUILD_RELEASE=202110262219.p0.git.0d7ecfb.assembly.stream BUILD_VERSION=v4.8.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=8 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.8.0-202110262219.p0.git.0d7ecfb.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=0d7ecfb5f9ca4603990bb264eae4d998da0e1060 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=13+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.13.0+0d7ecfb OS_GIT_COMMIT=0d7ecfb OS_GIT_VERSION=4.8.0-202110262219.p0.git.0d7ecfb.assembly.stream-0d7ecfb SOURCE_DATE_EPOCH=1616532080 SOURCE_GIT_COMMIT=0d7ecfb5f9ca4603990bb264eae4d998da0e1060 SOURCE_GIT_TAG=0.14.0-1727-g0d7ecfb5 SOURCE_GIT_URL=https://github.com/kube-reporting/metering-operator 

USER root
RUN set -x; \
    INSTALL_PKGS="curl bash ca-certificates \
    less which tini \
    python3-netaddr python3-botocore \
    python3-boto3 python3-openshift \
    python3-cryptography ansible 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

# Ansible 2.9.6 and above is required due to the crypto.py FIPS fix
# being patched upstream: https://bugzilla.redhat.com/show_bug.cgi?id=1899136
RUN yum -y update python3-openshift python3-cryptography 'ansible>=2.9.6'

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/ansible.cfg /etc/ansible/ansible.cfg
COPY charts/openshift-metering ${HELM_CHART_PATH}

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

USER 1001
ENTRYPOINT ["tini", "--", "/usr/local/bin/ansible-operator", "run", "--watches-file", "/opt/ansible/watches.yaml"]

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." \
        summary="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="<metering-team@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" \
        release="202110262219.p0.git.0d7ecfb.assembly.stream" \
        io.openshift.build.commit.id="0d7ecfb5f9ca4603990bb264eae4d998da0e1060" \
        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/0d7ecfb5f9ca4603990bb264eae4d998da0e1060" \
        version="v4.8.0"

