diff --git a/DESCRIPTION b/DESCRIPTION index 131ab1a..92bc449 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dockerfiler Title: Easy Dockerfile Creation from R -Version: 0.2.4 +Version: 0.2.4.9000 Authors@R: c( person("Colin", "Fay", , "contact@colinfay.me", role = c("cre", "aut"), comment = c(ORCID = "0000-0001-7343-1846")), diff --git a/NEWS.md b/NEWS.md index 86c778c..19cac5e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# dockerfiler 0.2.4.9xxx + +- allow multistage dockerfile creation + # dockerfiler 0.2.4 - remove native pipe thanks to @HenningLorenzen-ext-bayer, this enable to use of older R versions diff --git a/R/add.R b/R/add.R index c463047..dc45369 100644 --- a/R/add.R +++ b/R/add.R @@ -31,19 +31,22 @@ add_add <- function( glue("ADD {from} {to}") } -add_copy <- function( - from, - to, - force = TRUE -) { +add_copy <- function(from, + to, + stage = NULL, + force = TRUE) { if (!force) { - warn_if_not( - normalizePath(from), - file.exists, - "The file `from` doesn't seem to exists" - ) + warn_if_not(normalizePath(from), + file.exists, + "The file `from` doesn't seem to exists") + } + + if (is.null(stage)) { + glue("COPY {from} {to}") + } else { + glue("COPY --from={stage} {from} {to}") + } - glue("COPY {from} {to}") } add_workdir <- function(where) { diff --git a/R/dockerfile.R b/R/dockerfile.R index a2f3f98..2c291b3 100644 --- a/R/dockerfile.R +++ b/R/dockerfile.R @@ -39,9 +39,10 @@ self$Dockerfile <- c(self$Dockerfile, add_add(from, to, force)) #' @param from The source file. #' @param to The destination file. #' @param force If TRUE, overwrite the destination file. +#' @param stage Optional. Name of the build stage (e.g., `"builder"`) to copy files from. This corresponds to the `--from=` part in a Dockerfile COPY instruction (e.g., `COPY --from=builder /source /dest`). If `NULL`, the `--from=` argument is omitted. #' @return the Dockerfile object, invisibly. -COPY = function(from, to, force = TRUE) { -self$Dockerfile <- c(self$Dockerfile, add_copy(from, to, force)) +COPY = function(from, to, stage= NULL , force = TRUE) { +self$Dockerfile <- c(self$Dockerfile, add_copy(from, to, stage, force)) }, #' @description #' Add a WORKDIR command. @@ -162,9 +163,10 @@ cat(self$Dockerfile, sep = "\n") #' @description #' Write the Dockerfile to a file. #' @param as The file to write to. +#' @param append boolean, if TRUE append to file. #' @return used for side effect -write = function(as = "Dockerfile") { -base::write(self$Dockerfile, file = as) +write = function(as = "Dockerfile", append = FALSE) { +base::write(self$Dockerfile, file = as, append = append) }, #' @description #' Switch commands. diff --git a/man/Dockerfile.Rd b/man/Dockerfile.Rd index 9ab72aa..390a5f3 100644 --- a/man/Dockerfile.Rd +++ b/man/Dockerfile.Rd @@ -120,7 +120,7 @@ the Dockerfile object, invisibly. \subsection{Method \code{COPY()}}{ Add a COPY command. \subsection{Usage}{ -\if{html}{\out{