Skip to content

Commit

Permalink
Merge pull request #2 from colearendt/easy-deploy
Browse files Browse the repository at this point in the history
Easy deploy
  • Loading branch information
colearendt authored Jan 22, 2019
2 parents a52560b + bec4264 commit 800fad7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Encoding: UTF-8
Imports:
R6,
httr,
rlang
rlang,
fs
RoxygenNote: 6.0.1
Suggests: rmarkdown,
Suggests:
rmarkdown,
htmltools,
flexdashboard,
webshot,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ export(audit_r_versions)
export(audit_runas)
export(audit_vanity_urls)
export(cache_apps)
export(deploy_bundle)
export(dir_bundle)
export(poll_task)
export(promote)
export(tag_page)
34 changes: 27 additions & 7 deletions R/promote.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,43 @@ promote <- function(from,
warning(sprintf('Updating EXISTING app %d with name %s on %s', to_app$id, app_name, to))
}

to_app_url <- deploy_bundle(
task_id <- deploy_bundle(
connect = to_client,
bundle = bundle,
app = to_app
app_id = to_app$id
)

poll_task(connect = to_client, task_id = task_id)

to_app_url <- app$url

return(to_app_url)
}

deploy_bundle <- function(connect, bundle, app){
#' @export
dir_bundle <- function(path = ".") {
before_wd <- getwd()
setwd(path)
on.exit(expr = setwd(before_wd), add = TRUE)

utils::tar(tarfile = "bundle.tar.gz", files = ".", compression = "gzip", tar = "internal")

return(fs::path_abs("bundle.tar.gz"))
}

#' @export
deploy_bundle <- function(connect, bundle, app_id){
#upload bundle
new_bundle_id <- connect$upload_bundle(bundle, app$id)
new_bundle_id <- connect$upload_bundle(bundle, app_id)

#activate bundle
task_id <- connect$activate_bundle(app$id, new_bundle_id)
task_id <- connect$activate_bundle(app_id, new_bundle_id)

#poll task
return(task_id)
}

#' @export
poll_task <- function(connect, task_id) {
start <- 0
while (task_id > 0) {
Sys.sleep(2)
Expand All @@ -80,5 +100,5 @@ deploy_bundle <- function(connect, bundle, app){
task_id = 0
}
}
return(app$url)
invisible()
}

0 comments on commit 800fad7

Please sign in to comment.