From e472c06ad0b7cccafc87999fc4ba926fefed339a Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Thu, 23 Feb 2023 20:08:46 +0100 Subject: [PATCH 1/3] Fix #67 no tests --- DESCRIPTION | 2 +- R/installation.R | 74 +++++++++++++++++++++++---------- inst/compile_r.sh | 5 ++- man/dockerize.Rd | 8 +++- tests/testthat/test_dockerize.R | 4 +- 5 files changed, 65 insertions(+), 28 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2c5153f..3752620 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rang Title: Reconstructing Reproducible R Computational Environments with Ease -Version: 0.1.1 +Version: 0.1.2 Authors@R: c(person("Chung-hong", "Chan", , "chainsawtiney@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6232-7530")), diff --git a/R/installation.R b/R/installation.R index 5512fc6..cb885b1 100644 --- a/R/installation.R +++ b/R/installation.R @@ -99,12 +99,16 @@ .group_sysreqs <- function(rang) { must_do_cmd <- "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config" if (length(rang$sysreqs) == 0) { + must_do_cmd <- paste(must_do_cmd, "libcurl4-openssl-dev") return(must_do_cmd) } if (isFALSE(.is_ppa_in_sysreqs(rang))) { cmds <- rang$sysreqs prefix <- "" cmd <- .group_apt_cmds(cmds, fix_libgit2 = TRUE) + if (!grepl("libcurl4-gnutls-dev", cmd)) { + must_do_cmd <- paste(must_do_cmd, "libcurl4-openssl-dev") + } } else { cmds <- setdiff(rang$sysreqs, c("apt-get install -y software-properties-common", "apt-get update")) ppa_lines <- c("apt-get install -y software-properties-common", @@ -249,7 +253,7 @@ dockerfile_content[(rang_line + 1):length(dockerfile_content)]) } -.generate_pre310_dockerfile_content <- function(r_version, lib, sysreqs_cmd, cache, debian_version = "lenny") { +.generate_debian_eol_dockerfile_content<- function(r_version, lib, sysreqs_cmd, cache, debian_version = "lenny") { dockerfile_content <- c( paste0("FROM debian/eol:", debian_version), "ENV TZ UTC", @@ -268,6 +272,23 @@ return(dockerfile_content) } +.generate_rocker_dockerfile_content <- function(r_version, lib, sysreqs_cmd, cache, image) { + dockerfile_content <- c("", "", "COPY rang.R ./rang.R", "RUN Rscript rang.R", "CMD [\"R\"]") + if (!is.na(lib)) { + dockerfile_content[4] <- paste0("RUN mkdir ", lib, " && Rscript rang.R") + } + dockerfile_content[1] <- paste0("FROM rocker/", image, ":", r_version) + dockerfile_content[2] <- paste("RUN", sysreqs_cmd) + if (image == "rstudio") { + dockerfile_content[5] <- "EXPOSE 8787" + dockerfile_content[6] <- "CMD [\"/init\"]" + } + if (isTRUE(cache)) { + dockerfile_content <- .insert_cache_dir(dockerfile_content) + } + return(dockerfile_content) +} + .generate_docker_readme <- function(output_dir,image){ file.create(file.path(output_dir,"README")) con <- file(file.path(output_dir,"README"), open="w") @@ -337,10 +358,9 @@ export_rang <- function(rang, path, rang_as_comment = TRUE, verbose = TRUE, lib cat(paste0("lib <- \"", as.character(lib), "\"\n"), file = con) } cat(paste0("cran_mirror <- \"", cran_mirror, "\"\n"), file = con) - if(!is.null(rang$bioc_version)){ + if(!is.null(rang$bioc_version)) { cat(paste0("bioc_mirror <- \"", "https://bioconductor.org/packages/",rang$bioc_version,"/", "\"\n"), file = con) } - writeLines(readLines(system.file("footer.R", package = "rang")), con = con) if (isTRUE(rang_as_comment)) { .write_rang_as_comment(rang = rang, con = con, path = path, verbose = verbose, @@ -360,6 +380,8 @@ export_rang <- function(rang, path, rang_as_comment = TRUE, verbose = TRUE, lib #' @param image character, which versioned Rocker image to use. Can only be "r-ver", "rstudio", "tidyverse", "verse", "geospatial" #' This applies only to R version <= 3.1 #' @param cache logical, whether to cache the packages now. Please note that the system requirements are not cached. For query with non-CRAN packages, this option is strongly recommended. For R version < 3.1, this must be TRUE if there is any non-CRAN packages. +#' @param no_rocker logical, whether to skip using Rocker images even when an appropriate version is available. Please keep this as `TRUE` unless you know what you are doing +#' @param debian_version, when Rocker images are not used, which EOL version of Debian to use. Can only be "lenny", "etch", "squeeze", "wheezy", "jessie", "stretch". Please keep this as default "lenny" unless you know what you are doing #' @param ... arguments to be passed to `dockerize` #' @return `output_dir`, invisibly #' @inheritParams export_rang @@ -380,7 +402,9 @@ export_rang <- function(rang, path, rang_as_comment = TRUE, verbose = TRUE, lib dockerize <- function(rang, output_dir, materials_dir = NULL, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), rang_as_comment = TRUE, cache = FALSE, verbose = TRUE, lib = NA, cran_mirror = "https://cran.r-project.org/", check_cran_mirror = TRUE, - bioc_mirror = "https://bioconductor.org/packages/") { + bioc_mirror = "https://bioconductor.org/packages/", + no_rocker = FALSE, + debian_version = c("lenny", "etch", "squeeze", "wheezy", "jessie", "stretch")) { if (missing(output_dir)) { stop("You must provide `output_dir`.", call. = FALSE) } @@ -401,6 +425,7 @@ dockerize <- function(rang, output_dir, materials_dir = NULL, image = c("r-ver", stop("Non-CRAN packages must be cached for this R version: ", rang$r_version, ". Please set `cache` = TRUE.", call. = FALSE) } image <- match.arg(image) + debian_version <- match.arg(debian_version) sysreqs_cmd <- .group_sysreqs(rang) if (!dir.exists(output_dir)) { dir.create(output_dir) @@ -412,26 +437,31 @@ dockerize <- function(rang, output_dir, materials_dir = NULL, image = c("r-ver", if (isTRUE(cache)) { .cache_pkgs(rang, output_dir, cran_mirror, bioc_mirror, verbose) } - if (utils::compareVersion(rang$r_version, "3.1") == -1) { + if (utils::compareVersion(rang$r_version, "3.1") == -1 || isTRUE(no_rocker)) { file.copy(system.file("compile_r.sh", package = "rang"), file.path(output_dir, "compile_r.sh"), overwrite = TRUE) - dockerfile_content <- .generate_pre310_dockerfile_content(r_version = rang$r_version, - sysreqs_cmd = sysreqs_cmd, lib = lib, - cache = cache) + + dockerfile_content <- .generate_debian_eol_dockerfile_content(r_version = rang$r_version, + sysreqs_cmd = sysreqs_cmd, lib = lib, + cache = cache, + debian_version = debian_version) } else { - dockerfile_content <- c("", "", "COPY rang.R ./rang.R", "RUN Rscript rang.R", "CMD [\"R\"]") - if (!is.na(lib)) { - dockerfile_content[4] <- paste0("RUN mkdir ", lib, " && Rscript rang.R") - } - dockerfile_content[1] <- paste0("FROM rocker/", image, ":", rang$r_version) - dockerfile_content[2] <- paste("RUN", sysreqs_cmd) - if (image == "rstudio") { - dockerfile_content[5] <- "EXPOSE 8787" - dockerfile_content[6] <- "CMD [\"/init\"]" - } - if (isTRUE(cache)) { - dockerfile_content <- .insert_cache_dir(dockerfile_content) - } + dockerfile_content <- .generate_rocker_dockerfile_content(r_version = rang$r_version, + sysreqs_cmd = sysreqs_cmd, lib = lib, + cache = cache, image = image) + ## dockerfile_content <- c("", "", "COPY rang.R ./rang.R", "RUN Rscript rang.R", "CMD [\"R\"]") + ## if (!is.na(lib)) { + ## dockerfile_content[4] <- paste0("RUN mkdir ", lib, " && Rscript rang.R") + ## } + ## dockerfile_content[1] <- paste0("FROM rocker/", image, ":", rang$r_version) + ## dockerfile_content[2] <- paste("RUN", sysreqs_cmd) + ## if (image == "rstudio") { + ## dockerfile_content[5] <- "EXPOSE 8787" + ## dockerfile_content[6] <- "CMD [\"/init\"]" + ## } + ## if (isTRUE(cache)) { + ## dockerfile_content <- .insert_cache_dir(dockerfile_content) + ## } } if (!(is.null(materials_dir))) { materials_subdir_in_output_dir <- file.path(output_dir, "materials") @@ -444,9 +474,7 @@ dockerize <- function(rang, output_dir, materials_dir = NULL, image = c("r-ver", dockerfile_content <- .insert_materials_dir(dockerfile_content) } writeLines(dockerfile_content, file.path(output_dir, "Dockerfile")) - .generate_docker_readme(output_dir = output_dir,image = image) - invisible(output_dir) } diff --git a/inst/compile_r.sh b/inst/compile_r.sh index 3679683..afb9eca 100644 --- a/inst/compile_r.sh +++ b/inst/compile_r.sh @@ -4,9 +4,12 @@ if echo "$1" | grep -Eq '^1' ; then elif echo "$1" | grep -Eq '^2' ; then DOWNLOAD_DIR="R-2" TARFILE="R-$1.tar.gz" -else +elif echo "$1" | grep -Eq '^3' ; then DOWNLOAD_DIR="R-3" TARFILE="R-$1.tar.gz" +else + DOWNLOAD_DIR="R-4" + TARFILE="R-$1.tar.gz" fi wget "http://cran.r-project.org/src/base/$DOWNLOAD_DIR/$TARFILE" diff --git a/man/dockerize.Rd b/man/dockerize.Rd index 75096c3..4fb3479 100644 --- a/man/dockerize.Rd +++ b/man/dockerize.Rd @@ -18,7 +18,9 @@ dockerize( lib = NA, cran_mirror = "https://cran.r-project.org/", check_cran_mirror = TRUE, - bioc_mirror = "https://bioconductor.org/packages/" + bioc_mirror = "https://bioconductor.org/packages/", + no_rocker = FALSE, + debian_version = c("lenny", "etch", "squeeze", "wheezy", "jessie", "stretch") ) dockerize_rang(...) @@ -53,6 +55,10 @@ and \code{\link[=download.file]{download.file()}}.} \item{bioc_mirror}{character, which Bioconductor mirror to use} +\item{no_rocker}{logical, whether to skip using Rocker images even when an appropriate version is available. Please keep this as \code{TRUE} unless you know what you are doing} + +\item{debian_version, }{when Rocker images are not used, which EOL version of Debian to use. Can only be "lenny", "etch", "squeeze", "wheezy", "jessie", "stretch". Please keep this as default "lenny" unless you know what you are doing} + \item{...}{arguments to be passed to \code{dockerize}} } \value{ diff --git a/tests/testthat/test_dockerize.R b/tests/testthat/test_dockerize.R index f2e047e..1550a2b 100644 --- a/tests/testthat/test_dockerize.R +++ b/tests/testthat/test_dockerize.R @@ -105,9 +105,9 @@ test_that("Docker R < 2.1", { test_that(".group_sysreqs and issue #21", { graph <- readRDS("../testdata/graph.RDS") - expect_equal(.group_sysreqs(graph), "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config && apt-get install -y default-jdk libgsl0-dev libicu-dev libpng-dev libxml2-dev make python3 zlib1g-dev liblzma-dev libpcre3-dev libbz2-dev && R CMD javareconf") + expect_equal(.group_sysreqs(graph), "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config libcurl4-openssl-dev && apt-get install -y default-jdk libgsl0-dev libicu-dev libpng-dev libxml2-dev make python3 zlib1g-dev liblzma-dev libpcre3-dev libbz2-dev && R CMD javareconf") graph <- readRDS("../testdata/rang_ok.RDS") - expect_equal(.group_sysreqs(graph), "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config") + expect_equal(.group_sysreqs(graph), "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config libcurl4-openssl-dev") graph <- readRDS("../testdata/issue21.RDS") expected_output <- "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config && apt-get install -y software-properties-common && add-apt-repository -y ppa:cran/libgit2 && apt-get update && apt-get install -y cmake git libcurl4-openssl-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libgit2-dev libgsl0-dev libharfbuzz-dev libicu-dev libjpeg-dev libpng-dev libssh2-1-dev libssl-dev libtiff-dev libxml2-dev make pandoc pari-gp zlib1g-dev" expect_warning(output <- .group_sysreqs(graph)) From 9e5471a6617cca53403a9b944c6da87fb6f04bdb Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Fri, 24 Feb 2023 11:16:15 +0100 Subject: [PATCH 2/3] Add tests #67 --- tests/testthat/test_dockerize.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/testthat/test_dockerize.R b/tests/testthat/test_dockerize.R index 1550a2b..ce3ea61 100644 --- a/tests/testthat/test_dockerize.R +++ b/tests/testthat/test_dockerize.R @@ -210,3 +210,23 @@ test_that("dockerize with bioc #58", { x <- readLines(file.path(temp_dir, "rang.R")) expect_true(any(grepl("bioc_mirror",x))) }) + +test_that("no_rocker #67", { + rang_ok <- readRDS("../testdata/rang_ok.RDS") + temp_dir <- .generate_temp_dir() + dockerize(rang = rang_ok, output_dir = temp_dir) ## no_rocker = FALSE + expect_false(file.exists(file.path(temp_dir, "compile_r.sh"))) + expect_false(any(readLines(file.path(temp_dir, "Dockerfile")) == "FROM debian/eol:lenny")) + temp_dir <- .generate_temp_dir() + dockerize(rang = rang_ok, output_dir = temp_dir, no_rocker = TRUE) ## debian_version = lenny + expect_true(file.exists(file.path(temp_dir, "compile_r.sh"))) + expect_true(any(readLines(file.path(temp_dir, "Dockerfile")) == "FROM debian/eol:lenny")) + temp_dir <- .generate_temp_dir() + dockerize(rang = rang_ok, output_dir = temp_dir, no_rocker = TRUE, + debian_version = "jessie") + expect_true(file.exists(file.path(temp_dir, "compile_r.sh"))) + expect_true(any(readLines(file.path(temp_dir, "Dockerfile")) == "FROM debian/eol:jessie")) + temp_dir <- .generate_temp_dir() + expect_error(dockerize(rang = rang_ok, output_dir = temp_dir, no_rocker = TRUE, + debian_version = "3.11")) +}) From c200863ac700c50dc24c1086505994a104f62674 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Fri, 24 Feb 2023 11:31:23 +0100 Subject: [PATCH 3/3] Remove the commented out rocker code [no ci] --- R/installation.R | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/R/installation.R b/R/installation.R index c025f77..6acf41d 100644 --- a/R/installation.R +++ b/R/installation.R @@ -457,19 +457,6 @@ dockerize <- function(rang, output_dir, materials_dir = NULL, image = c("r-ver", dockerfile_content <- .generate_rocker_dockerfile_content(r_version = rang$r_version, sysreqs_cmd = sysreqs_cmd, lib = lib, cache = cache, image = image) - ## dockerfile_content <- c("", "", "COPY rang.R ./rang.R", "RUN Rscript rang.R", "CMD [\"R\"]") - ## if (!is.na(lib)) { - ## dockerfile_content[4] <- paste0("RUN mkdir ", lib, " && Rscript rang.R") - ## } - ## dockerfile_content[1] <- paste0("FROM rocker/", image, ":", rang$r_version) - ## dockerfile_content[2] <- paste("RUN", sysreqs_cmd) - ## if (image == "rstudio") { - ## dockerfile_content[5] <- "EXPOSE 8787" - ## dockerfile_content[6] <- "CMD [\"/init\"]" - ## } - ## if (isTRUE(cache)) { - ## dockerfile_content <- .insert_cache_dir(dockerfile_content) - ## } } if (!(is.null(materials_dir))) { materials_subdir_in_output_dir <- file.path(output_dir, "materials")