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

# Global dependencies
RUN apt-get update
RUN apt-get install -y sudo curl wget rlwrap
RUN apt-get install -y iputils-ping
RUN apt-get install -y git build-essential python-setuptools python-pip python-dev libffi-dev libssl-dev
RUN apt-get install -y redis-tools software-properties-common libxrender1 libxext6 xfonts-75dpi xfonts-base
RUN apt-get install -y libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev python-tk apt-transport-https libsasl2-dev libldap2-dev libtiff5-dev tcl8.6-dev tk8.6-dev
RUN apt-get install -y libmysqlclient-dev mariadb-client mariadb-common
RUN pip install --upgrade setuptools pip
# NodeJS
RUN curl -LO https://nodejs.org/dist/v6.11.3/node-v6.11.3-linux-x64.tar.xz && tar xJf node-v6.11.3-linux-x64.tar.xz && ln -s node-v6.11.3-linux.x64/bin/node /usr/bin/ && ln -s node-v6.11.3-linux.x64/bin/npm /usr/bin/
# WKHTMLTOPDF
RUN apt-get install -y wkhtmltopdf

# Environment variables
ENV FRAPPE_USER=frappe \
  MYSQL_PASSWORD=somethingToChange \
  ADMIN_PASSWORD=somethingToChange

# Create frappe user
RUN useradd $FRAPPE_USER -m
# RUN usermod -aG sudo $FRAPPE_USER
RUN echo "$FRAPPE_USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/frappe

# Install frappe
RUN git clone --depth 1 https://github.com/frappe/bench bench_repo
RUN pip install -e bench-repo
RUN curl -LO https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py
RUN python install.py --production --user $FRAPPE_USER --mysql-root-password $MYSQL_PASSWORD --admin-password $ADMIN_PASSWORD
# Supervidor production configuration
# COPY production.conf /etc/supervisor/conf.d/

WORKDIR /home/$FRAPPE_USER
USER frappe

# Cleanup (to move on production)
# RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/ /home/$FRAPPE_USER/.cache

WORKDIR /home/$FRAPPE_USER/frappe-bench
# Default ports
EXPOSE 80 25

# Volumes : data dir
VOLUME /opt/odoo/data

# CMD ["/usr/bin/supervisord","-n"]
