Skip to content

Commit

Permalink
enable app from container #40
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Aug 16, 2020
1 parent c5d1cf7 commit 1419966
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 29 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

export(az_webapp_config)
export(az_webapp_shiny_opts)
export(get_tag)
export(runOldFaithful)
20 changes: 15 additions & 5 deletions R/azure.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ az_webapp_config <- function(name,
restart = FALSE) {
checkmate::assert_string(name)
checkmate::assert_string(deployment_container_image_name)
checkmate::assert_string(startup_file, )
checkmate::assert_string(startup_file, null.ok = TRUE)
checkmate::assert_string(subscription)
checkmate::assert_string(resource_group)
checkmate::assert_string(docker_registry_server_url, null.ok = TRUE)
Expand Down Expand Up @@ -95,7 +95,21 @@ az_webapp_config <- function(name,
"webapp", "create",
"--name", name,
"--plan", plan,
# az webapp create, though undocumented, requires either an image name or a runtime
# other container settings are set below
"--deployment-container-image-name", deployment_container_image_name,
if (!is.null(startup_file)) {
c("--startup-file", startup_file)
}
# todo also pass on tags #25
))

cli::cli_alert_info("Setting web app container settings")
az_cli_run(args = c(
"webapp", "config", "container", "set",
# redundant, container is already set above, but safer\
# otherwise command might be called with no args
"--docker-custom-image-name", deployment_container_image_name,
if (!is.null(docker_registry_server_url)) {
c("--docker-registry-server-url", docker_registry_server_url)
},
Expand All @@ -104,11 +118,7 @@ az_webapp_config <- function(name,
},
if (!is.null(docker_registry_server_password)) {
c("--docker-registry-server-password", docker_registry_server_password)
},
if (!is.null(startup_file)) {
c("--startup-file", startup_file)
}
# todo also pass on tags #25
))

cli::cli_alert_info("Setting web app tags ...")
Expand Down
20 changes: 20 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' Use `github.sha` environment variable or `"latest"` as docker image tag
#'
#' Retrieves the current git commit SHA from the [`github.sha`](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions) environment variable set on GitHub Actions.
#' Returns `latest`, if the environment variable is an empty string.
#' Internal function used to retrieve the appropriate docker image tag for a shiny app.
#'
#' @return character string
#'
#' @export
#'
#' @keywords internal
get_tag <- function() {
sha <- Sys.getenv("gihub.sha")
if (sha == "") {
tag <- "latest"
} else {
tag <- sha
}
tag
}
34 changes: 22 additions & 12 deletions man/az_webapp_config.Rd

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

17 changes: 17 additions & 0 deletions man/get_tag.Rd

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

34 changes: 22 additions & 12 deletions tests/testthat/setup-azure.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# hoad credentials used for testing
# authentication happens outside of r, see github actions main.yaml
plan <- "hoad"
resource_group <- "hoad"
subscription <- "f0dd3a37-0a4e-4e7f-9c9b-cb9f60146edc"

# deploy shiny app using rocker image
az_webapp_config(
name = "hello-shiny",
Expand All @@ -15,18 +21,22 @@ az_webapp_config(
"-e shiny::runExample('01_hello',port=getOption('shiny.port'))"
),
# replace below with your own credentials
plan = "hoad",
resource_group = "hoad",
subscription = "f0dd3a37-0a4e-4e7f-9c9b-cb9f60146edc"
plan = plan,
resource_group = resource_group,
subscription = subscription
)

# deploy shiny app using muggle image
# az_webapp_config(
# name = "old-faithful",
# deployment_container_image_name = "docker.pkg.github.com/subugoe/shinycaas/oldfaithful",
# plan = "hoad",
# resource_group = "hoad",
# subscription = "f0dd3a37-0a4e-4e7f-9c9b-cb9f60146edc",
# docker_registry_server_url = "https://docker.pkg.github.com",
# docker_registry_server_user = "maxheld83"
# )
az_webapp_config(
name = "old-faithful",
deployment_container_image_name = paste0(
"docker.pkg.github.com/subugoe/shinycaas/oldfaithful:",
get_tag()
),
plan = plan,
resource_group = resource_group,
subscription = subscription,
docker_registry_server_url = "https://docker.pkg.github.com",
docker_registry_server_user = "maxheld83"
# docker password is a GITHUB PAT, pasted directly into portal.azure.com
)

0 comments on commit 1419966

Please sign in to comment.