FROM docker-config-engine

COPY [ \
{% for deb in docker_snmp_sv2_debs.split(' ') -%}
    "debs/{{ deb }}",
{%- endfor %} \
    "/debs/"]

COPY python-wheels/sswsdk-*-py3-*.whl /python-wheels/
COPY python-wheels/asyncsnmp-*-py3-*.whl /python-wheels/

# enable -O for all Python calls
ENV PYTHONOPTIMIZE 1

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

# install supervisor
# install libsnmp30 dependencies
# install libpython3.6-dev dependencies
# install pip dependencies
# TODO: remove libpython3.6-dev, its and pip's dependencies if we can get pip3 directly
# install subagent
# clean up
RUN apt-get update && apt-get install -y supervisor \
            libperl5.20 libpci3 libwrap0 \
            libexpat1-dev \
            curl gcc && \
    dpkg -i \
{% for deb in docker_snmp_sv2_debs.split(' ') -%}
        debs/{{ deb }}{{' '}}
{%- endfor %} && \
    rm -rf /debs && \
    curl https://bootstrap.pypa.io/get-pip.py | python3.6 && \
    python3.6 -m pip install --no-cache-dir /python-wheels/*py3*.whl hiredis && \
    rm -rf /python-wheels && \
    python3.6 -m sonic_ax_impl install && \
    apt-get -y purge libpython3.6-dev libexpat1-dev curl gcc && \
    apt-get clean -y && apt-get autoclean -y && apt-get autoremove -y --purge && \
    find / | grep -E "__pycache__" | xargs rm -rf && \
    rm -rf ~/.cache

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY ["*.j2", "/usr/share/sonic/templates/"]
COPY ["config.sh", "/usr/bin/"]

## Although exposing ports is not need for host net mode, keep it for possible bridge mode
EXPOSE 161/udp 162/udp

ENTRYPOINT /usr/bin/config.sh && /usr/bin/supervisord