Because R packages all have to install from source and do a lot of compilation, I find testing and deploying my internal package in Docker is sometimes really slow. A few months ago I realized I can just make a "base" R Docker container that does all of the work of installing the common dependencies that our internal packages have. Then the packages themselves can pull from an existing built container and just have to copy code over.
This was working great, but I noticed in the last few weeks that installing my package within the Docker container is reinstalling R packages.
I'm hoping for some help here-- it makes testing and deploying go from <5 mins to > 20 mins. I am wondering if it's possible that because docker runs as root that the packages are being installed in the wrong user or something?
Here's some sample code to get a feel for what's happening. The Dockerfile of the base container:
FROM rocker/r-ver:3.4.1
ARG BUILD_DATE
ENV BUILD_DATE=2017-07-15
ENV MRAN https://mran.microsoft.com/snapshot/$BUILD_DATE
RUN apt-get update -qq && apt-get -y --no-install-recommends install \
libxml2-dev \
libcairo2-dev \
libsqlite-dev \
libpq-dev \
libicu-dev \
libbz2-dev \
liblzma-dev \
default-jdk \
libssl-dev \
libcurl4-openssl-dev \
vim \
unixodbc \
unixodbc-dev \
odbc-postgresql \
&& R CMD javareconf \
&& . /etc/environment
RUN Rscript -e "install.packages(c('dplyr', 'tidyr', 'dbplyr', 'devtools', 'openxlsx', 'RJDBC', 'data.table', 'dtplyr', 'yaml', 'knitr', 'rmarkdown', 'ggplot2', 'data.tree', 'slackr', 'testthat', 'roxygen2', 'assertr', 'purrr', 'futile.logger', 'magrittr', 'odbc', 'feather'), repos = Sys.getenv('MRAN'), Ncpus = 2)"
Then to run my tests I run a script in my container:
Rscript -e "library(devtools);library(methods);library(testthat);install();library($MY_PACKAGE);test_package('$MY_PACKAGE', reporter = 'Summary')
The install step here re-installs all of the dependencies. I also cannot exclude the install step, even though creating the actual docker container should have installed my package:
FROM allovue/rbase:development
RUN mkdir -p /var/$MY_PACKAGE
# Copy my code to the docker container
ADD . /var/$MY_PACKAGE
# Build and install package
RUN cd /var/$MY_PACKAGE && \
R CMD build . --no-build-vignettes && \
R CMD INSTALL *tar.gz
WORKDIR /var/$MY_PACKAGE
Any ideas?