fix: fail if r package installation fails (#4994)

- Fail if the installation of a R package fails.
- Install the remotes package once during the image build, and not when we scan
  files at runtime.
- Reuse the default R library directory instead of moving it to /home/r-library
This commit is contained in:
Marco Ferrari 2023-12-21 20:52:57 +01:00 committed by GitHub
parent a2cf1807a7
commit 60983d395f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 10 deletions

View file

@ -219,8 +219,8 @@ RUN --mount=type=secret,id=GITHUB_TOKEN /install-glibc.sh && rm -rf /install-gli
################# #################
# Install Lintr # # Install Lintr #
################# #################
COPY scripts/install-lintr.sh / COPY scripts/install-lintr.sh scripts/install-r-package-or-fail.R /
RUN /install-lintr.sh && rm -rf /install-lintr.sh RUN /install-lintr.sh && rm -rf /install-lintr.sh /install-r-package-or-fail.R
################################# #################################
# Install luacheck and luarocks # # Install luacheck and luarocks #

View file

@ -479,7 +479,6 @@ function RunAdditionalInstalls() {
############################## ##############################
INSTALL_CMD=$( INSTALL_CMD=$(
cd "${WORKSPACE_PATH}" || exit 0 cd "${WORKSPACE_PATH}" || exit 0
R -e "install.packages('remotes', repos = 'https://cloud.r-project.org/')" 2>&1
R -e "remotes::install_local('.', dependencies=T)" 2>&1 R -e "remotes::install_local('.', dependencies=T)" 2>&1
) )

View file

@ -2,8 +2,4 @@
set -euo pipefail set -euo pipefail
mkdir -p /home/r-library Rscript --no-save /install-r-package-or-fail.R lintr purrr remotes
cp -r /usr/lib/R/library/ /home/r-library/
Rscript -e "install.packages(c('lintr','purrr'), repos = 'https://cloud.r-project.org/')"
R -e "install.packages(list.dirs('/home/r-library',recursive = FALSE), repos = NULL, type = 'source')"
mv /etc/R/* /usr/lib/R/etc/

View file

@ -0,0 +1,12 @@
#!/usr/bin/env Rscript
# Based on: https://stackoverflow.com/questions/26244530/how-do-i-make-install-packages-return-an-error-if-an-r-package-cannot-be-install
packages = commandArgs(trailingOnly=TRUE)
for (l in packages) {
install.packages(l, repos='https://cloud.r-project.org/');
if ( ! library(l, character.only=TRUE, logical.return=TRUE) ) {
quit(status=1, save='no')
}
}

View file

@ -402,7 +402,6 @@ control "super-linter-validate-directories" do
desc "Check that directories that Super-Linter needs are installed." desc "Check that directories that Super-Linter needs are installed."
dirs = [ dirs = [
"/home/r-library",
"/node_modules", "/node_modules",
"/action/lib", "/action/lib",
"/action/lib/functions", "/action/lib/functions",
@ -413,7 +412,6 @@ control "super-linter-validate-directories" do
# Removed linters from slim image # Removed linters from slim image
SLIM_IMAGE_REMOVED_DIRS=%w( SLIM_IMAGE_REMOVED_DIRS=%w(
/home/r-library
) )
dirs.each do |item| dirs.each do |item|