Skip to content

Commit

Permalink
wire up application deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Oct 2, 2013
1 parent 26ca110 commit a6b104f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
45 changes: 31 additions & 14 deletions R/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,55 @@ deploy <- function(appDir = getwd(), appName = NULL, account = NULL) {

# determine the deployment target and target account info
target <- deploymentTarget(appDir, appName, account)
appName <- target$appName
account <- target$account
accountInfo <- accountInfo(target$account)

# list the existing applications for this account and see if we
# need to create a new application
appId <- NULL
app <- NULL
existingApps <- lucid$applications(accountInfo$accountId)
for (app in existingApps) {
if (identical(app$name, target$appName)) {
appId <- app$id
for (existingApp in existingApps) {
if (identical(existingApp$name, target$appName)) {
app <- existingApp
break
}
}

# if there is no record of deploying this application locally yet there
# is an application of that name already deployed then confirm
if (!target$isUpdate && !is.null(appId) && interactive()) {

# TODO
if (!target$isUpdate && !is.null(app) && interactive()) {
prompt <- paste("Update existing application at ", app$url,
"? [Y/n] ", sep="")
input <- readline(prompt)
if (nzchar(input) && !identical(input, "y") && !identical(input, "Y"))
stop("Application deployment aborted")
}

# create the application if we need to
if (is.null(appId)) {
if (is.null(app)) {
app <- lucid$createApplication(target$appName,
"shiny",
accountInfo$accountId)
appId <- app$id
}

# upload the bundle
bundle <- lucid$uploadApplication(appId, bundlePath)
bundle <- lucid$uploadApplication(app$id, bundlePath)

# deploy the bundle
task <- lucid$deployApplication(app$id, bundle$id)

# poll for task status


# save a record of the deployment
saveDeployment(appDir,
target$appName,
target$account,
bundle$id,
app$url)

bundle
invisible(TRUE)
}

# calculate the deployment target based on the passed parameters and
Expand Down Expand Up @@ -210,8 +227,8 @@ readDeployments <- function(appDir, nameFilter = NULL, accountFilter = NULL) {
stringsAsFactors = FALSE)

# apply optional name filter
if (!is.null(nameFilter) && !identical(nameFilter,
basename(deploymentFile)))
name <- tools::file_path_sans_ext(basename(deploymentFile))
if (!is.null(nameFilter) && !identical(nameFilter, name))
next

deployments <- rbind(deployments, deployment)
Expand All @@ -224,7 +241,7 @@ readDeployments <- function(appDir, nameFilter = NULL, accountFilter = NULL) {
deploymentFile <- function(appDir, name, account) {
accountDir <- file.path(appDir, "shinyapps", account)
if (!file.exists(accountDir))
dir.create(accountDir)
dir.create(accountDir, recursive=TRUE)
file.path(accountDir, paste(name, ".dcf", sep=""))
}

Expand Down
9 changes: 8 additions & 1 deletion R/lucid.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ lucidClient <- function(authInfo) {
uploadApplication = function(applicationId, bundlePath) {
path <- paste("/v1/applications/", applicationId, "/upload", sep="")
handleResponse(POST(authInfo, path, "application/x-gzip", bundlePath))
},

deployApplication = function(applicationId, bundleId) {
path <- paste("/v1/applications/", applicationId, "/deploy", sep="")
json <- list()
json$bundle <- as.numeric(bundleId)
handleResponse(POST_JSON(authInfo, path, json))
}
)
}
Expand All @@ -51,7 +58,7 @@ handleResponse <- function(response, jsonFilter = NULL) {

json <- RJSONIO::fromJSON(response$content, simplify = FALSE)

if (response$status %in% 200:299)
if (response$status %in% 200:399)
if (!is.null(jsonFilter))
jsonFilter(json)
else
Expand Down

0 comments on commit a6b104f

Please sign in to comment.