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

# Odoo 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 \
        python-dev python-setuptools python-pip nodejs npm

# Handle Node PATH
RUN ln -s /usr/bin/nodejs /usr/bin/node
# Install NPM dependencies
RUN npm install -g less@2 less-plugin-clean-css

# PostgreSQL 9.5
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main 9.5" \
      > /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-9.5

# WKHTMLTOPDF and fonts
ENV WKNAME wkhtmltox-0.12.1.2_linux-jessie-amd64.deb
RUN apt-get install -y --no-install-recommends \
      libfontenc1 libxfont1 x11-common xfonts-75dpi xfonts-base \
      xfonts-encodings xfonts-utils \
      && curl -LO http://nightly.odoo.com/extra/$WKNAME \
      && echo "40e8b906de658a2221b15e4e8cd82565a47d7ee8 $WKNAME" | sha1sum -c - \
      && dpkg --force-depends -i $WKNAME \
      && apt-get -y install -f --no-install-recommends

# Packages cleanup
RUN apt-get purge -y --auto-remove \
      && apt-get clean \
      && rm ${WKNAME}

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

# Install OCB 8.0 latest
ENV ODOO_BRANCH 9.0
WORKDIR /opt/odoo
# Default user : odoo
USER odoo
RUN mkdir pipcache data backups extra-addons custom-addons
RUN git clone -b ${ODOO_BRANCH} --depth 1 https://github.com/OCA/OCB.git
RUN pip install --user -U pip
RUN pip install --user -r OCB/requirements.txt

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