-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
77 changed files
with
8,960 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
.generate_debian_eol_apptainer_content <- function(r_version, lib, sysreqs_cmd, cache, debian_version = "lenny", | ||
post_installation_steps = NULL, | ||
rel_dir = "", | ||
copy_all = FALSE) { | ||
rang_path <- file.path(rel_dir, "rang.R") | ||
cache_path <- file.path(rel_dir, "cache") | ||
compile_path <- file.path(rel_dir, "compile_r.sh") | ||
environment_vars <- c("export TZ=UTC", paste0("export COMPILE_PATH=", compile_path), paste0("export RANG_PATH=", rang_path)) | ||
containerfile_content <- list( | ||
BOOTSTRAP = "Bootstrap: docker", | ||
FROM = c(paste0("From: debian/eol:", debian_version)), | ||
ENV_section = "\n%environment\n", | ||
ENV = environment_vars, | ||
FILES_section = "\n%files\n", | ||
FILES = c(paste0("rang.R ", rang_path), paste0("compile_r.sh ", compile_path)), | ||
POST_section = "\n%post\n", | ||
POST = c( | ||
environment_vars, | ||
"ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && apt-get update -qq && apt-get install wget locales build-essential r-base-dev -y", | ||
sysreqs_cmd | ||
), | ||
STARTSCRIPT_section = "\n%startscript\n", | ||
STARTSCRIPT = c("exec R \"${@}\"") | ||
) | ||
if (!is.na(lib)) { | ||
containerfile_content$POST <- append(containerfile_content$POST, paste0("mkdir ", lib, " && bash $COMPILE_PATH ", r_version)) | ||
} else { | ||
containerfile_content$POST <- append(containerfile_content$POST, paste0("bash $COMPILE_PATH ", r_version)) | ||
} | ||
if (isTRUE(cache)) { | ||
containerfile_content$BOOTSTRAP <- "Bootstrap: docker" | ||
containerfile_content$FROM <- c(paste0("From: debian/eol:", debian_version)) | ||
containerfile_content$FILES <- append( | ||
containerfile_content$FILES, | ||
c( | ||
paste0("cache/rpkgs ", file.path(cache_path, "rpkgs")), | ||
paste0("cache/rsrc ", file.path(cache_path, "rsrc")) | ||
) | ||
) | ||
containerfile_content$POST <- append(paste0("export CACHE_PATH=", cache_path), containerfile_content$POST) | ||
} | ||
containerfile_content$POST <- append(containerfile_content$POST, post_installation_steps) | ||
if (isTRUE(copy_all)) { | ||
containerfile_content$FILES <- c(". /") | ||
} | ||
return(containerfile_content) | ||
} | ||
|
||
.generate_rocker_apptainer_content <- function(r_version, lib, sysreqs_cmd, cache, image, | ||
post_installation_steps = NULL, | ||
rel_dir = "", | ||
copy_all = FALSE) { | ||
rang_path <- file.path(rel_dir, "rang.R") | ||
cache_path <- file.path(rel_dir, "cache") | ||
environment_vars <- c(paste0("export RANG_PATH=", rang_path)) | ||
containerfile_content <- list( | ||
BOOTSTRAP = "Bootstrap: docker", | ||
FROM = c(paste0("From: rocker/", image, ":", r_version)), | ||
ENV_section = "\n%environment\n", | ||
ENV = c(environment_vars, "export RPORT=${RPORT:-8787}", | ||
"export USER=$(whoami)", "export PASSWORD=${PASSWORD:-set_your_password}"), | ||
FILES_section = "\n%files\n", | ||
FILES = c(paste0("rang.R ", rang_path)), | ||
POST_section = "\n%post\n", | ||
POST = c(environment_vars, sysreqs_cmd), | ||
STARTSCRIPT_section = "\n%startscript\n", | ||
STARTSCRIPT = c("exec R \"${@}\"") | ||
) | ||
if (!is.na(lib)) { | ||
containerfile_content$POST <- append(containerfile_content$POST, paste0("mkdir ", lib, " && Rscript $RANG_PATH")) | ||
} else { | ||
containerfile_content$POST <- append(containerfile_content$POST, "Rscript $RANG_PATH") | ||
} | ||
if (isTRUE(cache)) { | ||
containerfile_content$FILES <- append(containerfile_content$FILES, paste0("cache ", cache_path)) | ||
containerfile_content$POST <- append(paste0("export CACHE_PATH=", cache_path), containerfile_content$POST) | ||
} | ||
if (image == "rstudio") { | ||
containerfile_content$STARTSCRIPT <- c("exec /usr/lib/rstudio-server/bin/rserver \\\ | ||
--auth-none=0 --auth-pam-helper-path=pam-helper \\\ | ||
--server-user=${USER} --www-port=${RPORT}") | ||
} | ||
containerfile_content$POST <- append(containerfile_content$POST, post_installation_steps) | ||
if (isTRUE(copy_all)) { | ||
containerfile_content$FILES <- c(". /") | ||
} | ||
return(containerfile_content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
#' @importFrom utils download.file | ||
#' @importFrom here here | ||
NULL | ||
|
||
.query_mirror_validity <- function(mirror) { | ||
if (mirror == "https://cran.r-project.org/") { | ||
return(TRUE) | ||
} | ||
all_mirrors <- utils::getCRANmirrors()$URL | ||
mirror %in% all_mirrors | ||
} | ||
|
||
.normalize_url <- function(mirror, https = TRUE) { | ||
if (grepl("^http://", mirror)) { | ||
mirror <- gsub("^http://", "https://", mirror) | ||
} | ||
if (!grepl("^https://", mirror)) { | ||
mirror <- paste0("https://", mirror) | ||
} | ||
if (!grepl("/$", mirror)) { | ||
mirror <- paste0(mirror, "/") | ||
} | ||
if (grepl("/+$", mirror)) { | ||
mirror <- gsub("/+$", "/", mirror) | ||
} | ||
if (isTRUE(https)) { | ||
return(mirror) | ||
} else { | ||
return(gsub("^https://", "http://", mirror)) | ||
} | ||
} | ||
|
||
.check_tarball_path <- function(tarball_path, x, dir = FALSE) { | ||
## raise error when tarball_path doesn't exist | ||
if ((isFALSE(dir) && isFALSE(file.exists(tarball_path))) || | ||
(isTRUE(dir) && isFALSE(dir.exists(tarball_path)))) { | ||
stop(x, " can't be cached.", call. = FALSE) | ||
} | ||
invisible() | ||
} | ||
|
||
.cache_pkg_cran <- function(x, version, cache_dir, cran_mirror, verbose) { | ||
url <- paste(cran_mirror, "src/contrib/Archive/", x, "/", x, "_", version, ".tar.gz", sep = "") | ||
tarball_path <- file.path(cache_dir, paste(x, "_", version, ".tar.gz", sep = "")) | ||
tryCatch({ | ||
suppressWarnings(utils::download.file(url, destfile = tarball_path, quiet = !verbose)) | ||
}, error = function(e) { | ||
## is the current latest | ||
url <- paste(cran_mirror, "src/contrib/", x, "_", version, ".tar.gz", sep = "") | ||
utils::download.file(url, destfile = tarball_path, quiet = !verbose) | ||
}) | ||
.check_tarball_path(tarball_path, x) | ||
} | ||
|
||
.cache_pkg_bioc <- function(x, version, cache_dir, bioc_mirror, bioc_version, verbose, uid) { | ||
url <- paste(bioc_mirror, bioc_version, "/", uid, "/src/contrib/", x, "_", version, ".tar.gz", sep = "") | ||
tarball_path <- file.path(cache_dir, paste(x, "_", version, ".tar.gz", sep = "")) | ||
suppressWarnings(utils::download.file(url, destfile = tarball_path, quiet = !verbose)) | ||
.check_tarball_path(tarball_path, x) | ||
} | ||
|
||
.cache_pkg_github <- function(x, version, handle, source, uid, cache_dir, verbose) { | ||
sha <- uid | ||
tarball_path <- file.path(cache_dir, paste("raw_", x, "_", version, ".tar.gz", sep = "")) | ||
utils::download.file(paste("https://api.github.com/repos/", handle, "/tarball/", sha, sep = ""), destfile = tarball_path, | ||
quiet = !verbose) | ||
.check_tarball_path(tarball_path, x) | ||
} | ||
|
||
.cache_pkg_local <- function(x, version, cache_dir, uid) { | ||
local_path <- uid | ||
tarball_path <- file.path(cache_dir, paste("raw_", x, "_", version, ".tar.gz", sep = "")) | ||
if (isTRUE(grepl("\\.tar.gz$|\\.tgz$", local_path))) { | ||
## it could be a valid source package, but don't trust it blindly, mark it as raw_ | ||
## similar to github packages | ||
file.copy(local_path, tarball_path) | ||
return(.check_tarball_path(tarball_path, x)) | ||
} | ||
if (.is_directory(local_path)) { | ||
dir_pkg_path <- file.path(cache_dir, paste("dir_", x, "_", version, sep = "")) | ||
res <- file.copy(from = local_path, to = cache_dir, recursive = TRUE, overwrite = TRUE) | ||
res <- file.rename(from = file.path(cache_dir, x), to = dir_pkg_path) | ||
return(.check_tarball_path(dir_pkg_path, x, dir = TRUE)) | ||
} | ||
} | ||
|
||
.cache_pkgs <- function(rang, base_dir, cran_mirror, bioc_mirror, verbose) { | ||
installation_order <- .generate_installation_order(rang) | ||
cache_dir <- file.path(base_dir, "cache", "rpkgs") | ||
if (!dir.exists(cache_dir)) { | ||
dir.create(cache_dir, recursive = TRUE) | ||
} | ||
for (i in seq(from = 1, to = nrow(installation_order), by = 1)) { | ||
x <- installation_order$x[i] | ||
source <- installation_order$source[i] | ||
version <- installation_order$version[i] | ||
handle <- installation_order$handle[i] | ||
uid <- installation_order$uid[i] | ||
if (source == "cran") { | ||
.cache_pkg_cran(x = x, version = version, cache_dir = cache_dir, | ||
cran_mirror = cran_mirror, verbose = verbose) | ||
} | ||
if (source == "github") { | ||
## please note that these cached packages are not built | ||
.cache_pkg_github(x = x, version = version, handle = handle, | ||
source = source, uid = uid, | ||
cache_dir = cache_dir, verbose = verbose) | ||
} | ||
if(source == "bioc") { | ||
.cache_pkg_bioc(x = x, version = version, cache_dir = cache_dir, | ||
bioc_mirror = bioc_mirror, bioc_version = rang$bioc_version, verbose = verbose, | ||
uid = uid) | ||
} | ||
if(source == "local") { | ||
## please note that these cached packages are not built | ||
.cache_pkg_local(x = x, version = version, cache_dir = cache_dir, uid = uid) | ||
} | ||
} | ||
invisible(base_dir) | ||
} | ||
|
||
.cache_rsrc <- function(r_version, base_dir, verbose) { | ||
cache_dir <- file.path(base_dir, "cache", "rsrc") | ||
if (!dir.exists(cache_dir)) { | ||
dir.create(cache_dir, recursive = TRUE) | ||
} | ||
major_version <- as.character(package_version(r_version)$major) | ||
if (major_version == "1") { | ||
file_extension <- ".tgz" | ||
} else { | ||
file_extension <- ".tar.gz" | ||
} | ||
download_dir <- paste0("R-", major_version) | ||
tar_file <- paste0("R-", r_version, file_extension) | ||
url <- paste0("https://cran.r-project.org/src/base/", download_dir, "/", tar_file) | ||
tar_path <- file.path(cache_dir, tar_file) | ||
download.file(url = url, destfile = tar_path, quiet = !verbose) | ||
if (!file.exists(tar_path)) { | ||
stop("Fail to cache R source.") | ||
} | ||
return(tar_path) | ||
} | ||
|
||
|
||
.cache_debian <- function(debian_version, base_dir, verbose) { | ||
cache_dir <- file.path(base_dir, "cache", "debian") | ||
if (!dir.exists(cache_dir)) { | ||
dir.create(cache_dir, recursive = TRUE) | ||
} | ||
debian_image_url <- debian_urls[debian_version] | ||
rootfs_path <- file.path(cache_dir, "rootfs.tar.xz") | ||
download.file(debian_image_url, destfile = rootfs_path, quiet = !verbose) | ||
if (!file.exists(rootfs_path)) { | ||
stop("Fail to cache Debian disk image.") | ||
} | ||
return(rootfs_path) | ||
} |
Oops, something went wrong.