diff --git a/R/add.R b/R/add.R index c463047..02e6c05 100644 --- a/R/add.R +++ b/R/add.R @@ -111,6 +111,11 @@ add_custom <- function(base, cmd) { glue("{base} {cmd}") } + +add_comment <- function(comment) { + paste0("# ", strsplit(comment, "\n")[[1]], collapse = "\n") +} + switch_them <- function(vec, a, b) { what <- vec[a] whbt <- vec[b] diff --git a/R/dockerfile.R b/R/dockerfile.R index a2f3f98..5f4af37 100644 --- a/R/dockerfile.R +++ b/R/dockerfile.R @@ -154,6 +154,13 @@ custom = function(base, cmd) { self$Dockerfile <- c(self$Dockerfile, add_custom(base, cmd)) }, #' @description +#' Add a comment. +#' @param comment The comment to add. +#' @return the Dockerfile object, invisibly. +COMMENT = function(comment) { +self$Dockerfile <- c(self$Dockerfile, add_comment(comment)) +}, +#' @description #' Print the Dockerfile. #' @return used for side effect print = function() { diff --git a/README.Rmd b/README.Rmd index a9ff00e..3de4b0f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -66,6 +66,12 @@ my_dock <- Dockerfile$new() my_dock$MAINTAINER("Colin FAY", "contact@colinfay.me") ``` +Add comments to your Dockerfile + +```{r} +my_dock$COMMENT("Install required R package.") +``` + Wrap your raw R Code inside the `r()` function to turn it into a bash command with `R -e`. ```{r} @@ -75,10 +81,12 @@ my_dock$RUN(r(install.packages("attempt", repo = "http://cran.irsn.fr/"))) Classical Docker stuffs: ```{r} +my_dock$COMMENT("Copy Plumber API and main script to container.") my_dock$RUN("mkdir /usr/scripts") my_dock$RUN("cd /usr/scripts") my_dock$COPY("plumberfile.R", "/usr/scripts/plumber.R") my_dock$COPY("torun.R", "/usr/scripts/torun.R") +my_dock$COMMENT("Expose the API port and run the main script when the container starts.") my_dock$EXPOSE(8000) my_dock$CMD("Rscript /usr/scripts/torun.R ") ``` diff --git a/README.md b/README.md index 3417e26..d6c693d 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,12 @@ my_dock <- Dockerfile$new() my_dock$MAINTAINER("Colin FAY", "contact@colinfay.me") ``` +Add comments to your Dockerfile + +``` r +my_dock$COMMENT("Install required R package.") +``` + Wrap your raw R Code inside the `r()` function to turn it into a bash command with `R -e`. @@ -70,10 +76,12 @@ my_dock$RUN(r(install.packages("attempt", repo = "http://cran.irsn.fr/"))) Classical Docker stuffs: ``` r +my_dock$COMMENT("Copy Plumber API and main script to container.") my_dock$RUN("mkdir /usr/scripts") my_dock$RUN("cd /usr/scripts") my_dock$COPY("plumberfile.R", "/usr/scripts/plumber.R") my_dock$COPY("torun.R", "/usr/scripts/torun.R") +my_dock$COMMENT("Expose the API port and run the main script when the container starts.") my_dock$EXPOSE(8000) my_dock$CMD("Rscript /usr/scripts/torun.R ") ``` diff --git a/man/Dockerfile.Rd b/man/Dockerfile.Rd index 9ab72aa..bd50c9d 100644 --- a/man/Dockerfile.Rd +++ b/man/Dockerfile.Rd @@ -40,6 +40,7 @@ my_dock <- Dockerfile$new() \item \href{#method-Dockerfile-SHELL}{\code{Dockerfile$SHELL()}} \item \href{#method-Dockerfile-MAINTAINER}{\code{Dockerfile$MAINTAINER()}} \item \href{#method-Dockerfile-custom}{\code{Dockerfile$custom()}} +\item \href{#method-Dockerfile-COMMENT}{\code{Dockerfile$COMMENT()}} \item \href{#method-Dockerfile-print}{\code{Dockerfile$print()}} \item \href{#method-Dockerfile-write}{\code{Dockerfile$write()}} \item \href{#method-Dockerfile-switch_cmd}{\code{Dockerfile$switch_cmd()}} @@ -441,6 +442,26 @@ the Dockerfile object, invisibly. } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Dockerfile-COMMENT}{}}} +\subsection{Method \code{COMMENT()}}{ +Add a comment. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Dockerfile$COMMENT(comment)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{comment}}{The comment to add.} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +the Dockerfile object, invisibly. +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Dockerfile-print}{}}} \subsection{Method \code{print()}}{ diff --git a/tests/testthat/test-r6.R b/tests/testthat/test-r6.R index f84bd17..bc0359a 100644 --- a/tests/testthat/test-r6.R +++ b/tests/testthat/test-r6.R @@ -45,6 +45,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$COMMENT("Just testing Dockerfile comments.") + expect_captured_length(my_dock, 18) my_dock <- Dockerfile$new(FROM = "plop") expect_match(my_dock$Dockerfile, "plop")