FROM debian:buster-slim
# todo utiliser image python3 ?

## install dependencies
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y sudo vim nano locales unzip && \
    apt-get install -y python-dev python-pip libpq-dev libgeos-dev python3 python3-pip unzip && \
    apt-get install -y python3-venv git npm wget postgresql-client && \
    localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8 && \
    apt-get clean

## set envs
ENV LANG fr_FR.utf8
ENV TERM xterm

RUN adduser --uid 1000 --gecos ""  --disabled-password appuser
RUN usermod -aG sudo appuser
RUN echo "appuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

COPY vendor/GeoNature-citizen/ /home/appuser/citizen/

# patches
#COPY patches/back/requirements.txt /home/appuser/citizen/backend/requirements.txt #use the requirements from the GnC repo
COPY patches/back/default_config.toml /home/appuser/citizen/config/default_config.toml
COPY patches/settings.ini /home/appuser/citizen/config/settings.ini
COPY patches/back/wsgi.py /home/appuser/citizen/backend/wsgi.py
COPY patches/back/server.py /home/appuser/citizen/backend/server.py


RUN chown -R appuser:appuser /home/appuser
USER appuser

WORKDIR /home/appuser/citizen/backend/

ENV VIRTUAL_ENV=/home/appuser/citizen/backend/venv2/
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# RUN /bin/bash create_sys_dir.sh


# Install dependencies:
RUN pip install -r requirements.txt

EXPOSE 5002

CMD ["python", "server.py ", "runserver"]