Skip to content

Commit 5ef486d

Browse files
remove the distro parameter (#73)
* remove the distro parameter * add dependencies parameter * update doc
1 parent cac5dd4 commit 5ef486d

File tree

7 files changed

+140
-154
lines changed

7 files changed

+140
-154
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- remove sysreqs.r-hub.io to use {pak} instead for system requirement detection
44
- move from `pak::pkg_system_requirements` to `pak::pkg_sysreqs()` thanks to @B0ydT
55
- `dock_from_renv` allow to specify user to use in Dockerfile
6+
- 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,
67

78
# dockerfile 0.2.2
89

R/dock_from_renv.R

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
# WARNING - Generated by {fusen} from dev/flat_dock_from_renv.Rmd: do not edit by hand
22

3-
# ignoring opensuse for the time being
4-
available_distros <- c(
5-
"xenial",
6-
"bionic",
7-
"focal",
8-
"centos7",
9-
"centos8"
10-
)
11-
123
#' @importFrom memoise memoise
134
pkg_sysreqs_mem <- memoise::memoise(
145
pak::pkg_sysreqs
@@ -20,7 +11,7 @@ pkg_sysreqs_mem <- memoise::memoise(
2011
#' @param lockfile Path to an `renv.lock` file to use as an input..
2112
#' @param FROM Docker image to start FROM Default is FROM rocker/r-base
2213
#' @param AS The AS of the Dockerfile. Default it `NULL`.
23-
#' @param distro One of "focal", "bionic", "xenial", "centos7",or "centos8". See available distributions at https://hub.docker.com/r/rstudio/r-base/.
14+
#' @param distro - deprecated - only debian/ubuntu based images are supported
2415
#' @param sysreqs boolean. If `TRUE`, the Dockerfile will contain sysreq installation.
2516
#' @param expand boolean. If `TRUE` each system requirement will have its own `RUN` line.
2617
#' @param repos character. The URL(s) of the repositories to use for `options("repos")`.
@@ -33,6 +24,13 @@ pkg_sysreqs_mem <- memoise::memoise(
3324
#' If you set it to `NULL`, the latest available version of renv will be used.
3425
#' @param use_pak boolean. If `TRUE` use pak to deal with dependencies during `renv::restore()`. FALSE by default
3526
#' @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.
27+
#' @param dependencies What kinds of dependencies to install. Most commonly
28+
#' one of the following values:
29+
#' - `NA`: only required (hard) dependencies,
30+
#' - `TRUE`: required dependencies plus optional and development
31+
#' dependencies,
32+
#' - `FALSE`: do not install any dependencies. (You might end up with a
33+
#' non-working package, and/or the installation might fail.)
3634
#' @importFrom utils getFromNamespace
3735
#' @return A R6 object of class `Dockerfile`.
3836
#' @details
@@ -59,7 +57,7 @@ pkg_sysreqs_mem <- memoise::memoise(
5957
#' }
6058
dock_from_renv <- function(
6159
lockfile = "renv.lock",
62-
distro = "focal",
60+
distro = NULL,
6361
FROM = "rocker/r-base",
6462
AS = NULL,
6563
sysreqs = TRUE,
@@ -68,9 +66,9 @@ dock_from_renv <- function(
6866
extra_sysreqs = NULL,
6967
use_pak = FALSE,
7068
user = NULL,
69+
dependencies = NA,
7170
renv_version
7271
) {
73-
distro <- match.arg(distro, available_distros)
7472
try(dockerfiler::renv$initialize(),silent=TRUE)
7573
lock <- dockerfiler::renv$lockfile_read(file = lockfile) # using vendored renv
7674
# https://rstudio.github.io/renv/reference/vendor.html?q=vendor#null
@@ -79,7 +77,6 @@ dock_from_renv <- function(
7977
R_major_minor <- lock$R$Version
8078
dock <- Dockerfile$new(
8179
FROM = gen_base_image(
82-
distro = distro,
8380
r_version = R_major_minor,
8481
FROM = FROM
8582
),
@@ -101,58 +98,18 @@ dock_from_renv <- function(
10198
message("renv version = ",
10299
ifelse(!is.null(renv_version),renv_version,"the must up to date in the repos")
103100
)
101+
102+
103+
# ici il faut connaire l'image utilisé par l'image.
104+
104105

105-
distro_args <- switch(
106-
distro,
107-
centos7 = list(
108-
sysreqs_platform = "centos-7"
109-
),
110-
centos8 = list(
111-
sysreqs_platform = "centos-8"
112-
),
113-
xenial = list(
114-
sysreqs_platform = "ubuntu-16.04"
115-
),
116-
bionic = list(
117-
sysreqs_platform = "ubuntu-18.04"
118-
),
119-
focal = list(
120-
sysreqs_platform = "ubuntu-20.04"
121-
),
122-
jammy = list(
123-
sysreqs_platform = "ubuntu-2.04"
124-
)
125-
)
126-
127-
install_cmd <- switch(
128-
distro,
129-
centos7 = "yum install -y",
130-
centos8 = "yum install -y",
131-
xenial = "apt-get install -y",
132-
bionic = "apt-get install -y",
133-
focal = "apt-get install -y",
134-
jammy = "apt-get install -y"
135-
)
136-
137-
update_cmd <- switch(
138-
distro,
139-
centos7 = "yum update -y",
140-
centos8 = "yum update -y",
141-
xenial = "apt-get update -y",
142-
bionic = "apt-get update -y",
143-
focal = "apt-get update -y",
144-
jammy = "apt-get update -y"
145-
)
106+
# distro_args <- list(sysreqs_platform = "ubuntu-22.04")
107+
108+
distro_args <- list(sysreqs_platform = "ubuntu")
146109

147-
clean_cmd <- switch(
148-
distro,
149-
centos7 = "yum clean all && rm -rf /var/cache/yum",
150-
centos8 = "yum clean all && rm -rf /var/cache/yum",
151-
xenial = "rm -rf /var/lib/apt/lists/*",
152-
bionic = "rm -rf /var/lib/apt/lists/*",
153-
focal = "rm -rf /var/lib/apt/lists/*",
154-
jammy = "rm -rf /var/lib/apt/lists/*"
155-
)
110+
install_cmd <- "apt-get install -y"
111+
update_cmd <-"apt-get update -y"
112+
clean_cmd <- "rm -rf /var/lib/apt/lists/*"
156113

157114
pkgs <- names(lock$Packages)
158115

@@ -176,7 +133,8 @@ dock_from_renv <- function(
176133
pkgs,
177134
FUN = function(x) {
178135
c(
179-
list(pkg = x),
136+
list(pkg = x,
137+
dependencies = dependencies),
180138
distro_args
181139
)
182140
}

R/gen_base_image.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
#' @keywords internal
88
#' @noRd
99
gen_base_image <- function(
10-
distro = "bionic",
10+
distro = NULL,
1111
r_version = "4.0",
1212
FROM = "rstudio/r-base"
1313
) {
14-
distro <- match.arg(distro, available_distros)
1514

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

0 commit comments

Comments
 (0)