Skip to content

Commit

Permalink
Fix do_provision (#448)
Browse files Browse the repository at this point in the history
* scp fix attempt

* switch back to their original code within install_api fxn

* Work around `cloud-init` which clobbers /etc/apt/sources.list after some number of seconds.

The edits we were making to add the CRAN repo were getting clobbered.

We also separated into multiple separate SSH commands, though we don't believe that this is actually necessary.

* Add libsodium system requirement.

Fulfills optional sodium requirements.

* Avoid ** which was broken for uploads.

* Add libssh-dev dependency.

Needed to enable the 'remotes' version of analogsea to install.

* Fix to handle new ** behavior.

* unlink dir when function exits

* add news item

* Use >= 0.7.0 version of analogsea

* do not unlink R's temp dir. Only downloaded file if it exists.

* remove normalize path and yell if the basic api example is not found
  • Loading branch information
trestletech authored and schloerke committed Jun 18, 2019
1 parent 6e3417e commit a159aa6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
^node_modules
^package\.json$
^\.github
^\.httr-oauth$
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- sourceline: 'ppa:chris-lea/libsodium'
packages:
- libsodium-dev
- libssh-dev
- <<: *trusty
name: Linux - trusty - release
r: release
Expand All @@ -41,6 +42,7 @@ jobs:
apt:
packages:
- libsodium-dev
- libssh-dev
- <<: *xenial
name: Linux - xenial - release; covr
r: release
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ Suggests:
base64enc,
htmlwidgets,
visNetwork,
analogsea,
analogsea (>= 0.7.0),
later
Remotes:
rstudio/promises,
rstudio/swagger,
rstudio/httpuv
rstudio/httpuv,
sckott/analogsea
Collate:
'async.R'
'content-types.R'
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ plumber 0.5.0

### Bug fixes

* Fix bugs that prevented `do_provision` from deploying to DigitalOcean and updated to the latest `analogsea`. ([#448](https://github.com/trestletech/plumber/pull/448/files))

* Fixed bug where functions defined earlier in the file could not be found when `plumb()`ing a file. ([#416](https://github.com/trestletech/plumber/pull/416))

* A multiline POST body is now collapsed to a single line (@robertdj, [#270](https://github.com/trestletech/plumber/issues/270) [#297](https://github.com/trestletech/plumber/pull/297)).
Expand Down
43 changes: 29 additions & 14 deletions R/digital-ocean.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ do_provision <- function(droplet, unstable=FALSE, example=TRUE, ...){
}

install_plumber <- function(droplet, unstable){
# Satisfy sodium's requirements
analogsea::debian_apt_get_install(droplet, "libsodium-dev")

if (unstable){
analogsea::debian_apt_get_install(droplet, "libcurl4-openssl-dev")
analogsea::debian_apt_get_install(droplet, "libgit2-dev")
Expand All @@ -91,22 +94,32 @@ install_plumber <- function(droplet, unstable){
#' Captures the output from running some command via SSH
#' @noRd
droplet_capture <- function(droplet, command){
tf <- tempfile()
tf <- tempdir()
randName <- paste(sample(c(letters, LETTERS), size=10, replace=TRUE), collapse="")
tff <- file.path(tf, randName)
on.exit({
if (file.exists(tff)) {
file.remove(tff)
}
})
analogsea::droplet_ssh(droplet, paste0(command, " > /tmp/", randName))
analogsea::droplet_download(droplet, paste0("/tmp/", randName), tf)
analogsea::droplet_ssh(droplet, paste0("rm /tmp/", randName))
lin <- readLines(tf)
file.remove(tf)
lin <- readLines(tff)
lin
}

install_api <- function(droplet){
analogsea::droplet_ssh(droplet, "mkdir -p /var/plumber")
analogsea::droplet_upload(droplet, local=normalizePath(
paste0(system.file("examples", "10-welcome", package="plumber"), "/**"), mustWork=FALSE), #TODO: Windows support for **?
remote="/var/plumber/",
verbose = TRUE)
example_plumber_file <- system.file("examples", "10-welcome", "plumber.R", package="plumber")
if (nchar(example_plumber_file) < 1) {
stop("Could not find example 10-welcome plumber file", call. = FALSE)
}
analogsea::droplet_upload(
droplet,
local = example_plumber_file,
remote = "/var/plumber/",
verbose = TRUE)
}

install_firewall <- function(droplet){
Expand All @@ -127,11 +140,12 @@ install_nginx <- function(droplet){
}

install_new_r <- function(droplet){
analogsea::droplet_ssh(droplet, c("echo 'deb https://cran.rstudio.com/bin/linux/ubuntu xenial/' >> /etc/apt/sources.list",
"apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9"))
analogsea::droplet_ssh(droplet, "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9")
analogsea::droplet_ssh(droplet, "echo 'deb https://cran.rstudio.com/bin/linux/ubuntu xenial/' >> /etc/apt/sources.list.d/cran.list")
# TODO: use the analogsea version once https://github.com/sckott/analogsea/issues/139 is resolved
#analogsea::debian_apt_get_update(droplet)
analogsea::droplet_ssh(droplet, "sudo apt-get update -qq", 'sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade')
analogsea::droplet_ssh(droplet, "sudo apt-get update -qq")
analogsea::droplet_ssh(droplet, 'sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade')

analogsea::debian_install_r(droplet)
}
Expand Down Expand Up @@ -288,10 +302,11 @@ do_deploy_api <- function(droplet, path, localPath, port, forward=FALSE,
}

### UPLOAD the API ###
localPath <- sub("/+$", "", localPath)
analogsea::droplet_ssh(droplet, paste0("mkdir -p /var/plumber/", path))
analogsea::droplet_upload(droplet, local=paste0(localPath, "/**"), #TODO: Windows support for **?
remote=paste0("/var/plumber/", path, "/"))
remoteTmp <- paste0("/tmp/", paste0(sample(LETTERS, 10, replace=TRUE), collapse=""))
dirName <- basename(localPath)
analogsea::droplet_ssh(droplet, paste0("mkdir -p ", remoteTmp))
analogsea::droplet_upload(droplet, local=localPath, remote=remoteTmp)
analogsea::droplet_ssh(droplet, paste("mv", paste0(remoteTmp, "/", dirName, "/"), paste0("/var/plumber/", path)))

### SYSTEMD ###
serviceName <- paste0("plumber-", path)
Expand Down

0 comments on commit a159aa6

Please sign in to comment.