FROM debian:buster-slim
LABEL maintainer="Yaltik - Fabien Bourgeois <fabien@yaltik.com>"

# Generate locale C.UTF-8 for postgres and general locale data
# 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

# Odoo dependencies from Debian APT repository

# RUN apt 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

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


# Install some deps, lessc and less-plugin-clean-css, and wkhtmltopdf
# WKHTMLTOPDF
# PostgreSQL-client
# Needed to build
# NPM rtlcss
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN apt-get update && apt-get install -y --no-install-recommends \
      ca-certificates curl dirmngr fonts-noto-cjk gnupg libssl-dev \
      node-less npm python3-num2words python3-pdfminer python3-pip \
      python3-phonenumbers python3-pyldap python3-qrcode python3-renderpm \
      python3-setuptools python3-slugify python3-vobject python3-watchdog \
      python3-xlrd python3-xlwt xz-utils && \
      curl -o wkhtmltox.deb -sSL https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb && \
      echo 'ea8277df4297afc507c61122f3c349af142f31e5 wkhtmltox.deb' | sha1sum -c - && \
      apt-get install -y --no-install-recommends ./wkhtmltox.deb && \
      echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' > /etc/apt/sources.list.d/pgdg.list && \
      GNUPGHOME="$(mktemp -d)" && export GNUPGHOME && \
      repokey='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8' && \
      gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "${repokey}" && \
      gpg --batch --armor --export "${repokey}" > /etc/apt/trusted.gpg.d/pgdg.gpg.asc && \
      gpgconf --kill all \ && rm -rf "$GNUPGHOME" && \
      apt-get update && \
      apt-get install --no-install-recommends -y libpq-dev postgresql-client-12 && \
      apt-get install -y --no-install-recommends build-essential git mercurial curl \
      python3-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev \
      libjpeg-dev libfreetype6-dev libssl-dev && \
      apt-get clean && rm -rf /var/lib/apt/lists/* wkhtmltox.deb && \
      npm install -g rtlcss@2.6.2

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

# Install OCB 14.0 latest
ENV ODOO_BRANCH 14.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 && \
      pip3 install --no-cache-dir --user -U pip==22.0.3 && \
      pip3 install --no-cache-dir --user -r OCB/requirements.txt && \
      pip3 install --no-cache-dir --user phonenumbers==8.12.44

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

# Post-install tasks
RUN touch odoo.conf
ENV ODOO_RC /opt/odoo/odoo.conf

# Odoo default ports
EXPOSE 8069 8071 8072

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

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