##################################################
# Dockerfile for project_quickstart 
# https://github.com/AntonioJBT/project_quickstart
##################################################

############
# Base image
############

#FROM continuumio/miniconda3
# It runs on Debian GNU/Linux 8; use e.g. uname -a ; cat /etc/issue.net

# FROM python:3-onbuild 
# FROM ubuntu:17.04
#FROM jfloff/alpine-python

# Or simply run:
# docker run --rm -ti continuumio/miniconda3
# docker run --rm -ti ubuntu

FROM frolvlad/alpine-miniconda3
# https://github.com/frol/docker-alpine-miniconda3
# https://hub.docker.com/r/frolvlad/alpine-miniconda3/


#########
# Contact
#########
MAINTAINER Antonio Berlanga-Taylor <a.berlanga@imperial.ac.uk>


#########################
# Update/install packages
#########################

# Install system dependencies
# If running on Debian and anaconda/miniconda image, use apt-get:
# apt-get update && apt-get upgrade --quiet --install -y apt-utils \
RUN apk update && apk upgrade && apk add \ 
    gcc \
    g++ \
    tzdata \
    wget \
    bzip2 \
    unzip \
    sudo \
    gcc \
    bash \
    make

# Get libraries for matplotlib:
RUN apk add libx11 \
            libxext \
            libsm \
            libxrender
            

# Get plotting libraries:
RUN apk add inkscape \
            graphviz \
            cairo \
            cairo-dev \
            cairo-tools \
            cairo-doc \
            cairo-gobject

# Get dependencies:
#RUN apk add \

# Additional packages:

#########################
# Install conda
#########################

# Miniconda:
#RUN cd /usr/bin \
#    && wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh \
#    && bash Miniconda3-latest-Linux-x86_64.sh -b -p /usr/local/miniconda \
#    && export PATH="/usr/local/miniconda/bin:$PATH"

# Add conda channels:
RUN conda config --add channels r \
    && conda config --add channels defaults \
    && conda config --add channels conda-forge \
    && conda config --add channels bioconda

# Note that there are dependency issues, specially rpy2, with clashes between conda-forge
# and default r (r-base), see here for icu 54 vs 56:
#https://github.com/conda-forge/conda-forge.github.io/issues/234
# but updates, new recipes, etc. changed things. 
# Solution was to update icu, which switches it to conda-forge icu58:
#RUN conda install -y icu

# Update conda:
RUN conda update -y conda

# Create a python 3.5 environment:
#RUN conda create -y -n py35 python=3.5

# Environments can't easily be sourced from a Dockerfile
# Mixing RUN with source errors, use instead this form of RUN:
# See:
# https://stackoverflow.com/questions/20635472/using-the-run-instruction-in-a-dockerfile-with-source-does-not-work
# https://docs.docker.com/engine/reference/builder/#run
# https://stackoverflow.com/questions/20635472/using-the-run-instruction-in-a-dockerfile-with-source-does-not-work/45087082#45087082
# Install everything in the virtual environment:
# Several cgat dependecies fail with pip so run with conda instead:
#RUN /bin/bash -c 'source activate py35 ; \
#    conda install -y git ; \
#    source deactivate'

RUN conda install -y git ; \
    pip install --upgrade pip cython numpy ; \
    pip install pysam ; \
    pip install pandas ; \
    pip install ruffus ; \
    conda install sphinx ; \
    pip install sphinxcontrib-bibtex ; \
    conda install -y -c r r=3.3 ; \
    conda install -y rpy2 ; \
    conda install -y readline ; \
    conda install -y r-docopt ; \
    conda install -y r-data.table ; \
    R --vanilla -e 'source("https://bioconductor.org/biocLite.R") ; install.packages("stargazer", repos = "http://cran.us.r-project.org") ; library("stargazer")' ; \
    conda install -y r-ggplot2 ; \
    conda install -y r-gdtools ; \
    R --vanilla -e 'source("https://bioconductor.org/biocLite.R") ; install.packages("svglite", repos = "http://cran.us.r-project.org") ; library("svglite")' ; \
    wget --no-check-certificate https://raw.githubusercontent.com/CGATOxford/cgat/master/requires.txt ; \
    cat requires.txt | grep -v "#" | xargs -n 1 pip install ; \
    conda install -y alignlib-lite ; \
    conda install -y bedtools ; \
    conda install -y pybedtools ; \
    conda install -y -c bioconda ucsc-wigtobigwig ; \
    conda install -y icu ; \
    pip install git+git://github.com/AntonioJBT/CGATPipeline_core.git ; \
    pip install git+git://github.com/AntonioJBT/project_quickstart.git ; \
    pip install cgat 

############################
# Default action to start in
############################
# Only one CMD is read (if several only the last one is executed)
#ENTRYPOINT ['/xxx']
#CMD echo "Hello world"
#CMD project_quickstart.py
#CMD ["/bin/bash"]
CMD ["/bin/bash"]

# To build run as:
#docker build --no-cache=true -t antoniojbt/pipe_tests_alpine .

# To run e.g.:
# docker run --rm -ti antoniojbt/pipe_tests

# If mounting a volume do e.g.:
# docker run -v /host/directory:/container/directory --rm -ti antoniojbt/pipe_tests
# docker run -v ~/Documents/github.dir/docker_tests.dir:/home/ --rm -ti antoniojbt/pipe_tests_alpine


# Create a shared folder between docker container and host
#VOLUME ["/shared/data"]
