FROM debian:stretch
MAINTAINER Yaltik - Fabien Bourgeois <fabien@yaltik.com>

# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8

# Flectra dependencies from Debian APT repository
RUN apt-get update \
      && apt-get install -y --no-install-recommends \
        build-essential git mercurial curl \
        libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libjpeg-dev libpq-dev \
        libfreetype6-dev libssl1.0-dev \
        python3-dev python3-setuptools python3-pip \
        nodejs node-less xz-utils \
        postgresql-client-9.6

# Handle Node PATH
RUN ln -s /usr/bin/nodejs /usr/bin/node

# WKHTMLTOPDF and fonts
RUN curl -o wkhtmltox.deb -SL https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb \
      && echo '7e35a63f9db14f93ec7feeb0fce76b30c08f2057 wkhtmltox.deb' | sha1sum -c \
      && dpkg --force-depends -i wkhtmltox.deb \
      && apt-get -y --fix-broken install

# Packages cleanup
RUN apt-get purge -y --auto-remove \
      && apt-get clean \
      && rm -r ./wkhtmltox*

# Create flectra user
RUN useradd flectra -md /opt/flectra

# Install Flectra 1.0 latest
ENV FLECTRA_BRANCH yaltik_1.0
WORKDIR /opt/flectra
# Default user
USER flectra
RUN mkdir pipcache data backups extra-addons custom-addons
RUN git clone -b ${FLECTRA_BRANCH} --depth 1 https://git.yaltik.net/Yaltik/flectra.git
RUN pip3 install --user -U pip
RUN .local/bin/pip3 install --user -r flectra/requirements.txt

# Launch scripts
COPY ./launch.sh ./
COPY ./genconf.sh ./

# Post-install tasks
RUN touch flectra.conf

# Flectra default ports
EXPOSE 7072 7073

# Volumes : data dir for filestore and addons
VOLUME /opt/flectra/data

CMD [ "bash", "launch.sh" ]
