## Image to build from sources

FROM python:3.7.10-slim-buster
MAINTAINER XiVO Team "dev@avencall.com"

ENV DEBIAN_FRONTEND noninteractive
ENV HOME /root

# Buster is now moved under archive.debian.org
RUN sed -i \
    -e 's/deb.debian.org/archive.debian.org/' \
    -e '/security.debian.org/d' \
    /etc/apt/sources.list

# Add dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends --auto-remove \
    git \
    python3-twisted \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Install xivo-confgend
WORKDIR /usr/src/confgend

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
RUN python setup.py install

RUN touch /var/log/xivo-confgend.log
RUN mkdir /var/lib/xivo-confgend
RUN cp -a boot.sh /var/lib/xivo-confgend/
WORKDIR /root

# Clean source dir
RUN rm -rf /usr/src/confgend

# Configure environment
ENV PYTHONPATH=/usr/local/lib/python3.7/site-packages

# Version
ARG TARGET_VERSION
LABEL version=${TARGET_VERSION}

EXPOSE 8669
CMD ["/var/lib/xivo-confgend/boot.sh"]
