Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e1d1f01
wip
VincentGuyader May 7, 2025
f102d4d
wip
VincentGuyader May 7, 2025
0b4891e
Merge branch 'master' into compact_dockerfile
VincentGuyader Jun 3, 2025
b87d6ca
fix docker build instruction
Jun 3, 2025
429bf35
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 6, 2025
381a935
deal with source_folder deprecation
Jun 27, 2025
7885ffe
Merge branch 'master' into compact_dockerfile
VincentGuyader Jun 27, 2025
a1703b0
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
e4027e1
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
284c282
Update tests/testthat/test-add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
292d106
Update tests/testthat/test-add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
aa6492c
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
11d81ae
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
3d819b3
Update tests/testthat/test-add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
b57c4ee
Update tests/testthat/test-add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
06bdcfb
Update tests/testthat/test-add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
ae4e2e2
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
f4c3c61
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
ac6473d
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
0a65753
Update tests/testthat/test-add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
a85c9da
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
b6ed713
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
2a535b5
Update R/add_dockerfiles_renv.R
VincentGuyader Jun 27, 2025
17d646d
Update DESCRIPTION
VincentGuyader Jun 27, 2025
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Suggests:
crayon,
desc,
devtools,
dockerfiler (>= 0.2.0),
dockerfiler (>= 0.2.5),
fs,
httpuv,
knitr,
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

# golem 0.5.1 to 0.6.0



## New features / user-visible changes

- The `add_dockerfile_with_renv_*` function now generates a multi-stage Dockerfile by default (use `single_file = FALSE` to retain the previous behavior).
- The `add_dockerfile_with_renv_*` function now creates a Dockerfile that sets `golem.app.prod = TRUE` by default (use `set_golem.app.prod = FALSE` to retain the previous behavior).

## Breaking change

