FROM debian:buster-slim

## 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/TaxHub/ /home/appuser/taxhub/

#patches
COPY patches/taxhub/config.py /home/appuser/taxhub/config.py
COPY patches/taxhub/server.py /home/appuser/taxhub/server.py
COPY patches/taxhub/install_db.sh /home/appuser/taxhub/install_db.sh
COPY patches/taxhub/settings.ini /home/appuser/taxhub/settings.ini


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

WORKDIR /home/appuser/taxhub/

ENV VIRTUAL_ENV=/home/appuser/taxhub/venv/
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

RUN cp static/app/constants.js.sample static/app/constants.js
RUN cd static && npm install

EXPOSE 5000

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