from ubuntu:xenial

LABEL authors="Gennadiy Dubina, Alfonso Tierno, Gerardo Garcia"

RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install software-properties-common && \
    DEBIAN_FRONTEND=noninteractive add-apt-repository -y cloud-archive:queens && \
    apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install git python python-pip && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install wget tox && \
    DEBIAN_FRONTEND=noninteractive pip2 install pip==9.0.3 && \
    DEBIAN_FRONTEND=noninteractive pip2 install -U progressbar pyvmomi pyvcloud==19.1.1 && \
    DEBIAN_FRONTEND=noninteractive pip2 install -U fog05rest && \
    DEBIAN_FRONTEND=noninteractive pip2 install -U azure && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install python-requests && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install python-novaclient python-keystoneclient python-glanceclient python-cinderclient python-neutronclient python-networking-l2gw && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install python-cffi libmysqlclient-dev libssl-dev libffi-dev python-mysqldb && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install python-openstacksdk python-openstackclient && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install python-networkx && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install genisoimage && \
    DEBIAN_FRONTEND=noninteractive pip2 install untangle && \
    DEBIAN_FRONTEND=noninteractive pip2 install pyone && \
    DEBIAN_FRONTEND=noninteractive pip2 install -e git+https://github.com/python-oca/python-oca#egg=oca && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-client

COPY . /root/RO

RUN /root/RO/scripts/install-osm-im.sh --develop && \
    /root/RO/scripts/install-lib-osm-openvim.sh --develop && \
    make -C /root/RO prepare && \
    mkdir -p /var/log/osm && \
    pip2 install -e /root/RO/build && \
    rm -rf /root/.cache && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

VOLUME /var/log/osm

EXPOSE 9090

# Two mysql databases are needed (DB and DB_OVIM). Can be hosted on same or separated containers
# These ENV must be provided
# RO_DB_HOST: host of the main
# RO_DB_OVIM_HOST: ...        if empty RO_DB_HOST is assumed
# RO_DB_ROOT_PASSWORD: this has to be provided first time for creating database. It will create and init only if empty!
# RO_DB_OVIM_ROOT_PASSWORD: ...  if empty RO_DB_ROOT_PASSWORD is assumed
# RO_DB_USER:    default value 'mano'
# RO_DB_OVIM_USER:       default value 'mano'
# RO_DB_PASSWORD:        default value 'manopw'
# RO_DB_OVIM_PASSWORD:        default value 'manopw'
# RO_DB_PORT:             default value '3306'
# RO_DB_OVIM_PORT:        default value '3306'
# RO_DB_NAME:             default value 'mano_db'
# RO_DB_OVIM_NAME:        default value 'mano_vim_db'
# RO_LOG_FILE:            default log to stderr if not defined

ENV RO_DB_HOST="" \
    RO_DB_OVIM_HOST="" \
    RO_DB_ROOT_PASSWORD="" \
    RO_DB_OVIM_ROOT_PASSWORD="" \
    RO_DB_USER=mano \
    RO_DB_OVIM_USER=mano \
    RO_DB_PASSWORD=manopw \
    RO_DB_OVIM_PASSWORD=manopw \
    RO_DB_PORT=3306 \
    RO_DB_OVIM_PORT=3306 \
    RO_DB_NAME=mano_db \
    RO_DB_OVIM_NAME=mano_vim_db \
    OPENMANO_TENANT=osm \
    RO_LOG_LEVEL=DEBUG

CMD RO-start.sh

# HEALTHCHECK --start-period=30s --interval=10s --timeout=5s --retries=12 \
#  CMD curl --silent --fail localhost:9090/openmano/tenants || exit 1
