Skip to content

Commit 432bfc2

Browse files
authored
Merge pull request #50 from ThinkR-open/issue-48
2 parents 0a6a01c + 1e12f09 commit 432bfc2

17 files changed

+836
-945
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
^dev$
1616
^dockerfiler\.Rproj$
1717
^\.dockerignore$
18+
tests/testthat/.dockerignore
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
push:
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
config:
21-
- {os: macOS-latest, r: 'release'}
21+
- {os: macos-latest, r: 'release'}
2222
- {os: windows-latest, r: 'release'}
2323
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
2424
- {os: ubuntu-latest, r: 'release'}
@@ -29,21 +29,21 @@ jobs:
2929
R_KEEP_PKG_SOURCE: yes
3030

3131
steps:
32-
- uses: actions/checkout@v2
32+
- uses: actions/checkout@v3
3333

34-
- uses: r-lib/actions/setup-pandoc@v1
34+
- uses: r-lib/actions/setup-pandoc@v2
3535

36-
- uses: r-lib/actions/setup-r@v1
36+
- uses: r-lib/actions/setup-r@v2
3737
with:
3838
r-version: ${{ matrix.config.r }}
3939
http-user-agent: ${{ matrix.config.http-user-agent }}
4040
use-public-rspm: true
4141

42-
- uses: r-lib/actions/setup-r-dependencies@v1
42+
- uses: r-lib/actions/setup-r-dependencies@v2
4343
with:
44-
extra-packages: rcmdcheck
45-
46-
- uses: r-lib/actions/check-r-package@v1
47-
48-
44+
extra-packages: any::rcmdcheck
45+
needs: check
4946

