diff --git a/R/installation.R b/R/installation.R index 8f68b12..545431d 100644 --- a/R/installation.R +++ b/R/installation.R @@ -188,7 +188,14 @@ basic_docker[gran_line:length(basic_docker)]) } -.generate_pre310_docker <- function(r_version, debian_version = "lenny", lib, sysreps_cmd, cache) { +.insert_materials_dir <- function(basic_docker){ + gran_line <- which(basic_docker == "COPY gran.R ./gran.R") + c(basic_docker[1:gran_line], + "COPY materials/ ./materials/", + basic_docker[(gran_line+1):length(basic_docker)]) +} + +.generate_pre310_docker <- function(materials_dir,r_version, debian_version = "lenny", lib, sysreps_cmd, cache) { basic_docker <- c( paste0("FROM debian/eol:", debian_version), "ENV TZ UTC", @@ -277,6 +284,7 @@ export_granlist <- function(granlist, path, granlist_as_comment = TRUE, verbose #' This function exports the result from [resolve()] to a Docker file. For R version >= 3.1.0, the Dockerfile is based on the versioned Rocker image. #' For R version < 3.1.0, the Dockerfile is based on Debian and it compiles R from source. #' @param output_dir where to put the Docker file +#' @param materials_dir additional resources (e.g. analysis scripts) to be copied into `output_dir` #' @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 content from CRAN now. Please note that the system requirements are not cached @@ -297,7 +305,7 @@ export_granlist <- function(granlist, path, granlist_as_comment = TRUE, verbose #' } #' } #' @export -dockerize <- function(granlist, output_dir, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), +dockerize <- function(granlist, output_dir, materials_dir = NULL, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), granlist_as_comment = TRUE, cache = FALSE, verbose = TRUE, lib = NA, cran_mirror = "https://cran.r-project.org/", check_cran_mirror = TRUE) { if (missing(output_dir)) { @@ -324,7 +332,7 @@ dockerize <- function(granlist, output_dir, image = c("r-ver", "rstudio", "tidyv if (utils::compareVersion(granlist$r_version, "3.1") == -1) { file.copy(system.file("compile_r.sh", package = "gran"), file.path(output_dir, "compile_r.sh"), overwrite = TRUE) - basic_docker <- .generate_pre310_docker(r_version = granlist$r_version, + basic_docker <- .generate_pre310_docker(materials_dir, r_version = granlist$r_version, sysreps_cmd = sysreps_cmd, lib = lib, cache = cache) } else { @@ -342,6 +350,20 @@ dockerize <- function(granlist, output_dir, image = c("r-ver", "rstudio", "tidyv basic_docker <- .insert_cache_dir(basic_docker) } } + if(!is.null(materials_dir)){ + if(!dir.exists(materials_dir)){ + stop(paste0("The folder ",materials_dir," does not exist"),call. = FALSE) + } else{ + out_mat_dir <- paste0(output_dir,"/materials") + if (!dir.exists(out_mat_dir)) { + dir.create(out_mat_dir) + } + file.copy(list.files(materials_dir, full.names = TRUE), + out_mat_dir, + recursive = TRUE) + basic_docker <- .insert_materials_dir(basic_docker) + } + } writeLines(basic_docker, file.path(output_dir, "Dockerfile")) invisible(output_dir) } diff --git a/man/dockerize.Rd b/man/dockerize.Rd index 366194a..230af0c 100644 --- a/man/dockerize.Rd +++ b/man/dockerize.Rd @@ -10,6 +10,7 @@ dockerize( granlist, output_dir, + materials_dir = NULL, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), granlist_as_comment = TRUE, cache = FALSE, @@ -30,6 +31,8 @@ dockerise_granlist(...) \item{output_dir}{where to put the Docker file} +\item{materials_dir}{additional resources (e.g. analysis scripts) to be copied into \code{output_dir}} + \item{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}