rstudio / packrat

Packrat is a dependency management system for R
http://rstudio.github.io/packrat/
401 stars 89 forks source link

binary package validation (via renv) #713

Closed aronatkins closed 1 year ago

aronatkins commented 1 year ago

Loads binary packages at install time, which traps some environment compatibility problems. The package is removed from the packrat library and never reaches the packrat cache.

Fixes #712

The following Dockerfile examples show failures occurring at restore-time; the "runtime" script.R is never executed.

This first example shows how an install-time package load can identify missing system dependencies.

Dockerfile.packrat identifying missing (jags) system dependencies ```dockerfile FROM rstudio/r-base:4.3-jammy AS base RUN apt-get update && apt-get -y install pkg-config ARG REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/jammy/latest RUN echo "options(repos = c(CRAN = '${REPOSITORY}'))" >> /opt/R/4.3.0/lib/R/etc/Rprofile.site RUN R -s -e "install.packages('remotes')" FROM base as setup ARG PACKRAT_REF="aron-renv-binary-package-validation" RUN R -s -e "remotes::install_github('rstudio/packrat', '${PACKRAT_REF}')" FROM setup AS installation RUN mkdir /content \ && echo "library(rjags)" > /content/script.R \ && echo "options(download.file.method = 'curl', download.file.extra = paste('-s -L -f -A ', shQuote(getOption('HTTPUserAgent'))))" > /content/.Rprofile WORKDIR /content ENV RENV_INSTALL_TEST_LOAD=True RUN R -s -e "packrat::init(enter = FALSE, infer.dependencies = FALSE)" # install by R of rjags into the packrat library.. RUN R -s -e "install.packages('rjags')" RUN R -s -e "packrat::snapshot()" RUN rm -rf packrat/lib* packrat/src # installation by packrat of rjags into the packrat library. RUN R -s -e "packrat::restore()" RUN R -s -f "script.R" ```
docker build --progress=plain --no-cache-filter=setup -f Dockerfile.packrat .
 > [installation 7/8] RUN R -s -e "packrat::restore()":
#15 8.501 Loading required package: coda
#15 8.501 Error: package or namespace load failed for ‘rjags’:
#15 8.501  .onLoad failed in loadNamespace() for 'rjags', details:
#15 8.501   call: dyn.load(file, DLLpath = DLLpath, ...)
#15 8.501   error: unable to load shared object '/content/packrat/lib/x86_64-pc-linux-gnu/4.3.0/rjags/libs/rjags.so':
#15 8.501   libjags.so.4: cannot open shared object file: No such file or directory
#15 8.501 Execution halted
#15 8.530 FAILED
#15 8.532 Error: error testing if 'rjags' can be loaded [error code 1]
#15 8.533 Execution halted

This second example shows how an install-time package load can identify incompatible base system libraries.

Dockerfile.packrat-crosswired showing incompatible base libraries ```dockerfile FROM rstudio/r-base:4.3-bionic AS base RUN apt-get update && apt-get -y install pkg-config ARG REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/bionic/latest RUN echo "options(repos = c(CRAN = '${REPOSITORY}'))" >> /opt/R/4.3.0/lib/R/etc/Rprofile.site RUN R -s -e "install.packages('remotes')" FROM base as setup ARG PACKRAT_REF="aron-renv-binary-package-validation" RUN R -s -e "remotes::install_github('rstudio/packrat', '${PACKRAT_REF}')" FROM setup AS installation RUN mkdir /content \ && echo "library(fastmap)" > /content/script.R \ && echo "options(download.file.method = 'curl', download.file.extra = paste('-s -L -f -A ', shQuote(getOption('HTTPUserAgent'))))" > /content/.Rprofile WORKDIR /content ENV RENV_INSTALL_TEST_LOAD=True RUN R -s -e "packrat::init(enter = FALSE, infer.dependencies = FALSE)" # install by R of fastmap into the packrat library.. RUN R -s -e "install.packages('fastmap')" RUN R -s -e "packrat::snapshot()" RUN rm -rf packrat/lib* packrat/src # installation by packrat of fastmap into the packrat library using a BAD repository ARG JAMMY_REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/jammy/latest RUN R -s -e "packrat::set_lockfile_metadata(repos = c(CRAN = '${JAMMY_REPOSITORY}'))" RUN R -s -e "packrat::restore()" RUN R -s -f "script.R" ```
docker build --progress=plain --no-cache-filter=setup -f Dockerfile.packrat-crosswired .
 > [installation 8/9] RUN R -s -e "packrat::restore()":
#17 2.259 /opt/R/4.3.0/lib/R/bin/R --vanilla -s -f '/tmp/Rtmpq1ZfQc/renv-install-75dce439a'
#17 2.259 ================================================================================
#17 2.259
#17 2.259 Error: package or namespace load failed for ‘fastmap’ in dyn.load(file, DLLpath = DLLpath, ...):
#17 2.259  unable to load shared object '/content/packrat/lib/x86_64-pc-linux-gnu/4.3.0/fastmap/libs/fastmap.so':
#17 2.259   /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /content/packrat/lib/x86_64-pc-linux-gnu/4.3.0/fastmap/libs/fastmap.so)
#17 2.259 Execution halted
#17 2.303 FAILED
#17 2.305 Error: error testing if 'fastmap' can be loaded [error code 1]
#17 2.305 Execution halted