47+
- uses: r-lib/actions/check-r-package@v2
48+
with:
49+
upload-snapshots: true

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: dockerfiler
22
Title: Easy Dockerfile Creation from R
3-
Version: 0.1.5.0002
3+
Version: 0.1.6
44
Authors@R: c(
55
person("Colin", "Fay", , "[email protected]", role = c("cre", "aut"),
66
comment = c(ORCID = "0000-0001-7343-1846")),
@@ -34,10 +34,11 @@ Imports:
3434
Suggests:
3535
knitr (>= 1.31),
3636
rmarkdown (>= 2.6),
37-
testthat (>= 3.0.0)
37+
testthat (>= 3.0.0),
38+
withr
3839
VignetteBuilder:
3940
knitr
4041
Config/testthat/edition: 3
4142
Encoding: UTF-8
4243
LazyData: true
43-
RoxygenNote: 7.1.2
44+
RoxygenNote: 7.2.3

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# dockerfile 0.1.6
2+
3+
fix: graceful failing in case no internet
14
# dockerfile 0.1.5
25

36
* Added `dock_from_renv()`, to create a Dockerfile from a renv.lock file (@JosiahParry, @statnmap)

R/dockerfile.R

Lines changed: 185 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,192 @@
11
#' A Dockerfile template
22
#'
3-
#' @return A dockerfile template
4-
#'
5-
#' @section Methods:
6-
#' \describe{
7-
#' \item{\code{RUN}}{add a RUN command}
8-
#' \item{\code{ADD}}{add a ADD command}
9-
#' \item{\code{COPY}}{add a COPY command}
10-
#' \item{\code{WORKDIR}}{add a WORKDIR command}
11-
#' \item{\code{EXPOSE}}{add an EXPOSE command}
12-
#' \item{\code{VOLUME}}{add a VOLUME command}
13-
#' \item{\code{CMD}}{add a CMD command}
14-
#' \item{\code{LABEL}}{add a LABEL command}
15-
#' \item{\code{ENV}}{add a ENV command}
16-
#' \item{\code{ENTRYPOINT}}{add a ENTRYPOINT command}
17-
#' \item{\code{VOLUME}}{add a VOLUME command}
18-
#' \item{\code{USER}}{add a USER command}
19-
#' \item{\code{ARG}}{add an ARG command}
20-
#' \item{\code{ONBUILD}}{add a ONBUILD command}
21-
#' \item{\code{STOPSIGNAL}}{add a STOPSIGNAL command}
22-
#' \item{\code{HEALTHCHECK}}{add a HEALTHCHECK command}
23-
#' \item{\code{STOPSIGNAL}}{add a STOPSIGNAL command}
24-
#' \item{\code{SHELL}}{add a SHELL command}
25-
#' \item{\code{MAINTAINER}}{add a MAINTAINER command}
26-
#' \item{\code{custom}}{add a custom command}
27-
#' \item{\code{write}}{save the Dockerfile}
28-
#' \item{\code{switch_cmd}}{switch two command}
29-
#' \item{\code{remove_cmd}}{remove_cmd one or more command(s)}
30-
#' }
31-
#'
32-
#' @importFrom R6 R6Class
333
#' @export
34-
#'
4+
#' @importFrom R6 R6Class
355
#' @examples
366
#' my_dock <- Dockerfile$new()
377
Dockerfile <- R6::R6Class(
38-
"Dockerfile",
39-
public = list(
40-
Dockerfile = character(),
41-
## Either from a file, or from a character vector
42-
initialize = function(
43-
FROM = "rocker/r-base",
44-
AS = NULL
45-
) {
46-
self$Dockerfile <- create_dockerfile(FROM, AS)
47-
},
48-
RUN = function(cmd) {
49-
self$Dockerfile <- c(self$Dockerfile, add_run(cmd))
50-
},
51-
ADD = function(from, to, force = TRUE) {
52-
self$Dockerfile <- c(self$Dockerfile, add_add(from, to, force))
53-
},
54-
COPY = function(from, to, force = TRUE) {
55-
self$Dockerfile <- c(self$Dockerfile, add_copy(from, to, force))
56-
},
57-
WORKDIR = function(where) {
58-
self$Dockerfile <- c(self$Dockerfile, add_workdir(where))
59-
},
60-
EXPOSE = function(port) {
61-
self$Dockerfile <- c(self$Dockerfile, add_expose(port))
62-
},
63-
VOLUME = function(volume) {
64-
self$Dockerfile <- c(self$Dockerfile, add_volume(volume))
65-
},
66-
CMD = function(cmd) {
67-
self$Dockerfile <- c(self$Dockerfile, add_cmd(cmd))
68-
},
69-
LABEL = function(key, value) {
70-
self$Dockerfile <- c(self$Dockerfile, add_label(key, value))
71-
},
72-
ENV = function(key, value) {
73-
self$Dockerfile <- c(self$Dockerfile, add_env(key, value))
74-
},
75-
ENTRYPOINT = function(cmd) {
76-
self$Dockerfile <- c(self$Dockerfile, add_entrypoint(cmd))
77-
},
78-
USER = function(user) {
79-
self$Dockerfile <- c(self$Dockerfile, add_user(user))
80-
},
81-
ARG = function(arg, ahead = FALSE) {
82-
if (ahead) {
83-
self$Dockerfile <- c(add_arg(arg), self$Dockerfile)
84-
} else {
85-
self$Dockerfile <- c(self$Dockerfile, add_arg(arg))
86-
}
87-
},
88-
ONBUILD = function(cmd) {
89-
self$Dockerfile <- c(self$Dockerfile, add_onbuild(cmd))
90-
},
91-
STOPSIGNAL = function(signal) {
92-
self$Dockerfile <- c(self$Dockerfile, add_stopsignal(signal))
93-
},
94-
HEALTHCHECK = function(check) {
95-
self$Dockerfile <- c(self$Dockerfile, add_healthcheck(check))
96-
},
97-
SHELL = function(shell) {
98-
self$Dockerfile <- c(self$Dockerfile, add_shell(shell))
99-
},
100-
MAINTAINER = function(name, email) {
101-
self$Dockerfile <- c(self$Dockerfile, add_maintainer(name, email))
102-
},
103-
custom = function(base, cmd) {
104-
self$Dockerfile <- c(self$Dockerfile, add_custom(base, cmd))
105-
},
106-
print = function() {
107-
cat(self$Dockerfile, sep = "\n")
108-
},
109-
write = function(as = "Dockerfile") {
110-
base::write(self$Dockerfile, file = as)
111-
},
112-
switch_cmd = function(a, b) {
113-
self$Dockerfile <- switch_them(self$Dockerfile, a, b)
114-
},
115-
remove_cmd = function(where) {
116-
self$Dockerfile <- remove_from(self$Dockerfile, where)
117-
},
118-
add_after = function(cmd, after) {
119-
self$Dockerfile <- add_to(self$Dockerfile, cmd, after)
120-
}
121-
)
8+
"Dockerfile",
9+
public = list(
10+
#' @field Dockerfile The dockerfile content.
11+
Dockerfile = character(),
12+
#' @description
13+
#' Create a new Dockerfile object.
14+
#' @param FROM The base image.
15+
#' @param AS The name of the image.
16+
#' @return A Dockerfile object.
17+
initialize = function(FROM = "rocker/r-base",
18+
AS = NULL) {
19+
self$Dockerfile <- create_dockerfile(FROM, AS)
20+
},
21+
#' @description
22+
#' Add a RUN command.
23+
#' @param cmd The command to add.
24+
#' @return the Dockerfile object, invisibly.
25+
RUN = function(cmd) {
26+
self$Dockerfile <- c(self$Dockerfile, add_run(cmd))
27+
},
28+
#' @description
29+
#' Add a ADD command.
30+
#' @param from The source file.
31+
#' @param to The destination file.
32+
#' @param force If TRUE, overwrite the destination file.
33+
#' @return the Dockerfile object, invisibly.
34+
ADD = function(from, to, force = TRUE) {
35+
self$Dockerfile <- c(self$Dockerfile, add_add(from, to, force))
36+
},
37+
#' @description
38+
#' Add a COPY command.
39+
#' @param from The source file.
40+
#' @param to The destination file.
41+
#' @param force If TRUE, overwrite the destination file.
42+
#' @return the Dockerfile object, invisibly.
43+
COPY = function(from, to, force = TRUE) {
44+
self$Dockerfile <- c(self$Dockerfile, add_copy(from, to, force))
45+
},
46+
#' @description
47+
#' Add a WORKDIR command.
48+
#' @param where The working directory.
49+
#' @return the Dockerfile object, invisibly.
50+
WORKDIR = function(where) {
51+
self$Dockerfile <- c(self$Dockerfile, add_workdir(where))
52+
},
53+
#' @description
54+
#' Add a EXPOSE command.
55+
#' @param port The port to expose.
56+
#' @return the Dockerfile object, invisibly.
57+
EXPOSE = function(port) {
58+
self$Dockerfile <- c(self$Dockerfile, add_expose(port))
59+
},
60+
#' @description
61+
#' Add a VOLUME command.
62+
#' @param volume The volume to add.
63+
#' @return the Dockerfile object, invisibly.
64+
VOLUME = function(volume) {
65+
self$Dockerfile <- c(self$Dockerfile, add_volume(volume))
66+
},
67+
#' @description
68+
#' Add a CMD command.
69+
#' @param cmd The command to add.
70+
#' @return the Dockerfile object, invisibly.
71+
CMD = function(cmd) {
72+
self$Dockerfile <- c(self$Dockerfile, add_cmd(cmd))
73+
},
74+
#' @description
75+
#' Add a LABEL command.
76+
#' @param key,value The key and value of the label.
77+
#' @return the Dockerfile object, invisibly.
78+
LABEL = function(key, value) {
79+
self$Dockerfile <- c(self$Dockerfile, add_label(key, value))
80+
},
81+
#' @description
82+
#' Add a ENV command.
83+
#' @param key,value The key and value of the label.
84+
#' @return the Dockerfile object, invisibly.
85+
ENV = function(key, value) {
86+
self$Dockerfile <- c(self$Dockerfile, add_env(key, value))
87+
},
88+
#' @description
89+
#' Add a ENTRYPOINT command.
90+
#' @param cmd The command to add.
91+
#' @return the Dockerfile object, invisibly.
92+
ENTRYPOINT = function(cmd) {
93+
self$Dockerfile <- c(self$Dockerfile, add_entrypoint(cmd))
94+
},
95+
#' @description
96+
#' Add a USER command.
97+
#' @param user The user to add.
98+
#' @return the Dockerfile object, invisibly.
99+
USER = function(user) {
100+
self$Dockerfile <- c(self$Dockerfile, add_user(user))
101+
},
102+
#' @description
103+
#' Add a ARG command.
104+
#' @param arg The argument to add.
105+
#' @param ahead If TRUE, add the argument at the beginning of the Dockerfile.
106+
#' @return the Dockerfile object, invisibly.
107+
ARG = function(arg, ahead = FALSE) {
108+
if (ahead) {
109+
self$Dockerfile <- c(add_arg(arg), self$Dockerfile)
110+
} else {
111+
self$Dockerfile <- c(self$Dockerfile, add_arg(arg))
112+
}
113+
},
114+
#' @description
115+
#' Add a ONBUILD command.
116+
#' @param cmd The command to add.
117+
#' @return the Dockerfile object, invisibly.
118+
ONBUILD = function(cmd) {
119+
self$Dockerfile <- c(self$Dockerfile, add_onbuild(cmd))
120+
},
121+
#' @description
122+
#' Add a STOPSIGNAL command.
123+
#' @param signal The signal to add.
124+
#' @return the Dockerfile object, invisibly.
125+
STOPSIGNAL = function(signal) {
126+
self$Dockerfile <- c(self$Dockerfile, add_stopsignal(signal))
127+
},
128+
#' @description
129+
#' Add a HEALTHCHECK command.
130+
#' @param check The check to add.
131+
#' @return the Dockerfile object, invisibly.
132+
HEALTHCHECK = function(check) {
133+
self$Dockerfile <- c(self$Dockerfile, add_healthcheck(check))
134+
},
135+
#' @description
136+
#' Add a SHELL command.
137+
#' @param shell The shell to add.
138+
#' @return the Dockerfile object, invisibly.
139+
SHELL = function(shell) {
140+
self$Dockerfile <- c(self$Dockerfile, add_shell(shell))
141+
},
142+
#' @description
143+
#' Add a MAINTAINER command.
144+
#' @param name,email The name and email of the maintainer.
145+
#' @return the Dockerfile object, invisibly.
146+
MAINTAINER = function(name, email) {
147+
self$Dockerfile <- c(self$Dockerfile, add_maintainer(name, email))
148+
},
149+
#' @description
150+
#' Add a custom command.
151+
#' @param base,cmd The base and command to add.
152+
#' @return the Dockerfile object, invisibly.
153+
custom = function(base, cmd) {
154+
self$Dockerfile <- c(self$Dockerfile, add_custom(base, cmd))
155+
},
156+
#' @description
157+
#' Print the Dockerfile.
158+
#' @return used for side effect
159+
print = function() {
160+
cat(self$Dockerfile, sep = "\n")
161+
},
162+
#' @description
163+
#' Write the Dockerfile to a file.
164+
#' @param as The file to write to.
165+
#' @return used for side effect
166+
write = function(as = "Dockerfile") {
167+
base::write(self$Dockerfile, file = as)
168+
},
169+
#' @description
170+
#' Switch commands.
171+
#' @param a,b The commands to switch.
172+
#' @return the Dockerfile object, invisibly.
173+
switch_cmd = function(a, b) {
174+
self$Dockerfile <- switch_them(self$Dockerfile, a, b)
175+
},
176+
#' @description
177+
#' Remove a command.
178+
#' @param where The commands to remove.
179+
#' @return the Dockerfile object, invisibly.
180+
remove_cmd = function(where) {
181+
self$Dockerfile <- remove_from(self$Dockerfile, where)
182+
},
183+
#' @description
184+
#' Add a command after another.
185+
#' @param cmd The command to add.
186+
#' @param after Where to add the cmd
187+
#' @return the Dockerfile object, invisibly.
188+
add_after = function(cmd, after) {
189+
self$Dockerfile <- add_to(self$Dockerfile, cmd, after)
190+
}
191+
)
122192
)

0 commit comments

Comments
 (0)