Skip to content

Commit 7a137bc

Browse files
feat: drop vendored renv, parse lockfiles with jsonlite (#94) (#97)
* feat: drop vendored renv, parse lockfiles with jsonlite (#94) Removes the ~30,000-line vendored copy of renv 1.0.3 (in inst/vendor/renv.R) and the bootstrap shell (R/renv.R, ~90 lines). The full renv toolkit was embedded for one runtime use only: renv$lockfile_read(). It is replaced by jsonlite::read_json() which already lives in Imports and produces the same structure for the fields dockerfiler reads (R$Version, names(Packages), Packages$<name>$Version). Public API change: the exported dockerfiler::renv data symbol is removed. Documented as @doctype data in 0.2.5; users who relied on it (unlikely outside of dockerfiler tests) should switch to renv:: directly. Behaviour change in the missing(renv_version) + lockfile-without-renv case: the previous fallback was the vendored 1.0.3 (frozen 2023-11), which produced remotes::install_version("renv", version = "1.0.3") in the generated Dockerfile. The new fallback is NULL, which now emits install.packages("renv") and pulls the latest renv from the configured repos. This aligns with the existing renv_version = NULL behaviour and avoids shipping increasingly stale renv builds. Tests use renv::snapshot() via Suggests + skip_if_not_installed guard. The "missing" assertion for the unpinned-renv lockfile now expects install.packages("renv") instead of install_version 1.0.3. Side effect: the inline-R in roxygen (`r dockerfiler::renv$initialize();...`) goes away, eliminating the attachment::att_amend_desc() regeneration trap on man/dock_from_renv.Rd. Closes #94. * fix(message): typo "the must" -> "the most up to date version" Address self-review nit on PR #97. Pre-existing typo in the `message("renv version = ", ...)` displayed when renv_version is NULL. Now fires more often since the unpinned-renv-in-lockfile path also lands here, so worth fixing. * release: bump to 0.3.0 The vendored-renv removal is a breaking change (the exported `dockerfiler::renv` symbol is dropped), so bump to 0.3.0 and split the development NEWS section into Breaking changes / New features / Bug fixes per tidyverse convention.
1 parent a18620d commit 7a137bc

9 files changed

Lines changed: 69 additions & 33601 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 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.6
3+
Version: 0.3.0
44
Authors@R: c(
55
person("Colin", "Fay", , "contact@colinfay.me", role = c("cre", "aut"),
66
comment = c(ORCID = "0000-0001-7343-1846")),
@@ -34,6 +34,7 @@ Imports:
3434
utils
3535
Suggests:
3636
knitr (>= 1.31),
37+
renv,
3738
rmarkdown (>= 2.6),
3839
testthat (>= 3.0.0),
3940
withr

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export(docker_ignore_add)
88
export(get_sysreqs)
99
export(parse_dockerfile)
1010
export(r)
11-
export(renv)
1211
importFrom(R6,R6Class)
1312
importFrom(attempt,map_try_catch)
1413
importFrom(attempt,warn_if_not)

NEWS.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
1-
# dockerfiler (development version)
1+
# dockerfiler 0.3.0
22

3-
- fix: `r()` no longer silently rewrites user code. The previous
3+
## Breaking changes
4+
5+
- The vendored copy of `{renv}` (~30,000 lines under `inst/vendor/`)
6+
is removed. Lockfiles are now parsed with `jsonlite::read_json()`
7+
(already in Imports). The exported `dockerfiler::renv` symbol is
8+
removed: it was a public-API surface only because the vendor pattern
9+
required it. The fallback `renv_version` value, when both the user
10+
argument is missing and the lockfile does not pin renv, is now
11+
`NULL` (install the latest renv from the configured repos), aligned
12+
with the existing `renv_version = NULL` behaviour. Closes #94.
13+
14+
## New features
15+
16+
- `dock$ARG()` and the internal `add_arg()` helper gain a `default`
17+
parameter to emit `ARG <name>=<default>` instead of `ARG <name>`.
18+
Closes #8.
19+
- `dock_from_desc()` and `dock_from_renv()` gain a `github_pat`
20+
parameter (default `"none"`) controlling how a GitHub PAT is provided
21+
to `remotes::install_github()` / `remotes::install_local()` /
22+
`renv::restore()` for private dependency repositories. Set to
23+
`"build_arg"` to emit `ARG GITHUB_PAT` + `ENV` propagation (passed
24+
via `--build-arg GITHUB_PAT=$GITHUB_PAT`), or `"secret"` to use
25+
BuildKit secret mounts (the PAT is never persisted in image
26+
metadata; recommended for published images). Closes #18.
27+
- `dock_from_renv()` gains a `renv_paths_cache` parameter (default
28+
`/root/.cache/R/renv`) used as the build-arg default, the propagated
29+
`ENV` value and the cache mount target. Users can override the renv
30+
cache location at image build time with
31+
`--build-arg RENV_PATHS_CACHE=...` without regenerating the
32+
Dockerfile.
33+
34+
## Bug fixes
35+
36+
- `r()` no longer silently rewrites user code. The previous
437
implementation called `gsub(" [2,]", " ", code)` (a typo for
538
`{2,}`) which deleted any digit `2` or comma preceded by a space:
639
`r(c(1, 2, 3))` returned `R -e 'c(1, , 3)'`. The replacement
@@ -10,36 +43,19 @@
1043
line then `paste(collapse = " ")`: only the line-wrap indentation
1144
added by `deparse()` is removed, internal whitespace is preserved.
1245
Closes #95.
13-
- fix: `r()` now wraps the deparsed R expression with
46+
- `r()` now wraps the deparsed R expression with
1447
`shQuote(., type = "sh")` instead of inlining it inside a hand-rolled
1548
single-quoted shell string. Apostrophes inside string literals no
1649
longer break the emitted command: `r(message("don't"))` used to emit
1750
`R -e 'message("don't")'`, which the shell refuses to parse
1851
(unterminated quoted string). The new wrapping is shell-safe by
1952
construction.
20-
- fix: `dock_from_desc(build_from_source = FALSE)` no longer carries
53+
- `dock_from_desc(build_from_source = FALSE)` no longer carries
2154
a dead-code branch (`if (missing(out))`) on the locally-assigned
2255
result of `pkgbuild::build()`. `missing()` only reports unsupplied
2356
function arguments, so the branch was unreachable; the success path
2457
always ran when `build()` returned. The branch is removed; failures
2558
of `pkgbuild::build()` propagate normally via `stop()`. Closes #98.
26-
- `dock$ARG()` and the internal `add_arg()` helper gain a `default`
27-
parameter to emit `ARG <name>=<default>` instead of `ARG <name>`.
28-
Closes #8.
29-
- `dock_from_desc()` and `dock_from_renv()` gain a `github_pat`
30-
parameter (default `"none"`) controlling how a GitHub PAT is provided
31-
to `remotes::install_github()` / `remotes::install_local()` /
32-
`renv::restore()` for private dependency repositories. Set to
33-
`"build_arg"` to emit `ARG GITHUB_PAT` + `ENV` propagation (passed
34-
via `--build-arg GITHUB_PAT=$GITHUB_PAT`), or `"secret"` to use
35-
BuildKit secret mounts (the PAT is never persisted in image
36-
metadata; recommended for published images). Closes #18.
37-
- `dock_from_renv()` gains a `renv_paths_cache` parameter (default
38-
`/root/.cache/R/renv`) used as the build-arg default, the propagated
39-
`ENV` value and the cache mount target. Users can override the renv
40-
cache location at image build time with
41-
`--build-arg RENV_PATHS_CACHE=...` without regenerating the
42-
Dockerfile.
4359

4460

4561
# dockerfiler 0.2.6

R/dock_from_renv.R

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ pkg_sysreqs_mem <- memoise::memoise(
1919
#' Will be installed with apt-get install.
2020
#' @param renv_version character. The renv version to use in the generated Dockerfile. By default, it is set to the version specified in the `renv.lock` file.
2121
#' If the `renv.lock` file does not specify a renv version,
22-
#' the version of renv bundled with dockerfiler,
23-
#' specifically `r dockerfiler::renv$initialize();toString(dockerfiler::renv$the$metadata$version)`, will be used.
24-
#' If you set it to `NULL`, the latest available version of renv will be used.
22+
#' the latest available version of renv will be installed.
23+
#' Set it to `NULL` to force installing the latest renv even when the
24+
#' lockfile pins a specific version.
2525
#' @param use_pak boolean. If `TRUE` use pak to deal with dependencies during `renv::restore()`. FALSE by default
2626
#' @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.
2727
#' @param dependencies What kinds of dependencies to install. Most commonly
@@ -88,9 +88,12 @@ dock_from_renv <- function(
8888
renv_paths_cache = "/root/.cache/R/renv"
8989
) {
9090
github_pat <- match.arg(github_pat)
91-
try(dockerfiler::renv$initialize(),silent=TRUE)
92-
lock <- dockerfiler::renv$lockfile_read(file = lockfile) # using vendored renv
93-
# https://rstudio.github.io/renv/reference/vendor.html?q=vendor#null
91+
lock <- jsonlite::read_json(
92+
lockfile,
93+
simplifyVector = TRUE,
94+
simplifyDataFrame = FALSE,
95+
simplifyMatrix = FALSE
96+
)
9497

9598
# start the dockerfile
9699
R_major_minor <- lock$R$Version
@@ -110,15 +113,11 @@ dock_from_renv <- function(
110113
# get renv version
111114

112115
if (missing(renv_version)) {
113-
if (!is.null(lock$Packages$renv$Version)) {
114-
renv_version <- lock$Packages$renv$Version
115-
} else {
116-
renv_version <- dockerfiler::renv$the$metadata$version
117-
}
116+
renv_version <- lock$Packages$renv$Version
118117
}
119118

120119
message("renv version = ",
121-
ifelse(!is.null(renv_version),renv_version,"the must up to date in the repos")
120+
ifelse(!is.null(renv_version), renv_version, "the most up to date version in the repos")
122121
)
123122

124123

R/renv.R

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)