-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add Dockerfile parser (#55) * add Dockerfile parser * add parsing test * add flag to dock_from_renv function (#60) * add keep_renv_version flag to dock_from_renv function and associated test * fixed typo * Update dock_from_renv.R * improve dock_from_renv * flat_ file correction * it's always a typo --------- Co-authored-by: Josiah Parry <[email protected]> Co-authored-by: Adam J Campbell <[email protected]>
- Loading branch information
1 parent
9008908
commit 2984727
Showing
16 changed files
with
679 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: dockerfiler | ||
Title: Easy Dockerfile Creation from R | ||
Version: 0.2.1.9002 | ||
Version: 0.2.1.9003 | ||
Authors@R: c( | ||
person("Colin", "Fay", , "[email protected]", role = c("cre", "aut"), | ||
comment = c(ORCID = "0000-0001-7343-1846")), | ||
|
@@ -36,8 +36,9 @@ Suggests: | |
rmarkdown (>= 2.6), | ||
testthat (>= 3.0.0), | ||
withr | ||
VignetteBuilder: | ||
VignetteBuilder: | ||
knitr | ||
Config/fusen/version: 0.5.2.9000 | ||
Config/testthat/edition: 3 | ||
Encoding: UTF-8 | ||
LazyData: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# WARNING - Generated by {fusen} from dev/flat_dock_from_renv.Rmd: do not edit by hand | ||
|
||
#' Generate base image name | ||
#' | ||
#' Creates the base image name from the provided distro name and the R version found in the `renv.lock` file. | ||
#' | ||
#' @keywords internal | ||
#' @noRd | ||
gen_base_image <- function( | ||
distro = "bionic", | ||
r_version = "4.0", | ||
FROM = "rstudio/r-base" | ||
) { | ||
distro <- match.arg(distro, available_distros) | ||
|
||
if (FROM == "rstudio/r-base") { | ||
glue::glue("{FROM}:{r_version}-{distro}") | ||
} else { | ||
glue::glue("{FROM}:{r_version}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
#' Parse a Dockerfile | ||
#' | ||
#' Create a Dockerfile object from a Dockerfile. | ||
#' | ||
#' @param path path to the Dockerfile | ||
#' @returns A Dockerfile object | ||
#' @export | ||
#' @examples | ||
#' parse_dockerfile(system.file("Dockerfile", package = "dockerfiler")) | ||
#' | ||
parse_dockerfile <- function(path) { | ||
|
||
# note that MAINTAINER is deprecated but there | ||
# for backwards compatability | ||
DOCKER_INSTRUCTIONS <- c( | ||
"#", # for detecting comments | ||
# "^$", # to capture empty lines | ||
"FROM", "RUN", "CMD", "EXPOSE", "LABEL", "MAINTAINER", "EXPOSE", "ENV", "ADD", "COPY", "ENTRYPOINT", "VOLUME", "USER", "WORKDIR", "ARG", "ONBUILD", "STOPSIGNAL", "HEALTHCHECK", "SHELL") | ||
|
||
instruction_regex <- paste0(DOCKER_INSTRUCTIONS, collapse = "|") | ||
|
||
# read the dockerfile | ||
dock_raw <- readLines(path) | ||
# capture instructions | ||
m <- gregexpr(paste0("^", instruction_regex), dock_raw) | ||
# extract the instruction | ||
instructions <- unlist(lapply(regmatches(dock_raw, m), `[`, 1)) | ||
# find positions | ||
instr_pos <- which(!is.na(instructions)) | ||
# find how many lines between instructions and last line | ||
n_lines_between <- diff(c(instr_pos, length(dock_raw))) - 1 | ||
# the last one needs to add 1 | ||
n_lines_between[length(n_lines_between)] <- n_lines_between[length(n_lines_between)] + 1 | ||
|
||
dock_lines <- find_line_positions(dock_raw, instr_pos, instr_pos + n_lines_between) | ||
|
||
res <- Dockerfile$new() | ||
res$Dockerfile <- dock_lines | ||
res | ||
} | ||
|
||
# helper function to craft commands | ||
find_line_positions <- function(x, start, end) { | ||
indexes <- Map(seq.int, start, end, by = 1) | ||
cmnds <- lapply(indexes, function(.x) x[.x]) | ||
vapply(cmnds, paste0, character(1), collapse = "\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
flat_dock_from_renv.Rmd: | ||
path: dev/flat_dock_from_renv.Rmd | ||
state: active | ||
R: | ||
- R/dock_from_renv.R | ||
- R/gen_base_image.R | ||
tests: tests/testthat/test-dock_from_renv.R | ||
vignettes: vignettes/dockerfile-from-renv-lock.Rmd | ||
inflate: | ||
flat_file: dev/flat_dock_from_renv.Rmd | ||
vignette_name: Dockerfile from renv.lock | ||
open_vignette: false | ||
check: false | ||
document: true | ||
overwrite: 'yes' |
Oops, something went wrong.