Skip to content

Commit

Permalink
draft : Temp (#977)
Browse files Browse the repository at this point in the history
* Pass `require_suggets` to `attachment_create_renv_for_prod`

* feat : force check_if_suggests_is_installed = FALSE in renv creation

* feat : add test to check suggested package are not in renv.lock

* fix : explictly use library(appname) before launching an app un Dockerfile

issue : #978

* fix : update add_dockerfile_with_renv

* fix : check_installed is more cleaver

* fix : add {renv} to dev_deps (its already in {dockerfiler}'s deps, but it seems safer to do this.

---------

Co-authored-by: Stephen Holsenbeck <[email protected]>
  • Loading branch information
VincentGuyader and yogat3ch authored Jan 29, 2023
1 parent c60f62d commit e1142e4
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 60 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.2
RoxygenNote: 7.2.3
6 changes: 3 additions & 3 deletions R/add_dockerfiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ add_dockerfile_ <- talk_once(

dock$CMD(
sprintf(
"R -e \"options('shiny.port'=%s,shiny.host='%s');%s::run_app()\"",
"R -e \"options('shiny.port'=%s,shiny.host='%s');library(%3$s);%3$s::run_app()\"",
port,
host,
read.dcf(path)[1]
Expand Down Expand Up @@ -263,7 +263,7 @@ add_dockerfile_shinyproxy_ <- talk_once(

dock$EXPOSE(3838)
dock$CMD(sprintf(
" [\"R\", \"-e\", \"options('shiny.port'=3838,shiny.host='0.0.0.0');%s::run_app()\"]",
" [\"R\", \"-e\", \"options('shiny.port'=3838,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"]",
read.dcf(path)[1]
))
dock$write(output)
Expand Down Expand Up @@ -357,7 +357,7 @@ add_dockerfile_heroku_ <- talk_once(

dock$CMD(
sprintf(
"R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');%s::run_app()\"",
"R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"",
read.dcf(path)[1]
)
)
Expand Down
79 changes: 54 additions & 25 deletions R/add_dockerfiles_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@ add_dockerfile_with_renv_ <- function(
repos = c(CRAN = "https://cran.rstudio.com/"),
expand = FALSE,
extra_sysreqs = NULL,
update_tar_gz = TRUE
update_tar_gz = TRUE,
document = FALSE,
...
# build_golem_from_source = TRUE,
) {

if (is.null(lockfile)) {
rlang::check_installed(
"attachment",
c("renv","attachment"),
reason = "to build a Dockerfile with automatic renv.lock creation. Use the `lockfile` parameter to pass your own `renv.lock` file."
)

}



rlang::check_installed(
"renv",
reason = "to build a Dockerfile."
)


# Small hack to prevent warning from rlang::lang() in tests
# This should be managed in {attempt} later on
x <- suppressWarnings({
Expand All @@ -41,10 +38,28 @@ add_dockerfile_with_renv_ <- function(
}

if (is.null(lockfile)) {



if ( isTRUE(document) ){

cli_cat_line("You set `document = TRUE` and you did not pass your own renv.lock file,")
cli_cat_line("as a consequence {golem} will use `attachment::att_amend_desc()` to update your ")
cli_cat_line("DESCRIPTION file before creating the renv.lock file")
cli_cat_line("")
cli_cat_line("you can set `document = FALSE` to use your actual DESCRIPTION file,")
cli_cat_line("or pass you own renv.lock to use, using the `lockfile` parameter")
cli_cat_line("")
cli_cat_line("In any case be sure to have no Error or Warning at `devtools::check()`")
}




lockfile <- attachment_create_renv_for_prod(
path = source_folder,
output = file.path(output_dir, "renv.lock.prod")
check_if_suggests_is_installed = FALSE, document = document,
output = file.path(output_dir, "renv.lock.prod"),
...
)
}

Expand Down Expand Up @@ -132,8 +147,10 @@ add_dockerfile_with_renv_ <- function(
#' @param output_dir folder to export everything deployment related.
#' @param distro One of "focal", "bionic", "xenial", "centos7", or "centos8".
#' 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}');{appname}::run_app()\`
#' the CMD will be `R -e "options('shiny.port'={port},shiny.host='{host}');library({appname});{appname}::run_app()\`
#' @param ... Other arguments to pass to [renv::snapshot()]
#' @inheritParams add_dockerfile
#' @rdname dockerfiles
#' @export
Expand All @@ -150,9 +167,11 @@ add_dockerfile_with_renv <- function(
repos = c(CRAN = "https://cran.rstudio.com/"),
expand = FALSE,
open = TRUE,
document = TRUE,
extra_sysreqs = NULL,
update_tar_gz = TRUE,
dockerfile_cmd = NULL
dockerfile_cmd = NULL,
...
) {
base_dock <- add_dockerfile_with_renv_(
source_folder = source_folder,
Expand All @@ -165,14 +184,16 @@ add_dockerfile_with_renv <- function(
repos = repos,
expand = expand,
extra_sysreqs = extra_sysreqs,
update_tar_gz = update_tar_gz
update_tar_gz = update_tar_gz,
document = document,
...
)
if (!is.null(port)) {
base_dock$EXPOSE(port)
}
if (is.null(dockerfile_cmd)) {
dockerfile_cmd <- sprintf(
"R -e \"options('shiny.port'=%s,shiny.host='%s');%s::run_app()\"",
"R -e \"options('shiny.port'=%s,shiny.host='%s');library(%3$s);%3$s::run_app()\"",
port,
host,
golem::get_golem_name()
Expand Down Expand Up @@ -205,7 +226,7 @@ docker run -p %s:%s %s
)
}

#' @inheritParams add_dockerfile
#' @inheritParams add_dockerfile_with_renv
#' @rdname dockerfiles
#' @export
#' @export
Expand All @@ -221,7 +242,9 @@ add_dockerfile_with_renv_shinyproxy <- function(
expand = FALSE,
extra_sysreqs = NULL,
open = TRUE,
update_tar_gz = TRUE
document = TRUE,
update_tar_gz = TRUE,
...
) {
add_dockerfile_with_renv(
source_folder = source_folder,
Expand All @@ -238,14 +261,16 @@ add_dockerfile_with_renv_shinyproxy <- function(
extra_sysreqs = extra_sysreqs,
update_tar_gz = update_tar_gz,
open = open,
document = document,
dockerfile_cmd = sprintf(
"R -e \"options('shiny.port'=3838,shiny.host='0.0.0.0');%s::run_app()\"",
"R -e \"options('shiny.port'=3838,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"",
golem::get_golem_name()
)
),
...
)
}

#' @inheritParams add_dockerfile
#' @inheritParams add_dockerfile_with_renv
#' @rdname dockerfiles
#' @export
#' @export
Expand All @@ -261,7 +286,9 @@ add_dockerfile_with_renv_heroku <- function(
expand = FALSE,
extra_sysreqs = NULL,
open = TRUE,
update_tar_gz = TRUE
document = TRUE,
update_tar_gz = TRUE,
...
) {
add_dockerfile_with_renv(
source_folder = source_folder,
Expand All @@ -278,10 +305,12 @@ add_dockerfile_with_renv_heroku <- function(
extra_sysreqs = extra_sysreqs,
update_tar_gz = update_tar_gz,
open = FALSE,
document = document,
dockerfile_cmd = sprintf(
"R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');%s::run_app()\"",
"R -e \"options('shiny.port'=$PORT,shiny.host='0.0.0.0');library(%1$s);%1$s::run_app()\"",
golem::get_golem_name()
)
),
...
)

apps_h <- gsub(
Expand Down
6 changes: 5 additions & 1 deletion R/bootstrap_attachment.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
check_attachment_installed <- function() {
rlang::check_installed(
"attachment",
version = "0.2.5",
version = "0.3.1",
reason = "to build a Dockerfile."
)
}
Expand All @@ -12,12 +12,16 @@ attachment_create_renv_for_prod <- function(
path = ".",
output = "renv.lock.prod",
dev_pkg = "remotes",
check_if_suggests_is_installed = FALSE,
document = FALSE,
...
) {
attachment::create_renv_for_prod(
path = path,
output = output,
dev_pkg = dev_pkg,
document = document,
check_if_suggests_is_installed = check_if_suggests_is_installed,
...
)
}
3 changes: 2 additions & 1 deletion R/install_dev_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ dev_deps <- unique(
"pkgload",
"processx",
"roxygen2",
"renv",
"rsconnect",
"rstudioapi",
"testthat",
Expand All @@ -97,7 +98,7 @@ check_dev_deps_are_installed <- function() {
if (!all(are_installed)) {
message(
"We noticed that some dev dependencies are not installed.\n",
"You can install them with `install_dev_deps()`."
"You can install them with `golem::install_dev_deps()`."
)
}
}
18 changes: 14 additions & 4 deletions man/dockerfiles.Rd

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

28 changes: 14 additions & 14 deletions man/get_golem_options.Rd

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

15 changes: 15 additions & 0 deletions tests/testthat/helper-config.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,18 @@ withr::with_dir(pkg, {
)
usethis::use_mit_license("Golem")
})


create_deploy_folder <- function(){
file.path(
tempdir(),
make.names(
paste0(
"deploy",
round(
runif(1, min = 0, max = 99999)
)
)
)
)
}
Loading

0 comments on commit e1142e4

Please sign in to comment.