Skip to content

Commit e40f804

Browse files
draft : Issue 44 (#54)
* feat : add ubuntu 22.04 name in distro * fix : allow Chrome's system dependence installation how: a more cleaver compact_sysreqs function is used * chore: update news , bump version * fix : unit test
1 parent 2832f5d commit e40f804

File tree

7 files changed

+188
-26
lines changed

7 files changed

+188
-26
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: dockerfiler
22
Title: Easy Dockerfile Creation from R
3-
Version: 0.2.1
3+
Version: 0.2.1.9001
44
Authors@R: c(
55
person("Colin", "Fay", , "[email protected]", role = c("cre", "aut"),
66
comment = c(ORCID = "0000-0001-7343-1846")),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(Dockerfile)
4+
export(compact_sysreqs)
45
export(dock_from_desc)
56
export(dock_from_renv)
67
export(docker_ignore_add)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- feat: Added `dock_from_renv()`, to create a Dockerfile from a renv.lock file (@JosiahParry, @statnmap)
66

7+
- fix: the dedicated `compact_sysreqs` function allow to deal with 'complex' sysreqs, such as chromimum installation
8+
9+
- feat: add jammy ubuntu distro in available distro
10+
711
# dockerfiler 0.1.4
812

913
* new version of `dock_from_desc()`

R/compact_sysreqs.R

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#' Compact Sysreqs
2+
#'
3+
#' @param pkg_installs pkg_sysreqs as vector, `pak::pkg_system_requirements` output
4+
#' @param update_cmd command used to update packages, "apt-get update -y" by default
5+
#' @param install_cmd command used to install packages, "apt-get install -y" by default
6+
#' @param clean_cmd command used to clean package folder, "rm -rf /var/lib/apt/lists/*" by default
7+
#'
8+
#' @return vector of compacted command to run to install sysreqs
9+
#' @export
10+
#'
11+
#' @examples
12+
#' pkg_installs <- list("apt-get install -y htop", "apt-get install -y top")
13+
#' compact_sysreqs(pkg_installs)
14+
15+
compact_sysreqs <- function(pkg_installs,
16+
update_cmd = "apt-get update -y",
17+
install_cmd = "apt-get install -y",
18+
clean_cmd ="rm -rf /var/lib/apt/lists/*"){
19+
20+
# on va extraire tout ce qui commence par pkg_installs
21+
pkg_ <- pkg_installs[lapply(pkg_installs,length)!=0]
22+
apt <- grepl(pattern = paste0("^",install_cmd),x = pkg_)
23+
24+
with_apt <- pkg_[apt]
25+
without_apt <- pkg_[!apt]
26+
# we choose to not compact unusals sysreqs
27+
without_apt_out <- unlist(without_apt)
28+
29+
if ( length(without_apt_out) > 0 && isTRUE( all(without_apt_out != "")) ){
30+
without_apt_out[1] <- paste(update_cmd, "&&", without_apt_out[1] )
31+
without_apt_out[length(without_apt_out)] <- paste( without_apt_out[length(without_apt_out)],"&&",clean_cmd)
32+
} else {
33+
without_apt_out <- NULL
34+
}
35+
36+
37+
compact <- paste(
38+
unique(unlist(strsplit(gsub(
39+
with_apt,
40+
pattern = install_cmd,
41+
replacement = ""
42+
),split = " "))),
43+
collapse = " "
44+
)
45+
if (compact != "") {
46+
apt_out <- paste(
47+
update_cmd,
48+
"&&",
49+
install_cmd,
50+
compact,
51+
"&&",
52+
clean_cmd
53+
)
54+
}else { apt_out <-NULL}
55+
56+
out<- unlist(c(apt_out,without_apt_out))
57+
58+
59+
60+
61+
out
62+
}

R/dock_from_renv.R

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ dock_from_renv <- function(
9393
focal = list(
9494
os = "ubuntu",
9595
os_release = "20.04"
96+
),
97+
jammy = list(
98+
os = "ubuntu",
99+
os_release = "22.04"
96100
)
97101
)
98102

@@ -102,7 +106,8 @@ dock_from_renv <- function(
102106
centos8 = "yum install -y",
103107
xenial = "apt-get install -y",
104108
bionic = "apt-get install -y",
105-
focal = "apt-get install -y"
109+
focal = "apt-get install -y",
110+
jammy = "apt-get install -y"
106111
)
107112

108113
update_cmd <- switch(
@@ -111,7 +116,8 @@ dock_from_renv <- function(
111116
centos8 = "yum update -y",
112117
xenial = "apt-get update -y",
113118
bionic = "apt-get update -y",
114-
focal = "apt-get update -y"
119+
focal = "apt-get update -y",
120+
jammy = "apt-get update -y"
115121
)
116122

117123
clean_cmd <- switch(
@@ -120,7 +126,8 @@ dock_from_renv <- function(
120126
centos8 = "yum clean all && rm -rf /var/cache/yum",
121127
xenial = "rm -rf /var/lib/apt/lists/*",
122128
bionic = "rm -rf /var/lib/apt/lists/*",
123-
focal = "rm -rf /var/lib/apt/lists/*"
129+
focal = "rm -rf /var/lib/apt/lists/*",
130+
jammy = "rm -rf /var/lib/apt/lists/*"
124131
)
125132

126133
pkgs <- names(lock$data()$Packages)
@@ -136,7 +143,7 @@ dock_from_renv <- function(
136143

137144
message(
138145
sprintf(
139-
"Fetching system dependencies for %s package records.",
146+
"Fetching system dependencies for %s package(s) records.",
140147
length(pkgs)
141148
)
142149
)
@@ -162,9 +169,13 @@ dock_from_renv <- function(
162169
.e = ~ character(0)
163170
)
164171

165-
pkg_installs <- unique(unlist(pkg_sysreqs))
166172

167-
if (length(pkg_installs) == 0) {
173+
174+
175+
176+
pkg_installs <- unique(pkg_sysreqs)
177+
178+
if (length(unlist(pkg_installs)) == 0) {
168179
cat_bullet(
169180
"No sysreqs required",
170181
bullet = "info",
@@ -179,36 +190,31 @@ dock_from_renv <- function(
179190

180191
# extra_sysreqs
181192

193+
194+
195+
182196
if (length(extra_sysreqs) > 0) {
183197
extra <- paste(
184198
install_cmd,
185199
extra_sysreqs
186200
)
187-
pkg_installs <- c(pkg_installs, extra)
201+
pkg_installs <- unique(c(pkg_installs, extra))
188202
}
189203

204+
205+
206+
207+
190208
# compact
191209
if (!expand) {
192210
# we compact sysreqs
193-
194-
compact <- paste(
195-
gsub(
196-
pkg_installs,
197-
pattern = install_cmd,
198-
replacement = ""
199-
),
200-
collapse = " "
211+
pkg_installs <- compact_sysreqs(
212+
pkg_installs,
213+
update_cmd = update_cmd,
214+
install_cmd = install_cmd,
215+
clean_cmd = clean_cmd
201216
)
202-
if (compact != "") {
203-
pkg_installs <- paste(
204-
update_cmd,
205-
"&&",
206-
install_cmd,
207-
compact,
208-
"&&",
209-
clean_cmd
210-
)
211-
}
217+
212218
} else {
213219
dock$RUN(update_cmd)
214220
}

man/compact_sysreqs.Rd

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
test_that("compact_sysreqs works", {
2+
pkg_installs <-
3+
list("apt-get install -y htop", "apt-get install -y top")
4+
expect_equal(
5+
compact_sysreqs(pkg_installs),
6+
"apt-get update -y && apt-get install -y htop top && rm -rf /var/lib/apt/lists/*"
7+
)
8+
})
9+
test_that("empty compact_sysreqs works", {
10+
pkg_installs <-
11+
list("")
12+
expect_equal(
13+
compact_sysreqs(pkg_installs),
14+
NULL
15+
)
16+
17+
pkg_installs <-
18+
NULL
19+
expect_equal(
20+
compact_sysreqs(pkg_installs),
21+
NULL
22+
)
23+
24+
25+
26+
27+
})
28+
29+
test_that("compact_sysreqs works with chromote", {
30+
pkg_installs <- list(character(0), character(0), character(0), character(0),
31+
character(0), "apt-get install -y make", character(0), c("[ $(which google-chrome) ] || apt-get install -y gnupg curl",
32+
"[ $(which google-chrome) ] || curl -fsSL -o /tmp/google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb",
33+
"[ $(which google-chrome) ] || DEBIAN_FRONTEND='noninteractive' apt-get install -y /tmp/google-chrome.deb",
34+
"apt-get install -y make libssl-dev libcurl4-openssl-dev"
35+
), character(0), character(0), character(0), character(0),
36+
character(0), "apt-get install -y libcurl4-openssl-dev libssl-dev",
37+
character(0), character(0), character(0), character(0), "apt-get install -y make",
38+
character(0), "apt-get install -y make zlib1g-dev", character(0),
39+
character(0), "apt-get install -y make zlib1g-dev", character(0),
40+
character(0), character(0), character(0), character(0), character(0),
41+
character(0), character(0), character(0), character(0), character(0),
42+
"apt-get install -y git", character(0), character(0), "apt-get install -y make",
43+
"apt-get install -y make zlib1g-dev", character(0), "apt-get install -y make libssl-dev",
44+
character(0), character(0), character(0))
45+
46+
47+
48+
expect_equal(
49+
compact_sysreqs(pkg_installs),
50+
c("apt-get update -y && apt-get install -y make libcurl4-openssl-dev libssl-dev zlib1g-dev git && rm -rf /var/lib/apt/lists/*",
51+
"apt-get update -y && [ $(which google-chrome) ] || apt-get install -y gnupg curl",
52+
"[ $(which google-chrome) ] || curl -fsSL -o /tmp/google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb",
53+
"[ $(which google-chrome) ] || DEBIAN_FRONTEND='noninteractive' apt-get install -y /tmp/google-chrome.deb",
54+
"apt-get install -y make libssl-dev libcurl4-openssl-dev && rm -rf /var/lib/apt/lists/*"
55+
)
56+
)
57+
})

0 commit comments

Comments
 (0)