diff --git a/DESCRIPTION b/DESCRIPTION index 05c9ac2..67bf448 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,5 +20,5 @@ Suggests: rmarkdown Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.0 +RoxygenNote: 7.1.0 VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index 2ef645f..0c57b08 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # dockerfiler 0.1.3.9000 * Corrected bug in `rthis()` +* `add_arg` can now receive an optional default value (@antoine-sachet, #8) # dockerfiler 0.1.3 diff --git a/R/add.R b/R/add.R index d5bf57e..9081ad7 100644 --- a/R/add.R +++ b/R/add.R @@ -94,8 +94,9 @@ add_user <- function(user){ glue("USER {user}") } -add_arg <- function(arg){ - glue("ARG {arg}") +add_arg <- function(arg, default = NULL){ + default <- if (!is.null(default)) glue('="{default}"') else "" + glue("ARG {arg}{default}") } add_onbuild <- function(cmd){ diff --git a/R/dockerfile.R b/R/dockerfile.R index 31319a4..8434ef7 100644 --- a/R/dockerfile.R +++ b/R/dockerfile.R @@ -5,15 +5,15 @@ #' @section Methods: #' \describe{ #' \item{\code{RUN}}{add a RUN command} -#' \item{\code{ADD}}{add a ADD command} +#' \item{\code{ADD}}{add an ADD command with optional default value} #' \item{\code{COPY}}{add a COPY command} #' \item{\code{WORKDIR}}{add a WORKDIR command} #' \item{\code{EXPOSE}}{add an EXPOSE command} #' \item{\code{VOLUME}}{add a VOLUME command} #' \item{\code{CMD}}{add a CMD command} #' \item{\code{LABEL}}{add a LABEL command} -#' \item{\code{ENV}}{add a ENV command} -#' \item{\code{ENTRYPOINT}}{add a ENTRYPOINT command} +#' \item{\code{ENV}}{add an ENV command} +#' \item{\code{ENTRYPOINT}}{add an ENTRYPOINT command} #' \item{\code{VOLUME}}{add a VOLUME command} #' \item{\code{USER}}{add a USER command} #' \item{\code{ARG}}{add an ARG command} @@ -75,11 +75,11 @@ Dockerfile <- R6::R6Class("Dockerfile", USER = function(user){ self$Dockerfile <- c(self$Dockerfile, add_user(user)) }, - ARG = function(arg, ahead = FALSE){ + ARG = function(arg, ahead = FALSE, default = NULL){ if (ahead) { - self$Dockerfile <- c(add_arg(arg), self$Dockerfile) + self$Dockerfile <- c(add_arg(arg, default = default), self$Dockerfile) } else { - self$Dockerfile <- c(self$Dockerfile,add_arg(arg)) + self$Dockerfile <- c(self$Dockerfile, add_arg(arg, default = default)) } }, ONBUILD = function(cmd){ diff --git a/man/Dockerfile.Rd b/man/Dockerfile.Rd index fef954a..775c986 100644 --- a/man/Dockerfile.Rd +++ b/man/Dockerfile.Rd @@ -1,32 +1,29 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/dockerfile.R -\docType{data} \name{Dockerfile} \alias{Dockerfile} \title{A Dockerfile template} -\format{An object of class \code{R6ClassGenerator} of length 24.} -\usage{ -Dockerfile -} \value{ A dockerfile template } \description{ +A Dockerfile template + A Dockerfile template } \section{Methods}{ \describe{ \item{\code{RUN}}{add a RUN command} - \item{\code{ADD}}{add a ADD command} + \item{\code{ADD}}{add an ADD command with optional default value} \item{\code{COPY}}{add a COPY command} \item{\code{WORKDIR}}{add a WORKDIR command} \item{\code{EXPOSE}}{add an EXPOSE command} \item{\code{VOLUME}}{add a VOLUME command} \item{\code{CMD}}{add a CMD command} \item{\code{LABEL}}{add a LABEL command} - \item{\code{ENV}}{add a ENV command} - \item{\code{ENTRYPOINT}}{add a ENTRYPOINT command} + \item{\code{ENV}}{add an ENV command} + \item{\code{ENTRYPOINT}}{add an ENTRYPOINT command} \item{\code{VOLUME}}{add a VOLUME command} \item{\code{USER}}{add a USER command} \item{\code{ARG}}{add an ARG command} @@ -46,4 +43,267 @@ A Dockerfile template \examples{ my_dock <- Dockerfile$new() } -\keyword{datasets} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-new}{\code{Dockerfile$new()}} +\item \href{#method-RUN}{\code{Dockerfile$RUN()}} +\item \href{#method-ADD}{\code{Dockerfile$ADD()}} +\item \href{#method-COPY}{\code{Dockerfile$COPY()}} +\item \href{#method-WORKDIR}{\code{Dockerfile$WORKDIR()}} +\item \href{#method-EXPOSE}{\code{Dockerfile$EXPOSE()}} +\item \href{#method-VOLUME}{\code{Dockerfile$VOLUME()}} +\item \href{#method-CMD}{\code{Dockerfile$CMD()}} +\item \href{#method-LABEL}{\code{Dockerfile$LABEL()}} +\item \href{#method-ENV}{\code{Dockerfile$ENV()}} +\item \href{#method-ENTRYPOINT}{\code{Dockerfile$ENTRYPOINT()}} +\item \href{#method-USER}{\code{Dockerfile$USER()}} +\item \href{#method-ARG}{\code{Dockerfile$ARG()}} +\item \href{#method-ONBUILD}{\code{Dockerfile$ONBUILD()}} +\item \href{#method-STOPSIGNAL}{\code{Dockerfile$STOPSIGNAL()}} +\item \href{#method-HEALTHCHECK}{\code{Dockerfile$HEALTHCHECK()}} +\item \href{#method-SHELL}{\code{Dockerfile$SHELL()}} +\item \href{#method-MAINTAINER}{\code{Dockerfile$MAINTAINER()}} +\item \href{#method-custom}{\code{Dockerfile$custom()}} +\item \href{#method-print}{\code{Dockerfile$print()}} +\item \href{#method-write}{\code{Dockerfile$write()}} +\item \href{#method-switch_cmd}{\code{Dockerfile$switch_cmd()}} +\item \href{#method-remove_cmd}{\code{Dockerfile$remove_cmd()}} +\item \href{#method-add_after}{\code{Dockerfile$add_after()}} +\item \href{#method-clone}{\code{Dockerfile$clone()}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-new}{}}} +\subsection{Method \code{new()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$new(FROM = "rocker/r-base", AS = NULL)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-RUN}{}}} +\subsection{Method \code{RUN()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$RUN(cmd)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ADD}{}}} +\subsection{Method \code{ADD()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$ADD(from, to, force = TRUE)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-COPY}{}}} +\subsection{Method \code{COPY()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$COPY(from, to, force = TRUE)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-WORKDIR}{}}} +\subsection{Method \code{WORKDIR()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$WORKDIR(where)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-EXPOSE}{}}} +\subsection{Method \code{EXPOSE()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$EXPOSE(port)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-VOLUME}{}}} +\subsection{Method \code{VOLUME()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$VOLUME(volume)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-CMD}{}}} +\subsection{Method \code{CMD()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$CMD(cmd)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LABEL}{}}} +\subsection{Method \code{LABEL()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$LABEL(key, value)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ENV}{}}} +\subsection{Method \code{ENV()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$ENV(key, value)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ENTRYPOINT}{}}} +\subsection{Method \code{ENTRYPOINT()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$ENTRYPOINT(cmd)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-USER}{}}} +\subsection{Method \code{USER()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$USER(user)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ARG}{}}} +\subsection{Method \code{ARG()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$ARG(arg, ahead = FALSE, default = NULL)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ONBUILD}{}}} +\subsection{Method \code{ONBUILD()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$ONBUILD(cmd)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-STOPSIGNAL}{}}} +\subsection{Method \code{STOPSIGNAL()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$STOPSIGNAL(signal)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-HEALTHCHECK}{}}} +\subsection{Method \code{HEALTHCHECK()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$HEALTHCHECK(check)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-SHELL}{}}} +\subsection{Method \code{SHELL()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$SHELL(shell)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-MAINTAINER}{}}} +\subsection{Method \code{MAINTAINER()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$MAINTAINER(name, email)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-custom}{}}} +\subsection{Method \code{custom()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$custom(base, cmd)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-print}{}}} +\subsection{Method \code{print()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$print()}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-write}{}}} +\subsection{Method \code{write()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$write(as = "Dockerfile")}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-switch_cmd}{}}} +\subsection{Method \code{switch_cmd()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$switch_cmd(a, b)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-remove_cmd}{}}} +\subsection{Method \code{remove_cmd()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$remove_cmd(where)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-add_after}{}}} +\subsection{Method \code{add_after()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$add_after(cmd, after)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/dock_from_desc.Rd b/man/dock_from_desc.Rd index c8f9f8e..c8ec692 100644 --- a/man/dock_from_desc.Rd +++ b/man/dock_from_desc.Rd @@ -4,8 +4,7 @@ \alias{dock_from_desc} \title{Docker file from DESCRIPTION} \usage{ -dock_from_desc(path = "DESCRIPTION", FROM = "rocker/r-base", - AS = NULL) +dock_from_desc(path = "DESCRIPTION", FROM = "rocker/r-base", AS = NULL) } \arguments{ \item{path}{Path to DESCRIPTION} @@ -35,7 +34,7 @@ my_dock <- dock_from_desc("DESCRIPTION") my_dock my_dock$CMD(r(library(dockerfiler))) my_dock$add_after( -cmd = "RUN R -e 'remotes::install_cran(\\"rlang\\")'", +cmd = "RUN R -e 'remotes::install_cran(\"rlang\")'", after = 3 ) } diff --git a/tests/testthat/test-r6.R b/tests/testthat/test-r6.R index 30f08de..d4fefd2 100644 --- a/tests/testthat/test-r6.R +++ b/tests/testthat/test-r6.R @@ -30,7 +30,7 @@ test_that("R6 creation works", { expect_captured_length(my_dock, 11) my_dock$USER("plop /usr/scripts") expect_captured_length(my_dock, 12) - my_dock$ARG("plop /usr/scripts") + my_dock$ARG("plop") expect_captured_length(my_dock, 13) my_dock$ONBUILD("plop /usr/scripts") expect_captured_length(my_dock, 14) @@ -46,6 +46,8 @@ test_that("R6 creation works", { expect_captured_length(my_dock, 17) my_dock$switch_cmd(5,6) expect_captured_length(my_dock, 17) + my_dock$ARG("plop", default = "pouet") + expect_captured_length(my_dock, 18) my_dock <- Dockerfile$new(FROM = "plop") expect_match(my_dock$Dockerfile, "plop") my_dock <- Dockerfile$new(FROM = "plop", AS = "pouet")