Skip to content

Commit

Permalink
default image from RSCONNECT_IMAGE
Browse files Browse the repository at this point in the history
fixes #1063
  • Loading branch information
aronatkins committed Apr 24, 2024
1 parent d585c26 commit 25d6c4c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# rsconnect (development version)

* `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
}
}

Check warning on line 135 in R/bundle.R

View workflow job for this annotation

GitHub Actions / lint

file=R/bundle.R,line=135,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
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.

34 changes: 33 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,32 @@ 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 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 25d6c4c

Please sign in to comment.