# xivo/xivo-dird-db (see Makefile)

ARG VERSION
FROM xivoxc/xivo-db:${VERSION}

MAINTAINER XiVO Team "dev@avencall.com"

RUN apt-get -yq update \
   && apt-get -yqq install \
      build-essential \
      python3-dev \
      libldap2-dev \
      libsasl2-dev \
   && apt-get -yq autoremove

# Ensure locale fr_FR.utf8 is present
# (installing build-essential (may) update locale package and removes the fr_FR which is only generated
# in the xivo-db container)
RUN localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8


#Insert data required for running integration tests
WORKDIR /usr/src/xivo-dird

# First copy requirements only to use pip cache if --no-cache-dir option is not used
COPY requirements.txt .

# Handle pep 668
RUN rm /usr/lib/python3.11/EXTERNALLY-MANAGED

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

COPY . /usr/src/xivo-dird

RUN sed '/db_uri/ s/localhost/:5432/' -i etc/xivo-dird/config.yml
RUN sed '/sqlalchemy.url/ s/localhost/:5432/' -i alembic.ini

RUN python3 setup.py install

COPY bin/xivo-dird /usr/bin/
COPY bin/xivo-dird-init-db /usr/bin/

COPY contribs/docker/zz-initdb.sh /docker-entrypoint-initdb.d/
# Dont redirect stdout in log for test
RUN sed '/exec \&>>/d' -i /usr/local/bin/docker-entrypoint.sh
