## Building gmri/nasa-facet-hycom-r

## Base image https://hub.docker.com/u/rocker/
## includes tidyverse andinstalling unrar system library
FROM rocker/r-ver:3.5

## get unrar lib for debian
## unrar works for *some* of the iccat rar archives
## better to use unar, the CLI version of Mac's unarchiver
RUN echo "deb http://deb.debian.org/debian stretch stretch-updates main contrib non-free" | tee /etc/apt/sources.list \
  && echo "deb http://security.debian.org/debian-security stretch/updates main contrib non-free" | tee -a /etc/apt/sources.list \
  && apt-get -y update \
  && apt-get -y install curl \
  && apt-get -y install libudunits2-* \
  && apt-get -y install udunits-* \
  && apt-get -y install libnetcdf-*

# create an R user
ENV USER rstudio

# cd but for Docker
WORKDIR /home/$USER/

## Install extra R packages using requirements.R
## Copy requirements.R to container directory /tmp
COPY ./pipelines/hycom/R/DockerConfig/requirements.R /home/$USER/requirements.R
## install required R packages on container
RUN Rscript /home/$USER/requirements.R

## custom R functions for this step of pipeline
COPY ./pipelines/hycom/R/ /home/$USER/R/
COPY ./R/ /home/$USER/R/functions/

#RUN ls -lR /home/$USER/R/

## make scripts executable
RUN chmod +x  /home/$USER/R/*.r

# Default command to run.
# Can be overridden, but these lay out the expectations on how the script should be called.
CMD ["./R/iccat_download.r", "/pfs/iccat_species/", "/pfs/out/"]