Create a Dockerfile from a DESCRIPTION
Usage
dock_from_desc(
path = "DESCRIPTION",
FROM = paste0("rocker/r-ver:", R.Version()$major, ".", R.Version()$minor),
AS = NULL,
sysreqs = TRUE,
repos = c(CRAN = "https://p3m.dev/cran/latest"),
expand = FALSE,
update_tar_gz = TRUE,
build_from_source = TRUE,
extra_sysreqs = NULL,
github_pat = c("none", "build_arg", "secret"),
strict_install = TRUE
)Arguments
- path
path to the DESCRIPTION file to use as an input.
- FROM
The FROM of the Dockerfile. Default is
paste0("rocker/r-ver:", R.Version()$major, ".", R.Version()$minor). Validated as a Docker image reference (alphanumerics, dot, slash, dash, underscore, optional:tagand / or@sha256:<hex>); other values raise an error to prevent shell-metacharacter injection into the generated FROM directive.- AS
The build-stage name of the Dockerfile (
FROM ... AS <name>). Default isNULL(noAS). When non-NULL, validated as a simple build-stage name (^[a-zA-Z0-9][a-zA-Z0-9._-]*$).- sysreqs
boolean. If TRUE, the Dockerfile will contain sysreq installation.
- repos
character. The URL(s) of the repositories to use for
options("repos"). Default isc(CRAN = "https://p3m.dev/cran/latest")(Posit Public Package Manager). Whenreposis a singleCRAN-keyed PPM URL (packagemanager.posit.co,packagemanager.rstudio.com, orp3m.dev), the codegen rewrites it to the__linux__/$VERSION_CODENAME/shape (codename resolved from/etc/os-releaseat image build time) and adds the strictHTTPUserAgentPPM requires, so the build pulls pre-compiled Linux binaries instead of compiling from source. Pass the legacyc(CRAN = "https://cran.rstudio.com/")to opt out. Each value must look like an http(s) URL (no quotes, spaces or newlines); each name (when set) must be a simple identifier (^[A-Za-z][A-Za-z0-9._-]*$). Other values raise an error to prevent injection into the generatedecho "options(...)"shell command.- expand
boolean. If
TRUEeach system requirement will have its ownRUNline.- update_tar_gz
boolean. If
TRUEandbuild_from_sourceis alsoTRUE, an updated tar.gz is created.- build_from_source
boolean. If
TRUEno tar.gz is created and the Dockerfile directly mount the source folder.- extra_sysreqs
character vector. Extra debian system requirements. Will be installed with apt-get install. Each entry must be a Debian package name (
^[a-z0-9][a-z0-9.+-]+$); other values raise an error to prevent injection into the generated apt-get RUN.- github_pat
character. How to provide a GitHub PAT to
remotes::install_github()for private dependency repositories. One of"none"(default; the generated Dockerfile does not reference any PAT),"build_arg"(emitARG GITHUB_PAT+ENVpropagation; pass with--build-arg GITHUB_PAT=$GITHUB_PAT; the PAT will be visible in the image metadata), or"secret"(BuildKit secret mount on eachinstall_github()/install_local()RUN; the PAT is never persisted in the image; requires BuildKit, so pass withDOCKER_BUILDKIT=1 docker build --secret id=github_pat,env=GITHUB_PAT ...).- strict_install
boolean. When
TRUE(the default), every install RUN in the generated Dockerfile is prefixed withoptions(warn = 2);so that any R warning during install (missing CRAN package, partial download, archived package, 404 on a remote) becomes a hard error and aborts the docker build. Set toFALSEif your build environment routinely emits benign warnings (locale defaulting, NTP time-verification, ABI-version notices) that you do not want to fail the build. Must be a single scalar logical;NA, character, numeric,NULLand length-2+ vectors are rejected with an error.
Details
Two install strategies are available for the package itself:
build_from_source = TRUE(the default): the generated Dockerfile mounts the source folder and installs from it directly.update_tar_gzis ignored.build_from_source = FALSE: a source tarball (<pkg>_<version>.tar.gz) isCOPY'd into the image and installed withremotes::install_local(). Whenupdate_tar_gz = TRUE, a fresh tarball is built withpkgbuild::build()first (and any stale<pkg>_*.tar.gzin the current directory is removed); whenupdate_tar_gz = FALSE, an already-built tarball is expected alongside theDESCRIPTION.
The package name and its dependency-field names are read from the
DESCRIPTION and validated against the CRAN package-name grammar
before being interpolated into the generated directives.
Examples
if (FALSE) { # \dontrun{
# From the DESCRIPTION of the package in the working directory:
dock <- dock_from_desc("DESCRIPTION")
dock
# Pull source packages from the classic CRAN mirror instead of PPM:
dock_from_desc(
"DESCRIPTION",
repos = c(CRAN = "https://cran.rstudio.com/")
)
} # }