diff --git a/R/cache.R b/R/cache.R index 9e70a6d..1a817f8 100644 --- a/R/cache.R +++ b/R/cache.R @@ -143,11 +143,7 @@ if (!dir.exists(cache_dir)) { dir.create(cache_dir, recursive = TRUE) } - sha <- .gh(paste0("/repos/debuerreotype/docker-debian-eol-artifacts/branches/dist-", - debian_version))$commit$sha - - debian_image_url <- .gh(paste0("/repos/debuerreotype/docker-debian-eol-artifacts/contents/", - debian_version, "/amd64/rootfs.tar.xz"), ref = sha)$download_url + 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)) { diff --git a/R/dockerfile.R b/R/dockerfile.R new file mode 100644 index 0000000..68e1e86 --- /dev/null +++ b/R/dockerfile.R @@ -0,0 +1,59 @@ +## .insert_cache_dir <- function(dockerfile_content) { +## rang_line <- which(dockerfile_content == "RUN Rscript rang.R") +## c(dockerfile_content[1:(rang_line - 1)], +## "COPY cache ./cache", +## dockerfile_content[rang_line:length(dockerfile_content)]) +## } + +.insert_materials_dir <- function(dockerfile_content) { + dockerfile_content$COPY <- append(dockerfile_content$COPY, "COPY materials/ ./materials/") + dockerfile_content +} + +.generate_debian_eol_dockerfile_content <- function(r_version, lib, sysreqs_cmd, cache, debian_version = "lenny") { + dockerfile_content <- list( + FROM = c(paste0("FROM debian/eol:", debian_version)), + chores = c("ENV TZ UTC", + "RUN 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"), + COPY = c("COPY rang.R ./rang.R", "COPY compile_r.sh ./compile_r.sh"), + RUN = c(paste("RUN", sysreqs_cmd)), + CMD = c("CMD [\"R\"]")) + if (!is.na(lib)) { + dockerfile_content$RUN <- append(dockerfile_content$RUN, paste0("RUN mkdir ", lib, " && bash compile_r.sh ", r_version)) + } else { + dockerfile_content$RUN <- append(dockerfile_content$RUN, paste0("RUN bash compile_r.sh ", r_version)) + } + if (isTRUE(cache)) { + dockerfile_content$COPY <- append(dockerfile_content$COPY, + c("COPY cache/rpkgs ./cache/rpkgs", "COPY cache/rsrc ./cache/rsrc")) + dockerfile_content$FROM <- c("FROM scratch", "ADD cache/debian/rootfs.tar.xz /") + } + return(dockerfile_content) +} + +.generate_rocker_dockerfile_content <- function(r_version, lib, sysreqs_cmd, cache, image) { + dockerfile_content <- list( + FROM = c(paste0("FROM rocker/", image, ":", r_version)), + chores = NULL, + COPY = c("COPY rang.R ./rang.R"), + RUN = c(paste("RUN", sysreqs_cmd)), + "CMD [\"R\"]") + if (!is.na(lib)) { + dockerfile_content$RUN <- append(dockerfile_content$RUN, paste0("RUN mkdir ", lib, " && Rscript rang.R")) + } else { + dockerfile_content$RUN <- append(dockerfile_content$RUN, "Rscript rang.R") + } + if (isTRUE(cache)) { + dockerfile_content$COPY <- append(dockerfile_content$COPY, "COPY cache ./cache") + } + if (image == "rstudio") { + dockerfile_content$RUN <- c("EXPOSE 8787", "CMD [\"/init\"]") + } + return(dockerfile_content) +} + +.write_dockerfile <- function(dockerfile_content, path) { + content <- c(dockerfile_content$FROM, dockerfile_content$chores, + dockerfile_content$COPY, dockerfile_content$RUN) + writeLines(content, path) +} diff --git a/R/installation.R b/R/installation.R index 7044443..6b98f53 100644 --- a/R/installation.R +++ b/R/installation.R @@ -114,59 +114,6 @@ utils::compareVersion(rang$r_version, r_version) == -1 } -.insert_cache_dir <- function(dockerfile_content) { - rang_line <- which(dockerfile_content == "RUN Rscript rang.R") - c(dockerfile_content[1:(rang_line - 1)], - "COPY cache ./cache", - dockerfile_content[rang_line:length(dockerfile_content)]) -} - -.insert_materials_dir <- function(dockerfile_content) { - rang_line <- which(dockerfile_content == "COPY rang.R ./rang.R") - c(dockerfile_content[1:rang_line], - "COPY materials/ ./materials/", - dockerfile_content[(rang_line + 1):length(dockerfile_content)]) -} - -.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", - "RUN 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", - "COPY rang.R ./rang.R", - "COPY compile_r.sh ./compile_r.sh", - paste("RUN", sysreqs_cmd), - paste("RUN bash compile_r.sh", r_version), - "CMD [\"R\"]") - if (!is.na(lib)) { - dockerfile_content[7] <- paste0("RUN mkdir ", lib, " && bash compile_r.sh ", r_version) - } - if (isTRUE(cache)) { - dockerfile_content <- c(dockerfile_content[1:5], "COPY cache/rpkgs ./cache/rpkgs", dockerfile_content[6:8]) - dockerfile_content <- append(dockerfile_content, "COPY cache/rsrc ./cache/rsrc", after = 6) - dockerfile_content[1] <- "ADD cache/debian/rootfs.tar.xz /" - dockerfile_content <- c("FROM scratch", dockerfile_content) - } - 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") @@ -428,7 +375,7 @@ dockerize <- function(rang, output_dir, materials_dir = NULL, image = c("r-ver", recursive = TRUE) dockerfile_content <- .insert_materials_dir(dockerfile_content) } - writeLines(dockerfile_content, file.path(output_dir, "Dockerfile")) + .write_dockerfile(dockerfile_content, file.path(output_dir, "Dockerfile")) .generate_docker_readme(output_dir = output_dir,image = image) invisible(output_dir) } diff --git a/R/memo_misc.R b/R/memo_misc.R index c8b3262..6daa56e 100644 --- a/R/memo_misc.R +++ b/R/memo_misc.R @@ -56,7 +56,7 @@ NULL ## internal data generation ## --- -### Supported OS Versions +## ### Supported OS Versions ## supported_os <- c("trusty" = "ubuntu-14.04", "xenial" = "ubuntu-16.04", "bionic" = "ubuntu-18.04", "focal" = "ubuntu-20.04", "centos-6", "centos-7", "centos-8", "redhat-6", "redhat-7", "redhat-8") ## ### R version history ## cached_rver <- .rver() @@ -64,7 +64,15 @@ NULL ## ### Bioconductor version history ## cached_biocver <- .biocver() ## attr(cached_biocver, "newest_date") <- max(cached_biocver$date) -## usethis::use_data(supported_os, cached_rver, cached_biocver, internal = TRUE, overwrite = TRUE) +## debian_version <- c("lenny", "squeeze", "wheezy", "jessie", "stretch") +## .get_debian_urls <- function(debian_version, output_dir, verbose) { +## sha <- .gh(paste0("/repos/debuerreotype/docker-debian-eol-artifacts/branches/dist-", +## debian_version))$commit$sha +## .gh(paste0("/repos/debuerreotype/docker-debian-eol-artifacts/contents/", +## debian_version, "/amd64/rootfs.tar.xz"), ref = sha)$download_url +## } +## debian_urls <- sapply(debian_version, .get_debian_urls) +## usethis::use_data(supported_os, cached_rver, cached_biocver, debian_urls, internal = TRUE, overwrite = TRUE) ## test data upgrade ## --- diff --git a/R/sysdata.rda b/R/sysdata.rda index 40fab33..922b9c4 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