Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

republishing and collaborating #1021

Merged
merged 17 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions R/accounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,7 @@ registerAccount <- function(serverName,
}

accountLabel <- function(account, server) {
# Note: The incoming "account" may correspond to our local account name, which does not always
# match the remote username.
paste0("server: ", server, " / username: ", account)
}
8 changes: 5 additions & 3 deletions R/applications.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ getAppByName <- function(client, accountInfo, name) {
if (length(app)) {
return(app[[1]])
}

stop("No application found. Specify the application's directory, name, ",
"and/or associated account.", call. = FALSE)
return(NULL)
aronatkins marked this conversation as resolved.
Show resolved Hide resolved
}

# Use the API to list all applications then filter the results client-side.
Expand Down Expand Up @@ -240,6 +238,10 @@ showLogs <- function(appPath = getwd(), appFile = NULL, appName = NULL,
accountDetails <- accountInfo(deployment$account, deployment$server)
client <- clientForAccount(accountDetails)
application <- getAppByName(client, accountDetails, deployment$name)
if (is.null(application)) {
stop("No application found. Specify the application's directory, name, ",
"and/or associated account.", call. = FALSE)
}

if (streaming) {
# streaming; poll for the entries directly
Expand Down
12 changes: 12 additions & 0 deletions R/configureApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ setProperty <- function(propertyName, propertyValue, appPath = getwd(),

client <- clientForAccount(accountDetails)
application <- getAppByName(client, accountDetails, deployment$name)
if (is.null(application)) {
stop("No application found. Specify the application's directory, name, ",
"and/or associated account.", call. = FALSE)
}

invisible(client$setApplicationProperty(application$id,
propertyName,
Expand Down Expand Up @@ -150,6 +154,10 @@ unsetProperty <- function(propertyName, appPath = getwd(), appName = NULL,

client <- clientForAccount(accountDetails)
application <- getAppByName(client, accountInfo, deployment$name)
if (is.null(application)) {
stop("No application found. Specify the application's directory, name, ",
"and/or associated account.", call. = FALSE)
}

invisible(client$unsetApplicationProperty(application$id,
propertyName,
Expand Down Expand Up @@ -182,6 +190,10 @@ showProperties <- function(appPath = getwd(), appName = NULL, account = NULL, se

client <- clientForAccount(accountDetails)
application <- getAppByName(client, accountDetails, deployment$name)
if (is.null(application)) {
stop("No application found. Specify the application's directory, name, ",
"and/or associated account.", call. = FALSE)
}

# convert to data frame
res <- do.call(rbind, application$deployment$properties)
Expand Down
105 changes: 51 additions & 54 deletions R/deployApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ deployApp <- function(appDir = getwd(),
recordDir <- appSourceDoc
}

cat(paste("deployApp entry:",
aronatkins marked this conversation as resolved.
Show resolved Hide resolved
"appDir:", appDir,
"appId:", appId,
"appName:", appName,
"appTitle:", appTitle,
"account:", account,
"server:", server,
"\n"))

# set up logging helpers
logLevel <- match.arg(logLevel)
quiet <- identical(logLevel, "quiet")
Expand Down Expand Up @@ -325,60 +334,48 @@ deployApp <- function(appDir = getwd(),
cli::cli_rule("Preparing for deployment")
}

# determine the deployment target and target account info
forceUpdate <- forceUpdate %||% getOption("rsconnect.force.update.apps") %||% fromIDE()

# determine the target deployment record and deploying account
recordPath <- findRecordPath(appDir, recordDir, appPrimaryDoc)
if (!is.null(appId) && is.null(appName)) {
# User has supplied only appId, so retrieve app data from server
# IDE supplies both appId and appName so should never hit this branch
target <- deploymentTargetForApp(
appId = appId,
appTitle = appTitle,
account = account,
server = server
)
} else {
forceUpdate <- forceUpdate %||% getOption("rsconnect.force.update.apps") %||%
fromIDE()

# Use name/account/server to look up existing deployment;
# create new deployment if no match found
target <- deploymentTarget(
recordPath = recordPath,
appId = appId,
appName = appName,
appTitle = appTitle,
envVars = envVars,
account = account,
server = server,
forceUpdate = forceUpdate
)
}
if (is.null(target$appId)) {
dest <- accountLabel(target$username, target$server)
taskComplete(quiet, "Deploying {.val {target$appName}} to {.val {dest}}")
target <- deploymentTarget(
recordPath = recordPath,
appId = appId,
appName = appName,
appTitle = appTitle,
envVars = envVars,
account = account,
server = server,
forceUpdate = forceUpdate
)
accountDetails <- target$accountDetails
deployment <- target$deployment

if (is.null(deployment$appId)) {
dest <- accountLabel(accountDetails$name, accountDetails$server)
taskComplete(quiet, "Deploying {.val {deployment$appName}} using {.val {dest}}")
} else {
dest <- accountLabel(target$username, target$server)
taskComplete(quiet, "Re-deploying {.val {target$appName}} to {.val {dest}}")
dest <- accountLabel(accountDetails$name, accountDetails$server)
taskComplete(quiet, "Re-deploying {.val {deployment$appName}} using {.val {dest}}")
}

# Run checks prior to first saveDeployment() to avoid errors that will always
# prevent a successful upload from generating a partial deployment
if (!isCloudServer(target$server) && identical(upload, FALSE)) {
if (!isCloudServer(accountDetails$server) && identical(upload, FALSE)) {
# it is not possible to deploy to Connect without uploading
stop("Posit Connect does not support deploying without uploading. ",
"Specify upload=TRUE to upload and re-deploy your application.")
}
if (!isConnectServer(target$server) && length(envVars) > 1) {
if (!isConnectServer(accountDetails$server) && length(envVars) > 1) {
cli::cli_abort("{.arg envVars} only supported for Posit Connect servers")
}

accountDetails <- accountInfo(target$account, target$server)
client <- clientForAccount(accountDetails)
if (verbose) {
showCookies(serverInfo(accountDetails$server)$url)
}

isShinyappsServer <- isShinyappsServer(target$server)
isShinyappsServer <- isShinyappsServer(accountDetails$server)

logger("Inferring App mode and parameters")
appMetadata <- appMetadata(
Expand All @@ -392,11 +389,11 @@ deployApp <- function(appDir = getwd(),
metadata = metadata
)

if (is.null(target$appId)) {
if (is.null(deployment$appId)) {
taskStart(quiet, "Creating application on server...")
application <- client$createApplication(
target$appName,
target$appTitle,
deployment$appName,
deployment$appTitle,
"shiny",
accountDetails$accountId,
appMetadata$appMode,
Expand All @@ -405,10 +402,10 @@ deployApp <- function(appDir = getwd(),
)
taskComplete(quiet, "Created application with id {.val {application$id}}")
} else {
taskStart(quiet, "Looking up application with id {.val {target$appId}}...")
taskStart(quiet, "Looking up application with id {.val {deployment$appId}}...")
application <- tryCatch(
{
application <- client$getApplication(target$appId, target$version)
application <- client$getApplication(deployment$appId, deployment$version)
taskComplete(quiet, "Found application {.url {application$url}}")

if (identical(application$type, "static")) {
Expand All @@ -418,15 +415,15 @@ deployApp <- function(appDir = getwd(),
application
},
rsconnect_http_404 = function(err) {
application <- applicationDeleted(client, target, recordPath, appMetadata)
application <- applicationDeleted(client, deployment, recordPath, appMetadata)
taskComplete(quiet, "Created application with id {.val {application$id}}")
application
}
)
}
saveDeployment(
recordPath,
target = target,
target = deployment,
aronatkins marked this conversation as resolved.
Show resolved Hide resolved
application = application,
metadata = metadata
)
Expand All @@ -441,9 +438,9 @@ deployApp <- function(appDir = getwd(),
)
taskComplete(quiet, "Visibility updated")
}
if (length(target$envVars) > 0) {
if (length(deployment$envVars) > 0) {
taskStart(quiet, "Updating environment variables {envVars}...")
client$setEnvVars(application$guid, target$envVars)
client$setEnvVars(application$guid, deployment$envVars)
taskComplete(quiet, "Environment variables updated")
}

Expand All @@ -453,7 +450,7 @@ deployApp <- function(appDir = getwd(),

taskStart(quiet, "Bundling {length(appFiles)} file{?s}: {.file {appFiles}}")
bundlePath <- bundleApp(
appName = target$appName,
appName = deployment$appName,
appDir = appDir,
appFiles = appFiles,
appMetadata = appMetadata,
Expand All @@ -479,7 +476,7 @@ deployApp <- function(appDir = getwd(),

saveDeployment(
recordPath,
target = target,
target = deployment,
application = application,
bundleId = bundle$id,
metadata = metadata
Expand Down Expand Up @@ -584,7 +581,7 @@ runDeploymentHook <- function(appDir, option, verbose = FALSE) {
hook(appDir)
}

applicationDeleted <- function(client, target, recordPath, appMetadata) {
applicationDeleted <- function(client, deployment, recordPath, appMetadata) {
header <- "Failed to find existing application on server; it's probably been deleted."
not_interactive <- c(
i = "Use {.fn forgetDeployment} to remove outdated record and try again.",
Expand All @@ -601,16 +598,16 @@ applicationDeleted <- function(client, target, recordPath, appMetadata) {

path <- deploymentConfigFile(
recordPath,
target$appName,
target$account,
target$server
deployment$appName,
deployment$account,
deployment$server
)
unlink(path)

accountDetails <- accountInfo(target$account, target$server)
accountDetails <- accountInfo(deployment$account, deployment$server)
client$createApplication(
target$appName,
target$appTitle,
deployment$appName,
deployment$appTitle,
"shiny",
accountDetails$accountId,
appMetadata$appMode
Expand Down
Loading
Loading