Skip to content

Commit

Permalink
Docker user (#1152)
Browse files Browse the repository at this point in the history
* feat `golem::add_dockerfile_with_renv_*()` set "rstudio" as default USER in Dockerfile to avoid launching app as root

* feat It is now easier to modify the renv.config.pak.enabled parameter in the Dockerfile generated by golem::add_dockerfile_with_renv_*().
  • Loading branch information
VincentGuyader authored and ColinFay committed Aug 7, 2024
1 parent 9ecee1e commit cc1bedf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@

+ `use_git()` is now at the bottom of 01_dev.R ((#1094, @ilyaZar))

+ `golem::add_dockerfile_with_renv_*()` set "rstudio" as default USER in Dockerfile to avoid launching app as root

+ It is now easier to modify the renv.config.pak.enabled parameter in the Dockerfile generated by `golem::add_dockerfile_with_renv_*()` functions.

## Bug fix

+ `use_{internal,external}_XXX_file()` function family works with default missing `name` argument (#1060, @ilyaZar)
Expand Down
11 changes: 10 additions & 1 deletion R/add_dockerfiles_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ add_dockerfile_with_renv_ <- function(

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

my_dock$RUN("R -e 'renv::restore()'")
my_dock$RUN("R -e 'options(renv.config.pak.enabled = FALSE);renv::restore()'")

if (update_tar_gz) {
old_version <- list.files(
Expand Down Expand Up @@ -202,6 +202,7 @@ add_dockerfile_with_renv_ <- function(
#' @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()\`.
#' @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 ... Other arguments to pass to [renv::snapshot()].
#' @inheritParams add_dockerfile
#' @rdname dockerfiles
Expand All @@ -223,6 +224,7 @@ add_dockerfile_with_renv <- function(
extra_sysreqs = NULL,
update_tar_gz = TRUE,
dockerfile_cmd = NULL,
user = "rstudio",
...
) {
base_dock <- add_dockerfile_with_renv_(
Expand All @@ -243,6 +245,9 @@ add_dockerfile_with_renv <- function(
if (!is.null(port)) {
base_dock$EXPOSE(port)
}
if (!is.null(user)) {
base_dock$USER(user)
}
if (is.null(dockerfile_cmd)) {
dockerfile_cmd <- sprintf(
"R -e \"options('shiny.port'=%s,shiny.host='%s');library(%3$s);%3$s::run_app()\"",
Expand Down Expand Up @@ -315,6 +320,7 @@ add_dockerfile_with_renv_shinyproxy <- function(
open = TRUE,
document = TRUE,
update_tar_gz = TRUE,
user = "rstudio",
...
) {
add_dockerfile_with_renv(
Expand All @@ -333,6 +339,7 @@ add_dockerfile_with_renv_shinyproxy <- function(
update_tar_gz = update_tar_gz,
open = open,
document = document,
user = user,
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 @@ -360,6 +367,7 @@ add_dockerfile_with_renv_heroku <- function(
extra_sysreqs = NULL,
open = TRUE,
document = TRUE,
user = "rstudio",
update_tar_gz = TRUE,
...
) {
Expand All @@ -379,6 +387,7 @@ add_dockerfile_with_renv_heroku <- function(
update_tar_gz = update_tar_gz,
open = FALSE,
document = document,
user = user,
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
5 changes: 5 additions & 0 deletions man/dockerfiles.Rd

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

2 changes: 1 addition & 1 deletion man/rstudio_deploy.Rd

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

0 comments on commit cc1bedf

Please sign in to comment.