Skip to content

Commit 77450cc

Browse files
Task 3 - Feature: Add COMMENT (#81)
* Task 3 - Feature: Add COMMENT * Adding comment ending dot * Fixed newlines in COMMENT
1 parent a2bf4f6 commit 77450cc

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

R/add.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ add_custom <- function(base, cmd) {
114114
glue("{base} {cmd}")
115115
}
116116

117+
118+
add_comment <- function(comment) {
119+
paste0("# ", strsplit(comment, "\n")[[1]], collapse = "\n")
120+
}
121+
117122
switch_them <- function(vec, a, b) {
118123
what <- vec[a]
119124
whbt <- vec[b]

R/dockerfile.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ custom = function(base, cmd) {
155155
self$Dockerfile <- c(self$Dockerfile, add_custom(base, cmd))
156156
},
157157
#' @description
158+
#' Add a comment.
159+
#' @param comment The comment to add.
160+
#' @return the Dockerfile object, invisibly.
161+
COMMENT = function(comment) {
162+
self$Dockerfile <- c(self$Dockerfile, add_comment(comment))
163+
},
164+
#' @description
158165
#' Print the Dockerfile.
159166
#' @return used for side effect
160167
print = function() {

README.Rmd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ my_dock <- Dockerfile$new()
6666
my_dock$MAINTAINER("Colin FAY", "[email protected]")
6767
```
6868

69+
Add comments to your Dockerfile
70+
71+
```{r}
72+
my_dock$COMMENT("Install required R package.")
73+
```
74+
6975
Wrap your raw R Code inside the `r()` function to turn it into a bash command with `R -e`.
7076

7177
```{r}
@@ -75,10 +81,12 @@ my_dock$RUN(r(install.packages("attempt", repo = "http://cran.irsn.fr/")))
7581
Classical Docker stuffs:
7682

7783
```{r}
84+
my_dock$COMMENT("Copy Plumber API and main script to container.")
7885
my_dock$RUN("mkdir /usr/scripts")
7986
my_dock$RUN("cd /usr/scripts")
8087
my_dock$COPY("plumberfile.R", "/usr/scripts/plumber.R")
8188
my_dock$COPY("torun.R", "/usr/scripts/torun.R")
89+
my_dock$COMMENT("Expose the API port and run the main script when the container starts.")
8290
my_dock$EXPOSE(8000)
8391
my_dock$CMD("Rscript /usr/scripts/torun.R ")
8492
```

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ my_dock <- Dockerfile$new()
6060
my_dock$MAINTAINER("Colin FAY", "[email protected]")
6161
```
6262

63+
Add comments to your Dockerfile
64+
65+
``` r
66+
my_dock$COMMENT("Install required R package.")
67+
```
68+
6369
Wrap your raw R Code inside the `r()` function to turn it into a bash
6470
command with `R -e`.
6571

@@ -70,10 +76,12 @@ my_dock$RUN(r(install.packages("attempt", repo = "http://cran.irsn.fr/")))
7076
Classical Docker stuffs:
7177

7278
``` r
79+
my_dock$COMMENT("Copy Plumber API and main script to container.")
7380
my_dock$RUN("mkdir /usr/scripts")
7481
my_dock$RUN("cd /usr/scripts")
7582
my_dock$COPY("plumberfile.R", "/usr/scripts/plumber.R")
7683
my_dock$COPY("torun.R", "/usr/scripts/torun.R")
84+
my_dock$COMMENT("Expose the API port and run the main script when the container starts.")
7785
my_dock$EXPOSE(8000)
7886
my_dock$CMD("Rscript /usr/scripts/torun.R ")
7987
```

man/Dockerfile.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-r6.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ test_that("R6 creation works", {
4545
expect_captured_length(my_dock, 17)
4646
my_dock$switch_cmd(5, 6)
4747
expect_captured_length(my_dock, 17)
48+
my_dock$COMMENT("Just testing Dockerfile comments.")
49+
expect_captured_length(my_dock, 18)
4850

4951
my_dock <- Dockerfile$new(FROM = "plop")
5052
expect_match(my_dock$Dockerfile, "plop")

0 commit comments

Comments
 (0)