FROM openshift/golang-builder:1.13 AS builder
ENV __doozer=update BUILD_RELEASE=202103270246.p0 BUILD_VERSION=v4.5.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=5 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.5.0-202103270246.p0 SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=88e7c98f74295ceeaa8fd7aa1f929bae67ea5db7 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=16+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.16.0+88e7c98 OS_GIT_COMMIT=88e7c98 OS_GIT_VERSION=4.5.0-202103270246.p0-88e7c98 SOURCE_DATE_EPOCH=1586376987 SOURCE_GIT_COMMIT=88e7c98f74295ceeaa8fd7aa1f929bae67ea5db7 SOURCE_GIT_TAG=88e7c98f SOURCE_GIT_URL=https://github.com/openshift/ocp-release-operator-sdk 

ENV GO111MODULE=on \
    GOFLAGS=-mod=vendor

COPY . /go/src/github.com/operator-framework/operator-sdk
RUN cd /go/src/github.com/operator-framework/operator-sdk \
 && make build/operator-sdk-dev VERSION=dev

FROM openshift/ose-base:v4.5.0.20210327.031006
ENV __doozer=update BUILD_RELEASE=202103270246.p0 BUILD_VERSION=v4.5.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=5 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.5.0-202103270246.p0 SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=88e7c98f74295ceeaa8fd7aa1f929bae67ea5db7 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=16+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.16.0+88e7c98 OS_GIT_COMMIT=88e7c98 OS_GIT_VERSION=4.5.0-202103270246.p0-88e7c98 SOURCE_DATE_EPOCH=1586376987 SOURCE_GIT_COMMIT=88e7c98f74295ceeaa8fd7aa1f929bae67ea5db7 SOURCE_GIT_TAG=88e7c98f SOURCE_GIT_URL=https://github.com/openshift/ocp-release-operator-sdk 

RUN yum install -y \
      ansible \
      ansible-runner \
      ansible-runner-http \
      python-kubernetes \
      python-openshift \
      python-jmespath \
      tini \
      inotify-tools \
      python-requests-2.6.0-7.el7_7 \
 && yum clean all \
 && rm -rf /var/cache/yum

RUN mkdir -p /etc/ansible \
    && echo "localhost ansible_connection=local" > /etc/ansible/hosts \
    && echo '[defaults]' > /etc/ansible/ansible.cfg \
    && echo 'roles_path = /opt/ansible/roles' >> /etc/ansible/ansible.cfg

ENV OPERATOR=/usr/local/bin/ansible-operator \
    USER_UID=1001 \
    USER_NAME=ansible-operator\
    HOME=/opt/ansible

COPY release/ansible/ansible_collections ${HOME}/.ansible/collections/ansible_collections

COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/build/operator-sdk-dev ${OPERATOR}
COPY release/ansible/bin /usr/local/bin

RUN /usr/local/bin/user_setup

# Ensure directory permissions are properly set
RUN mkdir -p ${HOME}/.ansible/tmp \
 && chown -R ${USER_UID}:0 ${HOME} \
 && chmod -R ug+rwx ${HOME}

ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint"]

USER ${USER_UID}

LABEL \
        name="openshift/ose-ansible-operator" \
        com.redhat.component="openshift-enterprise-ansible-operator-container" \
        io.openshift.maintainer.product="OpenShift Container Platform" \
        io.openshift.maintainer.component="Operator SDK" \
        release="202103270246.p0" \
        io.openshift.build.commit.id="88e7c98f74295ceeaa8fd7aa1f929bae67ea5db7" \
        io.openshift.build.source-location="https://github.com/openshift/ocp-release-operator-sdk" \
        io.openshift.build.commit.url="https://github.com/openshift/ocp-release-operator-sdk/commit/88e7c98f74295ceeaa8fd7aa1f929bae67ea5db7" \
        version="v4.5.0"

