FROM debian:stretch
LABEL 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

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Odoo dependencies from Debian APT repository
# PostgreSQL 10.x
# Handle Node PATH
# WKHTMLTOPDF and fonts
RUN apt-get update && \
      apt-get install -y --no-install-recommends \
      python3-pip python3-pyldap python3-qrcode python3-renderpm \
      python3-setuptools python3-vobject python3-watchdog python3-dev \
      build-essential git mercurial curl \
      libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libjpeg-dev libpq-dev \
      libfreetype6-dev libssl1.0-dev \
      nodejs node-less xz-utils && \
      apt-get update && apt-get install -y --no-install-recommends gnupg && \
      echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" \
      > /etc/apt/sources.list.d/postgresql.list && \
      curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
      apt-get update && \
      apt-get install -y libpq-dev postgresql-client-10 && \
      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 && \
      apt-get clean && rm -rf /var/lib/apt/lists/* && rm -r ./wkhtmltox* && \
      ln -s /usr/bin/nodejs /usr/bin/node

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

# Install OCB 12.0 latest
ENV ODOO_BRANCH 12.0
WORKDIR /opt/odoo
# Default user : odoo
USER odoo
RUN mkdir pipcache data backups extra-addons custom-addons && \
      git clone -b ${ODOO_BRANCH} --depth 1 https://github.com/OCA/OCB.git && \
      echo 'export PATH="$PATH:$HOME/.local/bin/"' >> /opt/odoo/.profile && \
      pip3 install --user --no-cache-dir -U pip && \
      .local/bin/pip3 install --no-cache-dir --user -r OCB/requirements.txt && \
      .local/bin/pip3 install --no-cache-dir --user phonenumbers==8.12.44

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

# Post-install tasks
RUN touch odoo.conf

# Odoo default ports
EXPOSE 8069 8072

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

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