Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 3 - Feature: Add COMMENT #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ add_custom <- function(base, cmd) {
glue("{base} {cmd}")
}


add_comment <- function(comment) {
glue("# {comment}")
}

switch_them <- function(vec, a, b) {
what <- vec[a]
whbt <- vec[b]
Expand Down
7 changes: 7 additions & 0 deletions R/dockerfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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 ")
```
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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 ")
```
Expand Down
21 changes: 21 additions & 0 deletions man/Dockerfile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/testthat/test-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down