dockerfiler
dockerfiler copied to clipboard
Build support for renv
Related issues : https://github.com/ThinkR-open/golem/issues/656
As said here: https://github.com/ThinkR-open/golem/issues/282#issuecomment-891118964
A new test today with a combination of {renv} and Docker cache requires:
- a .dockerignore with renv and .Rprofile ignored as suggested by jcpsantiago :
.RData
.Rhistory
.git
.gitignore
manifest.json
rsconnect/
Rproj.user
.Rprofile
renv/
- A Dockerfile like this that forces {renv} to use the classical path to install dependencies with
renv::restore(library = .libPaths())
:- Remember to create the dockerfile when you are in your package, with
renv::status()
up-to-date, so that currently installed versions are the same as in "renv.lock" - Note that sub-dependencies probably still don't have the correct version and will be re-installed by
renv::restore()
- Note also that when you change some code in your project, then
renv::restore()
will be called again as it appears afterWORKDIR
- Remember to create the dockerfile when you are in your package, with
FROM rocker/geospatial:4.0.1
RUN apt-get update && apt-get install -y gdal-bin git-core libcairo2-dev libcurl4-openssl-dev libgdal-dev libgeos-dev libgeos++-dev libgit2-dev libicu-dev libpng-dev libpq-dev libproj-dev libssl-dev libudunits2-dev libxml2-dev make pandoc pandoc-citeproc zlib1g-dev && rm -rf /var/lib/apt/lists/*
RUN echo "options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/__linux__/focal/latest'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site
RUN echo "options(warn = 2);" >> $R_HOME/etc/Rprofile.site
# Dependencies as extracted from DESCRIPTION file as usual
RUN Rscript -e 'install.packages("remotes")'
RUN Rscript -e 'remotes::install_version("stringr",upgrade="never", version = "1.4.0")'
RUN Rscript -e 'remotes::install_version("glue",upgrade="never", version = "1.4.2")'
RUN Rscript -e 'remotes::install_version("magrittr",upgrade="never", version = "2.0.1")'
RUN Rscript -e 'remotes::install_version("future",upgrade="never", version = "1.21.0")'
RUN Rscript -e 'remotes::install_version("cartography",upgrade="never", version = "2.4.2")'
RUN Rscript -e 'remotes::install_github("Thinkr-open/golem@aaae5c8788802a7b4aef4df23691902a286dd964")'
# renv part
RUN Rscript -e 'remotes::install_github("rstudio/renv")'
RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
# RUN Rscript -e 'source("renv/activate.R")'
# Still need to restore in case sub-dependencies versions are not good
RUN Rscript -e 'renv::restore(library = .libPaths())'
RUN Rscript -e 'remotes::install_local(upgrade = FALSE)'
RUN rm -rf /build_zone
# Remove option to warn and stop
# RUN head -n -1 $R_HOME/etc/Rprofile.site
RUN echo "options(warn = -1);" >> $R_HOME/etc/Rprofile.site
EXPOSE 3838
CMD ["R", "-e", "options('shiny.port'=3838,shiny.host='0.0.0.0');mygolem::run_app()"]
Note: there is a WIP here https://github.com/ColinFay/dockerfiler/pull/22
That should be good now.
Worth noting that this might be ready to be closed