Skip to content

Commit

Permalink
default image from RSCONNECT_IMAGE (#1065)
Browse files Browse the repository at this point in the history
* default image from RSCONNECT_IMAGE

fixes #1063

* test precedence between image and RSCONNECT_IMAGE
  • Loading branch information
aronatkins authored Apr 24, 2024
1 parent 76ffcfe commit 53d1591
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* `deployApp(logLevel = "quiet")` and `writeManifest(quiet=TRUE)` suppress
output when using renv to analyze dependencies. (#1051)

* `deployApp()` and `writeManifest()` receive the default value for the
`image` argument from the `RSCONNECT_IMAGE` environment variable. (#1063)

# rsconnect 1.2.2

* Use internally computed SHA1 sums and PKI signing when SHA1 is disabled
Expand Down
7 changes: 7 additions & 0 deletions R/bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ createAppManifest <- function(appDir,
verbose = FALSE,
quiet = FALSE) {

if (is.null(image)) {
imageEnv <- Sys.getenv("RSCONNECT_IMAGE", unset = NA)
if (!is.na(imageEnv) && nchar(imageEnv) > 0) {
image <- imageEnv
}
}

if (needsR(appMetadata)) {
extraPackages <- inferRPackageDependencies(appMetadata)
# provide package entries for all dependencies
Expand Down
3 changes: 2 additions & 1 deletion R/deployApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@
#' made. Currently has an effect only on deployments to shinyapps.io.
#' @param image Optional. The name of the image to use when building and
#' executing this content. If none is provided, Posit Connect will
#' attempt to choose an image based on the content requirements.
#' attempt to choose an image based on the content requirements. You can
#' override the default by setting the environment variable `RSCONNECT_IMAGE`.
#' @param envManagement Optional. Should Posit Connect install R and Python
#' packages for this content? (`TRUE`, `FALSE`, or `NULL`).
#' The default, `NULL`, will not write any values to the bundle manifest,
Expand Down
3 changes: 2 additions & 1 deletion man/deployApp.Rd

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

3 changes: 2 additions & 1 deletion man/writeManifest.Rd

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

46 changes: 45 additions & 1 deletion tests/testthat/test-writeManifest.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,18 @@ test_that("Deploying static content with _quarto.yaml succeeds without quartoInf
expect_equal(manifest$metadata$appmode, "static")
})

test_that("Sets environment.image in the manifest if one is provided", {
test_that("environment.image is not set when image is not provided", {
skip_on_cran()

withr::local_options(renv.verbose = TRUE)

appDir <- test_path("shinyapp-simple")

manifest <- makeManifest(appDir)
expect_null(manifest$environment)
})

test_that("environment.image is set when image is provided", {
skip_on_cran()

withr::local_options(renv.verbose = TRUE)
Expand All @@ -237,11 +248,44 @@ test_that("Sets environment.image in the manifest if one is provided", {

manifest <- makeManifest(appDir, image = "rstudio/content-base:latest")
expect_equal(manifest$environment$image, "rstudio/content-base:latest")
})

test_that("environment.image is set and uses a provided image even when RSCONNECT_IMAGE is set", {
skip_on_cran()

withr::local_options(renv.verbose = TRUE)
withr::local_envvar(RSCONNECT_IMAGE = "rstudio/content-base:older")

appDir <- test_path("shinyapp-simple")

manifest <- makeManifest(appDir, image = "rstudio/content-base:latest")
expect_equal(manifest$environment$image, "rstudio/content-base:latest")
})

test_that("environment.image is not set when RSCONNECT_IMAGE is empty", {
skip_on_cran()

withr::local_options(renv.verbose = TRUE)
withr::local_envvar(RSCONNECT_IMAGE = "")

appDir <- test_path("shinyapp-simple")

manifest <- makeManifest(appDir)
expect_null(manifest$environment)
})

test_that("environment.image is set when RSCONNECT_IMAGE is nonempty", {
skip_on_cran()

withr::local_options(renv.verbose = TRUE)
withr::local_envvar(RSCONNECT_IMAGE = "rstudio/content-base:latest")

appDir <- test_path("shinyapp-simple")

manifest <- makeManifest(appDir)
expect_equal(manifest$environment$image, "rstudio/content-base:latest")
})

test_that("Sets environment.environment_management in the manifest if envManagement is defined", {
skip_on_cran()

Expand Down

0 comments on commit 53d1591

Please sign in to comment.