FROM debian:bullseye-slim
LABEL maintainer="Odoo S.A. <info@odoo.com>"
LABEL maintainer="Yaltik - Fabien Bourgeois <fabien@yaltik.com>"

SHELL ["/bin/bash", "-xo", "pipefail", "-c"]

# Generate locale C.UTF-8 for postgres and general locale data
ENV LANG C.UTF-8

# Install some deps, lessc and less-plugin-clean-css, and wkhtmltopdf
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 \
        build-essential git mercurial curl \
        python3-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev \
        libjpeg-dev libfreetype6-dev libssl-dev \
    && 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 \
    && rm -rf /var/lib/apt/lists/* wkhtmltox.deb \
    && echo 'deb http://apt.postgresql.org/pub/repos/apt/ bullseye-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 postgresql-client libpq-dev \
    && apt-get clean && rm -f /etc/apt/sources.list.d/pgdg.list \
    && rm -rf /var/lib/apt/lists/* \
    && npm install -g rtlcss@4.0.0

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

# Install Odoo
ENV ODOO_BRANCH 16.0
WORKDIR /opt/odoo

# Set default user when running the container
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.3 && \
      pip3 install --no-cache-dir --user -r OCB/requirements.txt

# Launch scripts
COPY ./launch14.sh ./launch.sh
COPY ./genconf16.sh ./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" ]
