Skip to content

Commit 62fc265

Browse files
committed
Add documentation for core S3 dockerfile
1 parent 206d041 commit 62fc265

File tree

6 files changed

+265
-31
lines changed

6 files changed

+265
-31
lines changed

R/dockerfile-core.R

Lines changed: 121 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1-
#' Create a new dockerfile object
1+
#' Create a new `dockerfile` object
22
#'
3-
#' @return A new, empty dockerfile object
3+
#' Creates an empty `dockerfile` object that can be populated with Docker instructions.
4+
#'
5+
#' @return
6+
#' A `dockerfile` object with the following structure:
7+
#' * `lines`: Character vector containing Dockerfile instructions
8+
#' * `metadata`: List containing metadata about the Dockerfile:
9+
#' * `base_image`: Base image name
10+
#' * `package_manager`: Package manager type (e.g., "apt", "yum")
11+
#' * `r_version`: R version (if using a rocker image)
12+
#' * `os`: Operating system type
13+
#'
14+
#' @examples
15+
#' # Create a new dockerfile
16+
#' df <- dockerfile()
17+
#'
18+
#' # Add instruction for a base image
19+
#' df <- dfi_from(df, "rocker/r-ver:4.4.0")
20+
#' df
21+
#'
22+
#' # Add an instruction to run a command to update system packages
23+
#' df <- dfi_run(df, "apt update")
24+
#' df
25+
#'
26+
#' @seealso
27+
#' [is_dockerfile()] for checking if an object is a dockerfile,
28+
#' [dfi_from()] for adding a base image, &
29+
#' [write_dockerfile()] for writing a dockerfile to disk
30+
#'
31+
#' @family dockerfile core functions
432
#' @export
533
dockerfile <- function() {
634
structure(
@@ -17,10 +45,25 @@ dockerfile <- function() {
1745
)
1846
}
1947

20-
#' Test if an object is a dockerfile
48+
#' Test if an object is a `dockerfile`
49+
#'
50+
#' Checks whether the provided object is a valid `dockerfile` class object.
2151
#'
2252
#' @param x Object to test
23-
#' @return TRUE if x is a dockerfile, FALSE otherwise
53+
#'
54+
#' @return
55+
#' `TRUE` if `x` is a `dockerfile` object, `FALSE` otherwise
56+
#'
57+
#' @examples
58+
#' df <- dockerfile()
59+
#' is_dockerfile(df)
60+
#' is_dockerfile(list())
61+
#'
62+
#' @seealso
63+
#' [dockerfile()] for creating a `dockerfile` object &
64+
#' [check_dockerfile()] for ensuring an object is a `dockerfile` (with error)
65+
#'
66+
#' @family dockerfile core functions
2467
#' @export
2568
is_dockerfile <- function(x) {
2669
inherits(x, "dockerfile")
@@ -39,10 +82,30 @@ has_instruction <- function(dockerfile, instruction) {
3982
any(grepl(paste0("^", instruction, " "), dockerfile$lines))
4083
}
4184

42-
#' Ensure an object is a dockerfile
85+
#' Ensure an object is a `dockerfile`
86+
#'
87+
#' Verifies that the provided object is a valid `dockerfile` class object,
88+
#' throwing an error if not. Useful for validation inside functions that
89+
#' expect `dockerfile` objects.
4390
#'
4491
#' @param dockerfile Object to check
45-
#' @return Invisible TRUE if valid, error otherwise
92+
#'
93+
#' @return
94+
#' Invisibly returns `TRUE` if valid, otherwise throws an error
95+
#'
96+
#' @examples
97+
#' df <- dockerfile()
98+
#' check_dockerfile(df)
99+
#' \dontrun{
100+
#' # This would throw an error
101+
#' check_dockerfile(list())
102+
#' }
103+
#'
104+
#' @seealso
105+
#' [is_dockerfile()] for checking if an object is a dockerfile &
106+
#' [dockerfile()] for creating a dockerfile object
107+
#'
108+
#' @family dockerfile core functions
46109
#' @export
47110
check_dockerfile <- function(dockerfile) {
48111
if (!is_dockerfile(dockerfile)) {
@@ -51,10 +114,31 @@ check_dockerfile <- function(dockerfile) {
51114
invisible(TRUE)
52115
}
53116

54-
#' Print method for dockerfile objects
117+
#' Print method for `dockerfile` objects
55118
#'
56-
#' @param x A dockerfile object
119+
#' Displays the contents of a `dockerfile` object in a readable format,
120+
#' showing each instruction on a new line as it would appear in an
121+
#' actual **Dockerfile**.
122+
#'
123+
#' @param x A `dockerfile` object
57124
#' @param ... Additional arguments (not used)
125+
#'
126+
#' @return
127+
#' Invisibly returns the `dockerfile` object
128+
#'
129+
#' @examples
130+
#' # Create a new dockerfile and add a couple of instructions
131+
#' df <- dockerfile() |>
132+
#' dfi_from("rocker/r-ver:latest") |>
133+
#' dfi_run("apt-get update")
134+
#'
135+
#' # Print the dockerfile
136+
#' print(df)
137+
#'
138+
#' @seealso
139+
#' [dockerfile()] for creating a `dockerfile` object
140+
#'
141+
#' @family dockerfile core functions
58142
#' @export
59143
print.dockerfile <- function(x, ...) {
60144
check_dockerfile(x)
@@ -67,14 +151,37 @@ print.dockerfile <- function(x, ...) {
67151
invisible(x)
68152
}
69153

70-
71-
72-
#' Add a line to a dockerfile and update metadata
154+
#' Add a line to a `dockerfile` and update metadata
73155
#'
74-
#' @param dockerfile A dockerfile object
75-
#' @param instruction Docker instruction (e.g., "FROM", "RUN")
156+
#' Adds a line to a `dockerfile` and updates its metadata based on the instruction.
157+
#' This is an internal function used by the more specific `dfi_*` functions.
158+
#'
159+
#' @param dockerfile A `dockerfile` object
160+
#' @param instruction Docker instruction (e.g., `"FROM"`, `"RUN"`)
76161
#' @param args Arguments for the instruction
77-
#' @return Updated dockerfile object
162+
#'
163+
#' @return
164+
#' Updated `dockerfile` object with the new line and updated metadata
165+
#'
166+
#' @details
167+
#' This internal function handles:
168+
#'
169+
#' - Adding the instruction with proper formatting
170+
#' - Handling multi-line arguments with appropriate indentation
171+
#' - Updating metadata for special instructions like `FROM`
172+
#'
173+
#' For `FROM` instructions, it extracts and stores:
174+
#'
175+
#' - Base image name
176+
#' - Package manager
177+
#' - Operating system
178+
#' - R version (for `rocker/r-ver:version` images)
179+
#'
180+
#' @seealso
181+
#' [dfi_from()] for adding a FROM instruction &
182+
#' [dfi_run()] for adding a RUN instruction
183+
#'
184+
#' @family dockerfile core functions
78185
#' @keywords internal
79186
add_dockerfile_line <- function(dockerfile, instruction, args) {
80187
check_dockerfile(dockerfile)

man/add_dockerfile_line.Rd

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

man/check_dockerfile.Rd

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

man/dockerfile.Rd

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

man/is_dockerfile.Rd

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

0 commit comments

Comments
 (0)