Skip to content

Commit

Permalink
remove the distro parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentGuyader committed Jun 30, 2024
1 parent cac5dd4 commit 09100b7
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 154 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- remove sysreqs.r-hub.io to use {pak} instead for system requirement detection
- move from `pak::pkg_system_requirements` to `pak::pkg_sysreqs()` thanks to @B0ydT
- `dock_from_renv` allow to specify user to use in Dockerfile
- the `dependencies` parameter in `dock_from_renv` if set to `TRUE` will install required dependencies plus optional and development dependencies. defaut is `NA` only required (hard) dependencies,

# dockerfile 0.2.2

Expand Down
86 changes: 22 additions & 64 deletions R/dock_from_renv.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# WARNING - Generated by {fusen} from dev/flat_dock_from_renv.Rmd: do not edit by hand

# ignoring opensuse for the time being
available_distros <- c(
"xenial",
"bionic",
"focal",
"centos7",
"centos8"
)

#' @importFrom memoise memoise
pkg_sysreqs_mem <- memoise::memoise(
pak::pkg_sysreqs
Expand All @@ -20,7 +11,7 @@ pkg_sysreqs_mem <- memoise::memoise(
#' @param lockfile Path to an `renv.lock` file to use as an input..
#' @param FROM Docker image to start FROM Default is FROM rocker/r-base
#' @param AS The AS of the Dockerfile. Default it `NULL`.
#' @param distro One of "focal", "bionic", "xenial", "centos7",or "centos8". See available distributions at https://hub.docker.com/r/rstudio/r-base/.
#' @param distro - deprecated - only debian/ubuntu based images are supported
#' @param sysreqs boolean. If `TRUE`, the Dockerfile will contain sysreq installation.
#' @param expand boolean. If `TRUE` each system requirement will have its own `RUN` line.
#' @param repos character. The URL(s) of the repositories to use for `options("repos")`.
Expand All @@ -33,6 +24,13 @@ pkg_sysreqs_mem <- memoise::memoise(
#' If you set it to `NULL`, the latest available version of renv will be used.
#' @param use_pak boolean. If `TRUE` use pak to deal with dependencies during `renv::restore()`. FALSE by default
#' @param user Name of the user to specify in the Dockerfile with the USER instruction. Default is `NULL`, in which case the user from the FROM image is used.
#' @param dependencies What kinds of dependencies to install. Most commonly
#' one of the following values:
#' - `NA`: only required (hard) dependencies,
#' - `TRUE`: required dependencies plus optional and development
#' dependencies,
#' - `FALSE`: do not install any dependencies. (You might end up with a
#' non-working package, and/or the installation might fail.)
#' @importFrom utils getFromNamespace
#' @return A R6 object of class `Dockerfile`.
#' @details
Expand All @@ -59,7 +57,7 @@ pkg_sysreqs_mem <- memoise::memoise(
#' }
dock_from_renv <- function(
lockfile = "renv.lock",
distro = "focal",
distro = NULL,
FROM = "rocker/r-base",
AS = NULL,
sysreqs = TRUE,
Expand All @@ -68,9 +66,9 @@ dock_from_renv <- function(
extra_sysreqs = NULL,
use_pak = FALSE,
user = NULL,
dependencies = NA,
renv_version
) {
distro <- match.arg(distro, available_distros)
try(dockerfiler::renv$initialize(),silent=TRUE)
lock <- dockerfiler::renv$lockfile_read(file = lockfile) # using vendored renv
# https://rstudio.github.io/renv/reference/vendor.html?q=vendor#null
Expand All @@ -79,7 +77,6 @@ dock_from_renv <- function(
R_major_minor <- lock$R$Version
dock <- Dockerfile$new(
FROM = gen_base_image(
distro = distro,
r_version = R_major_minor,
FROM = FROM
),
Expand All @@ -101,58 +98,18 @@ dock_from_renv <- function(
message("renv version = ",
ifelse(!is.null(renv_version),renv_version,"the must up to date in the repos")
)


# ici il faut connaire l'image utilisé par l'image.


distro_args <- switch(
distro,
centos7 = list(
sysreqs_platform = "centos-7"
),
centos8 = list(
sysreqs_platform = "centos-8"
),
xenial = list(
sysreqs_platform = "ubuntu-16.04"
),
bionic = list(
sysreqs_platform = "ubuntu-18.04"
),
focal = list(
sysreqs_platform = "ubuntu-20.04"
),
jammy = list(
sysreqs_platform = "ubuntu-2.04"
)
)

install_cmd <- switch(
distro,
centos7 = "yum install -y",
centos8 = "yum install -y",
xenial = "apt-get install -y",
bionic = "apt-get install -y",
focal = "apt-get install -y",
jammy = "apt-get install -y"
)

update_cmd <- switch(
distro,
centos7 = "yum update -y",
centos8 = "yum update -y",
xenial = "apt-get update -y",
bionic = "apt-get update -y",
focal = "apt-get update -y",
jammy = "apt-get update -y"
)
# distro_args <- list(sysreqs_platform = "ubuntu-22.04")

distro_args <- list(sysreqs_platform = "ubuntu")

clean_cmd <- switch(
distro,
centos7 = "yum clean all && rm -rf /var/cache/yum",
centos8 = "yum clean all && rm -rf /var/cache/yum",
xenial = "rm -rf /var/lib/apt/lists/*",
bionic = "rm -rf /var/lib/apt/lists/*",
focal = "rm -rf /var/lib/apt/lists/*",
jammy = "rm -rf /var/lib/apt/lists/*"
)
install_cmd <- "apt-get install -y"
update_cmd <-"apt-get update -y"
clean_cmd <- "rm -rf /var/lib/apt/lists/*"

pkgs <- names(lock$Packages)

Expand All @@ -176,7 +133,8 @@ dock_from_renv <- function(
pkgs,
FUN = function(x) {
c(
list(pkg = x),
list(pkg = x,
dependencies = dependencies),
distro_args
)
}
Expand Down
12 changes: 6 additions & 6 deletions R/gen_base_image.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#' @keywords internal
#' @noRd
gen_base_image <- function(
distro = "bionic",
distro = NULL,
r_version = "4.0",
FROM = "rstudio/r-base"
) {
distro <- match.arg(distro, available_distros)

if (FROM == "rstudio/r-base") {
glue::glue("{FROM}:{r_version}-{distro}")
} else {
if (!is.null(distro)){
warning("the `distro` parameter is not used anymore, only debian/ubuntu based images are supported")
}

glue::glue("{FROM}:{r_version}")
}

}
Loading

0 comments on commit 09100b7

Please sign in to comment.