FROM {{ conductor_base }}
ENV ANSIBLE_CONTAINER=1
{% set distro = conductor_base.split(':')[0] %}
{% set distro_version = conductor_base.split(':')[1] %}
{% for envar in environment %}
ENV {{ envar }}
{% endfor %}
{% if distro in ["fedora"] %}
RUN dnf update -y && \
    dnf install -y make gcc git python2 python2-devel curl rsync libffi-devel openssl-devel redhat-rpm-config python2-dnf tar redhat-rpm-config && \
    dnf clean all
{% elif distro in ["centos"] %}
RUN yum update -y && \
    yum install -y epel-release && \
    yum install -y make gcc git python-devel curl rsync libffi-devel openssl-devel && \
    # yum remove -y python-chardet && \
    yum clean all
{% elif "rhel" in distro %}
RUN yum -y update-minimal --disablerepo "*" \
                          --enablerepo rhel-7-server-rpms,rhel-7-server-optional-rpms \
                          --security --sec-severity=Important --sec-severity=Critical --setopt=tsflags=nodocs && \
    yum -y install --disablerepo "*" \
                   --enablerepo rhel-7-server-rpms \
                   https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && \
    yum -y install --disablerepo "*" \
                   --enablerepo epel,rhel-7-server-rpms,rhel-7-server-optional-rpms \
                   make gcc git python-devel curl rsync libffi-devel openssl-devel tar redhat-rpm-config&& \
    yum clean all
{% elif distro in ["debian", "ubuntu"] %}
RUN apt-get update -y && \
    apt-get install -y make dpkg-dev curl gcc git libffi-dev libpopt0 libssl-dev python2.7 python-apt python-dev rsync sudo && \
    cd /usr/bin && \
    rm -f lsb_release && \
    ln -fs python2.7 python && \
    {% if distro_version in ["precise"] %}
    cd /usr && \
    ln -fs ../../include/python2.7 local/include/python2.7 && \
    {% endif %}
    apt-get clean
{% elif distro in ["alpine"] %}
# openssh is necessary until this is fixed: https://github.com/ansible/ansible/issues/24705
RUN apk add --no-cache -U python-dev make git curl rsync libffi libffi-dev openssl openssl-dev gcc musl-dev tar openssh
{% endif %}

RUN (curl https://bootstrap.pypa.io/get-pip.py | python - --no-cache-dir ) && \
    mkdir -p /etc/ansible/roles /_ansible/src && \
    (curl https://get.docker.com/builds/Linux/x86_64/docker-{{ docker_version }}.tgz \
       | tar -zxC /usr/local/bin/ --strip-components=1 docker/docker )

# The COPY here will break cache if the version of Ansible Container changed
COPY /container-src /_ansible/container
RUN cd /_ansible && \
    pip install --no-cache-dir -r container/conductor-build/conductor-requirements.txt && \
    PYTHONPATH=. LC_ALL="en_US.UTF-8" python container/conductor-build/setup.py develop -v -N && \
    ansible-galaxy install -p /etc/ansible/roles -r container/conductor-build/conductor-requirements.yml

{% if distro in ["centos"] %}
# Removing python-chardet removed yum-utils, and now that we're done pip-installing things,
# we'll put it back.
#RUN yum install -y yum-utils && \
#    yum clean all
{% endif %}



