Wrapper function around other pracpac
functions. See help for the functions linked below for detail on individual functions.
All arguments to use_docker()
are passed to downstream functions. use_docker()
will sequentially run:
pkg_info to get information about the current R package.
create_docker_dir to create the
docker/
directory in the specified location, if it doesn't already exist.renv_deps (if
use_renv=TRUE
, the default) to capture package dependencies with renv and create anrenv.lock
fileadd_dockerfile to create a Dockerfile using template specified by
use_case
add_assets depending on the
use_case
build_pkg to build the current R package source .tar.gz, and place it into the
docker/
directorybuild_image optional, default
FALSE
; if TRUE, will build the Docker image.
The default build=FALSE
means that everything up to build_image()
is run,
but the image is not actually built. Instead, use_docker()
will message the
docker build
command, and return that string in $buildcmd
in the
invisibly returned output.
See vignette("use-cases", package="pracpac")
for details on use cases.
Usage
use_docker(
pkg_path = ".",
img_path = NULL,
use_renv = TRUE,
use_case = "default",
base_image = NULL,
other_packages = NULL,
build = FALSE,
repos = NULL,
overwrite_assets = TRUE,
overwrite_renv = TRUE,
consent_renv = TRUE
)
Arguments
- pkg_path
Path to the package directory. Default is
"."
for the current working directory, which assumes developer is working in R package root. However, this can be set to another path as needed.- img_path
Path to the write the docker image definition contents. The default
NULL
will usedocker/
as a subdirectory of thepkg_path
.- use_renv
Logical; use renv? Defaults to
TRUE
. IfFALSE
, package dependencies are scraped from theDESCRIPTION
file without version information.- use_case
Name of the use case. Defaults to
"default"
, which only uses the base boilerplate.- base_image
Name of the base image to start
FROM
. Default isNULL
and the base image will be derived based onuse_case
. Optionally override this by setting the name of the base image (including tag if desired).- other_packages
Vector of other packages to be included in
renv
lock file; default isNULL
.- build
Logical as to whether or not the image should be built. Default is
TRUE
, and ifFALSE
thedocker build
command will be messaged. Settingbuild=FALSE
could be useful if additionaldocker build
options or different tags are desired. In either case thedocker build
command will be returned invisibly.- repos
Option to override the repos used for installing packages with
renv
by passing name of repository. Only used ifuse_renv = TRUE
. Default isNULL
meaning that the repos specified inrenv
lockfile will remain as-is and not be overridden.- overwrite_assets
Logical; should existing asset files should be overwritten? Default is
TRUE
.- overwrite_renv
Logical; should an existing lock file should be overwritten? Default is
TRUE
; ignored ifuse_renv = TRUE
.- consent_renv
Logical; give renv consent in this session with
options(renv.consent = TRUE)
? Default isTRUE
. See renv::consent for details.
Value
Invisibly returns a list with information about the package ($info
) and
the docker build
command ($buildcmd
). Primarily called for side effect.
Creates docker/
directory, identifies renv dependencies and creates lock
file (if use_renv = TRUE
), writes Dockerfile, builds package tar.gz,
moves all relevant assets to the docker/
directory, and builds Docker
image (if build = TRUE
).
Examples
if (FALSE) {
# Specify path to example package source and copy to tempdir()
# Note that in practice you do not need to copy to a tempdir()
# And in fact it may be easiest to use pracpac relative to your package directory root
ex_pkg_src <- system.file("hellow", package = "pracpac", mustWork = TRUE)
file.copy(from = ex_pkg_src, to = tempdir(), recursive = TRUE)
# Run use_docker to create Docker directory and assets for the example package
use_docker(pkg_path = file.path(tempdir(), "hellow"))
# To not use renv
use_docker(pkg_path = file.path(tempdir(), "hellow"), use_renv=FALSE)
# To specify a use case
use_docker(pkg_path = file.path(tempdir(), "hellow"), use_case="pipeline")
# To overwrite the default base image
use_docker(pkg_path = file.path(tempdir(), "hellow"), base_image="alpine:latest")
}