FROM ubuntu:16.04
MAINTAINER Yaltik - Fabien Bourgeois <fabien@yaltik.com>

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

# Global dependencies
RUN apt-get update
RUN apt-get install -y sudo curl wget
RUN apt-get install -y git build-essential python-setuptools python-pip python-dev libffi-dev libssl-dev
RUN apt-get install -y python-minimal build-essential python-setuptools
RUN pip install --upgrade setuptools pip

# 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
WORKDIR /home/$FRAPPE_USER

# Ubuntu package install
RUN apt-get install -y build-essential redis-server software-properties-common libxrender1 libxext6 xfonts-75dpi xfonts-base 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

# NodeJS external repository
RUN echo "deb [arch=amd64,i386] https://deb.nodesource.com/node_6.x xenial main" \
      > /etc/apt/sources.list.d/nodesource.list \
      && curl 'https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280' | apt-key add -
RUN apt-get update && apt-get install -y nodejs

# WKHTMLTOPDF
RUN curl -L 'https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz' > /tmp/wkhtmltox.tar.xz
RUN cd /tmp/ && tar Jxf wkhtmltox.tar.xz \
      && cp /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf \
      && chmod +x /usr/local/bin/wkhtmltopdf

# MariaDb
RUN echo "deb [arch=amd64,i386] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.1/ubuntu xenial main" \
      > /etc/apt/sources.list.d/mariadb.list \
      && curl 'https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0xF1656F24C74CD1D8' | apt-key add -
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update \
      && apt-get install -y mariadb-server mariadb-client mariadb-common libmariadbclient-dev
RUN pip install mysql-python==1.2.5
COPY simple_mariadb_config.cnf /etc/mysql/conf.d/frappe.cnf
RUN mysqladmin -u root password $MYSQL_PASSWORD

# Install frappe
# RUN curl -LO https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py

# Volumes : data dir
VOLUME /home/$FRAPPE_USER/
