|
| 1 | +#' A Dockerfile template |
| 2 | +#' |
| 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 |
| 33 | +#' @export |
| 34 | +#' |
| 35 | +#' @examples |
| 36 | +#' my_dock <- Dockerfile$new() |
| 37 | + |
| 38 | +Dockerfile <- R6::R6Class("Dockerfile", |
| 39 | + public = list( |
| 40 | + Dockerfile = character(), |
| 41 | + ## Either from a file, or from a character vector |
| 42 | + initialize = function(FROM = "rocker/r-base", AS = NULL){ |
| 43 | + self$Dockerfile <- create_dockerfile(FROM, AS) |
| 44 | + }, |
| 45 | + RUN = function(cmd){ |
| 46 | + self$Dockerfile <- c(self$Dockerfile, add_run(cmd)) |
| 47 | + }, |
| 48 | + ADD = function(from, to, force = TRUE){ |
| 49 | + self$Dockerfile <- c(self$Dockerfile,add_add(from, to, force)) |
| 50 | + }, |
| 51 | + COPY = function(from, to, force = TRUE){ |
| 52 | + self$Dockerfile <- c(self$Dockerfile,add_copy(from, to, force)) |
| 53 | + }, |
| 54 | + WORKDIR = function(where){ |
| 55 | + self$Dockerfile <- c(self$Dockerfile, add_workdir(where)) |
| 56 | + }, |
| 57 | + EXPOSE = function(port){ |
| 58 | + self$Dockerfile <- c(self$Dockerfile, add_expose(port)) |
| 59 | + }, |
| 60 | + VOLUME = function(volume){ |
| 61 | + self$Dockerfile <- c(self$Dockerfile, add_volume(volume)) |
| 62 | + }, |
| 63 | + CMD = function(cmd){ |
| 64 | + self$Dockerfile <- c(self$Dockerfile, add_cmd(cmd)) |
| 65 | + }, |
| 66 | + LABEL = function(key, value){ |
| 67 | + self$Dockerfile <- c(self$Dockerfile, add_label(key, value)) |
| 68 | + }, |
| 69 | + ENV = function(key, value){ |
| 70 | + self$Dockerfile <- c(self$Dockerfile, add_env(key, value)) |
| 71 | + }, |
| 72 | + ENTRYPOINT = function(cmd){ |
| 73 | + self$Dockerfile <- c(self$Dockerfile, add_entrypoint(cmd)) |
| 74 | + }, |
| 75 | + USER = function(user){ |
| 76 | + self$Dockerfile <- c(self$Dockerfile, add_user(user)) |
| 77 | + }, |
| 78 | + ARG = function(arg, ahead = FALSE){ |
| 79 | + if (ahead) { |
| 80 | + self$Dockerfile <- c(add_arg(arg), self$Dockerfile) |
| 81 | + } else { |
| 82 | + self$Dockerfile <- c(self$Dockerfile,add_arg(arg)) |
| 83 | + } |
| 84 | + }, |
| 85 | + ONBUILD = function(cmd){ |
| 86 | + self$Dockerfile <- c(self$Dockerfile,add_onbuild(cmd)) |
| 87 | + }, |
| 88 | + STOPSIGNAL = function(signal){ |
| 89 | + self$Dockerfile <- c(self$Dockerfile,add_stopsignal(signal)) |
| 90 | + }, |
| 91 | + HEALTHCHECK = function(check){ |
| 92 | + self$Dockerfile <- c(self$Dockerfile,add_healthcheck(check)) |
| 93 | + }, |
| 94 | + SHELL = function(shell){ |
| 95 | + self$Dockerfile <- c(self$Dockerfile,add_shell(shell)) |
| 96 | + }, |
| 97 | + MAINTAINER = function(name, email){ |
| 98 | + self$Dockerfile <- c(self$Dockerfile,add_maintainer(name, email)) |
| 99 | + }, |
| 100 | + custom = function(base, cmd){ |
| 101 | + self$Dockerfile <- c(self$Dockerfile, add_custom(base, cmd)) |
| 102 | + }, |
| 103 | + print = function(){ |
| 104 | + cat(self$Dockerfile, sep = '\n') |
| 105 | + }, |
| 106 | + write = function(as = "Dockerfile"){ |
| 107 | + base::write(self$Dockerfile, file = as) |
| 108 | + }, |
| 109 | + switch_cmd = function(a,b){ |
| 110 | + self$Dockerfile <- switch_them(self$Dockerfile, a, b) |
| 111 | + }, |
| 112 | + remove_cmd = function(where){ |
| 113 | + self$Dockerfile <- remove_from(self$Dockerfile, where) |
| 114 | + }, |
| 115 | + add_after = function(cmd, after){ |
| 116 | + self$Dockerfile <- add_to(self$Dockerfile, cmd, after) |
| 117 | + } |
| 118 | + )) |
0 commit comments