- /!\ Breaking change in the name of the arguments /!\ `{golem}` functions used to rely on arguments that where either `wd`, `path`, `pkg` or `golem_wd`. This has now been standardized and all functions rely on `golem_wd` now (@ilyaZar, #845)
Expand Down
132 changes: 107 additions & 25 deletions R/add_dockerfiles_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_dockerfile_with_renv_ <- function(
),
distro = "focal",
FROM = "rocker/verse",
AS = NULL,
AS = "builder",
sysreqs = TRUE,
repos = c(
CRAN = "https://cran.rstudio.com/"
Expand All @@ -16,6 +16,7 @@ add_dockerfile_with_renv_ <- function(
extra_sysreqs = NULL,
update_tar_gz = TRUE,
document = FALSE,
single_file = FALSE,
...,
source_folder
) {
Expand Down Expand Up @@ -103,6 +104,12 @@ add_dockerfile_with_renv_ <- function(
extra_sysreqs = extra_sysreqs
)





if ( !single_file){

socle$write(
as = file.path(
output_dir,
Expand All @@ -123,10 +130,51 @@ add_dockerfile_with_renv_ <- function(
)
)

my_dock$COPY(basename(lockfile), "renv.lock")

} else {

# ici on va faire le fork
# et ici faut append

my_dock <- dockerfiler_Dockerfile()$new(
FROM = AS, AS = "final"
)

socle$write( as = file.path(
output_dir,
"Dockerfile"
))




}

if (!single_file){
my_dock$COPY(basename(lockfile), "renv.lock")
my_dock$RUN("R -e 'options(renv.config.pak.enabled = FALSE);renv::restore()'")

}
# we use an already built tar.gz file
my_dock$COPY(
from =
paste0(
get_golem_name(
pkg = source_folder
),
"_*.tar.gz"
),
to = "/app.tar.gz"
)
my_dock$RUN(
"R -e 'remotes::install_local(\"/app.tar.gz\",upgrade=\"never\")'"
)
my_dock$RUN("rm /app.tar.gz")






if (update_tar_gz) {
old_version <- list.files(
path = output_dir,
Expand All @@ -151,7 +199,7 @@ add_dockerfile_with_renv_ <- function(
)
)
}

if (
isTRUE(
requireNamespace(
Expand Down Expand Up @@ -189,20 +237,6 @@ add_dockerfile_with_renv_ <- function(
}
}

# we use an already built tar.gz file
my_dock$COPY(
from = paste0(
get_golem_name(
golem_wd = golem_wd
),
"_*.tar.gz"
),
to = "/app.tar.gz"
)
my_dock$RUN(
"R -e 'remotes::install_local(\"/app.tar.gz\",upgrade=\"never\")'"
)
my_dock$RUN("rm /app.tar.gz")
my_dock
}

Expand All @@ -214,8 +248,13 @@ add_dockerfile_with_renv_ <- function(
#' See available distributions at https://hub.docker.com/r/rstudio/r-base/.
#' @param document boolean. If TRUE (by default), DESCRIPTION file is updated using [attachment::att_amend_desc()] before creating the renv.lock file
#' @param dockerfile_cmd What is the CMD to add to the Dockerfile. If NULL, the default,
#' the CMD will be `R -e "options('shiny.port'={port},shiny.host='{host}');library({appname});{appname}::run_app()\`.
#' the CMD will be `R -e "options('shiny.port'={port},shiny.host='{host}',golem.app.prod = {set_golem.app.prod});library({appname});{appname}::run_app()\`.
#' @param user Name of the user to specify in the Dockerfile with the USER instruction. Default is `rstudio`, if set to `NULL` no the user from the FROM image is used.
#' @param single_file boolean.
#' If `TRUE` (by default), generate a single multi-stage Dockerfile .
#' If `FALSE`, produce two distinct Dockerfiles to be run sequentially
#' for the build and production phases.
#' @param set_golem.app.prod boolean If `TRUE` (by default) set options(golem.app.prod = TRUE) in dockerfile_cmd.
#' @param ... Other arguments to pass to [renv::snapshot()].
#' @param source_folder deprecated, use golem_wd instead
#' @inheritParams add_dockerfile
Expand All @@ -227,7 +266,7 @@ add_dockerfile_with_renv <- function(
output_dir = fs::path(tempdir(), "deploy"),
distro = "focal",
from = "rocker/verse",
as = NULL,
as = "builder",
sysreqs = TRUE,
port = 80,
host = "0.0.0.0",
Expand All @@ -239,6 +278,8 @@ add_dockerfile_with_renv <- function(
update_tar_gz = TRUE,
dockerfile_cmd = NULL,
user = "rstudio",
single_file = TRUE,
set_golem.app.prod = TRUE,
...,
source_folder
) {
Expand All @@ -261,6 +302,7 @@ add_dockerfile_with_renv <- function(
extra_sysreqs = extra_sysreqs,
update_tar_gz = update_tar_gz,
document = document,
single_file = single_file,
...
)
if (!is.null(port)) {
Expand All @@ -271,9 +313,10 @@ add_dockerfile_with_renv <- function(
}
if (is.null(dockerfile_cmd)) {
dockerfile_cmd <- sprintf(
"R -e \"options('shiny.port'=%s,shiny.host='%s');library(%3$s);%3$s::run_app()\"",
"R -e \"options('shiny.port'=%s,shiny.host='%s',golem.app.prod=%s);library(%3$s);%3$s::run_app()\"",
port,
host,
set_golem.app.prod,
get_golem_name(
golem_wd = golem_wd
)
Expand All @@ -283,10 +326,14 @@ add_dockerfile_with_renv <- function(
dockerfile_cmd
)
base_dock
base_dock$write(as = file.path(output_dir, "Dockerfile"))
base_dock$write(as = file.path(output_dir, "Dockerfile"),
append = single_file)


if (!single_file){
out <- sprintf(
"docker build -f Dockerfile_base --progress=plain -t %s .
"# use cd to moove to the folder containing the Dockerfile
docker build -f Dockerfile_base --progress=plain -t %s .
docker build -f Dockerfile --progress=plain -t %s .
docker run -p %s:%s %s
# then go to 127.0.0.1:%s",
Expand All @@ -313,8 +360,35 @@ docker run -p %s:%s %s
":latest"
)),
port
)

)} else {




out <- sprintf(
"# use cd to moove to the folder containing the Dockerfile
docker build -f Dockerfile --target=final --progress=plain -t %s .
docker run -p %s:%s %s
# then go to 127.0.0.1:%s",
tolower(paste0(
get_golem_name(
pkg = source_folder
),
":latest"
)),
port,
port,
tolower(paste0(
get_golem_name(
pkg = source_folder
),
":latest"
)),
port
)

}

cat(out, file = file.path(output_dir, "README"))

open_or_go_to(
Expand Down Expand Up @@ -342,6 +416,8 @@ add_dockerfile_with_renv_shinyproxy <- function(
document = TRUE,
update_tar_gz = TRUE,
user = "rstudio",
single_file = TRUE,
set_golem.app.prod = TRUE,
...,
source_folder
) {
Expand All @@ -368,6 +444,8 @@ add_dockerfile_with_renv_shinyproxy <- function(
open = open,
document = document,
user = user,
single_file = single_file,
set_golem.app.prod = set_golem.app.prod,
dockerfile_cmd = sprintf(
"R -e \"options('shiny.port'=3838,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"",
get_golem_name(
Expand Down Expand Up @@ -397,6 +475,8 @@ add_dockerfile_with_renv_heroku <- function(
document = TRUE,
user = "rstudio",
update_tar_gz = TRUE,
single_file = TRUE,
set_golem.app.prod = TRUE,
...,
source_folder
) {
Expand All @@ -423,6 +503,8 @@ add_dockerfile_with_renv_heroku <- function(
open = FALSE,
document = document,
user = user,
single_file = single_file,
set_golem.app.prod = set_golem.app.prod,
dockerfile_cmd = sprintf(
"R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"",
get_golem_name(
Expand Down
17 changes: 15 additions & 2 deletions man/dockerfiles.Rd

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

Loading