meztez / plumberDeploy

Other
50 stars 12 forks source link

plumberDeploy::do_remove_api() results in 404 not found error. #14

Closed incredibeau closed 3 years ago

incredibeau commented 3 years ago

Help!

I've been following the instructions in this tutorial exactly (even uploading the provided plumber.R file): https://www.r-bloggers.com/2017/06/deploying-a-minimal-api-using-plumber-on-digitalocean/.

plumberDeploy::do_provision(unstable = T, example = TRUE) works without any errors and will publish the example /hello/ api with no problems. So it's not an issue with SSH.

When I create a new provision without the example:

plumberDeploy::do_deploy_api(id,"test", "path/to/plumber/folder", 8000)

I don't get any errors and get the following feedback that looks like a success message:

[100%] /path/to/plumber/folder/plumber.R
/tmp/HCOBTRZEID
[100%] /private/var/folders/3c/fn1530c15y97dp9fcjr2djh40000gn/T/RtmpBHLpK2/file74a4259dc597
/etc/systemd/system/plumber-hello.service
● plumber-hello.service - Plumber API
     Loaded: loaded (/etc/systemd/system/plumber-hello.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2020-09-28 20:14:57 UTC; 1s ago
   Main PID: 51724 (R)
      Tasks: 2 (limit: 1137)
     Memory: 60.1M
     CGroup: /system.slice/plumber-hello.service
             └─51724 /usr/lib/R/bin/exec/R --no-echo --no-restore -e pr~+~<-~+~plumber::pr('/var/plumber/hello/plumber.R');~+~pr$setDocs(FALSE);~+~~+~pr$run(port=8000)

Sep 28 20:14:57 PredictedJuggernaut systemd[1]: Started Plumber API.
Sep 28 20:14:57 PredictedJuggernaut Rscript[51724]: Running plumber API at http://127.0.0.1:8000
[100%] /private/var/folders/3c/fn1530c15y97dp9fcjr2djh40000gn/T/RtmpBHLpK2/file74a419174fcc
/etc/nginx/sites-available/plumber-apis/hello.conf

However, when I try to curl or navigate to the api: [[IPADDRESS]]/test or to any of the endpoints, I get a 404 error. Can someone help me troubleshoot what is going wrong?

meztez commented 3 years ago

From tutorial provided, endpoint should be http://[[IPADDRESS]]/date

meztez commented 3 years ago

This works on my end.

Local file ./api/plumber.R

#* @get /
function() {
  Sys.Date()
}

Running

id <- plumberDeploy::do_provision(example = FALSE)
plumberDeploy::do_deploy_api(id, "date", "./api/", 8000, docs = TRUE)

Navigating to : [[IPADDRESS]]/date

image

incredibeau commented 3 years ago

Thank you for the quick response. The problem seemed to be that I needed the docs = TRUE parameter in do_deploy_api(). I am able to successfully run:

id <- plumberDeploy::do_provision(example = FALSE)
plumberDeploy::do_deploy_api(id, "date", "./api/", 8000, docs = TRUE)

And can navigate to : [[IPADDRESS]]/date

However, a new problem has emerged. When I update the api (rerun plumberDeploy::do_deploy_api(id, "date", "./api/", 8000, docs = TRUE) ), I get an SSH error:

Error: ssh failed
mv /tmp/IWASQQZTKA/march_api/ /var/plumber/test

My SSH public key is registered using analogsea::keys() and I also have a DO_PAT environmental variable. SSH seems to work on the initial do_provision() and do_deploy_api() but not on subsequent updates. Any idea what could be going wrong.

muschellij2 commented 3 years ago

Could be that test/ already exists, so we may need to do a cp or an rm -rf https://unix.stackexchange.com/questions/9899/how-to-overwrite-target-files-with-mv before mv on line https://github.com/meztez/plumberDeploy/blob/master/R/digital-ocean.R#L321 Best, John

On Tue, Sep 29, 2020 at 3:01 PM Beau Walker notifications@github.com wrote:

Thank you for the quick response. The problem seemed to be that I needed the docs = TRUE parameter in do_deploy_api(). I am able to successfully run:

id <- plumberDeploy::do_provision(example = FALSE) plumberDeploy::do_deploy_api(id, "date", "./api/", 8000, docs = TRUE)

And can navigate to : [[IPADDRESS]]/date

However, a new problem has emerged. When I got to update the api (rerun plumberDeploy::do_deploy_api(id, "date", "./api/", 8000, docs = TRUE) ), I get an SSH error:

Error: ssh failed mv /tmp/IWASQQZTKA/march_api/ /var/plumber/test

My SSH public key is registered using analogsea::keys() and I also have a DO_PAT environmental variable. SSH seems to work on the initial do_provision() and do_deploy_api() but not on subsequent updates. Any idea what could be going wrong.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/meztez/plumberDeploy/issues/14#issuecomment-700918205, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGPLTVJRIDMQBRHJQHTRDSIIVGXANCNFSM4R5ERVCQ .

incredibeau commented 3 years ago

@muschellij2 Thank you. I've also tried removing the API entirely with do_remove_api(id, 'test') and re-uploading with do_deploy_api() and get the same error.

Also, just got a notification that DigitalOcean is having some outages in some resource groups that may be affecting this. Also getting this error:

error in ssh::ssh_info(session = session) : 
  ssh session has been disconnected
muschellij2 commented 3 years ago
library(plumberDeploy)
library(analogsea)
#> 
#> Attaching package: 'analogsea'
#> The following object is masked from 'package:graphics':
#> 
#>     image
library(pagedown)
library(httr)
library(magick)
#> Linking to ImageMagick 6.9.9.39
#> Enabled features: cairo, fontconfig, freetype, lcms, pango, rsvg, webp
#> Disabled features: fftw, ghostscript, x11
#> 
#> Attaching package: 'magick'
#> The following object is masked from 'package:analogsea':
#> 
#>     image_convert
d = droplets()
if (length(d) == 0) {
  droplet = do_provision(example = FALSE)
} else {
  droplet = d[[1]]
}
ip = analogsea:::droplet_ip(droplet)
url = paste0("http://", ip)

path = "date"
applet_url = paste0("http://", ip, "/", path)

do_remove_api(droplet, path = path, delete = TRUE)
#> stopping service: plumber-date
#> disabling service: plumber-date
#> removing service: plumber-date
#> removing config: plumber-date
#> reloading nginx: plumber-date
#> reloading plumber folder: plumber-date
#> <droplet>ConfidentConspiracy (210178483)
#>   IP:        167.172.213.184
#>   Status:    active
#>   Region:    San Francisco 2
#>   Image:     20.04 (LTS) x64
#>   Size:      s-1vcpu-1gb
#>   Volumes:
api = '#* @get /
function() {
  Sys.Date()
}'
tfile = tempfile()
dir.create(tfile)
outfile = file.path(tfile, "plumber.R")
writeLines(api, outfile)
file.exists(outfile)
#> [1] TRUE
readLines(outfile)
#> [1] "#* @get /"    "function() {" "  Sys.Date()" "}"

output_image = tempfile(fileext = ".png")
do_remove_api(droplet, path = path, delete = TRUE)
#> stopping service: plumber-date
#> disabling service: plumber-date
#> removing service: plumber-date
#> removing config: plumber-date
#> reloading nginx: plumber-date
#> reloading plumber folder: plumber-date
#> <droplet>ConfidentConspiracy (210178483)
#>   IP:        167.172.213.184
#>   Status:    active
#>   Region:    San Francisco 2
#>   Image:     20.04 (LTS) x64
#>   Size:      s-1vcpu-1gb
#>   Volumes:

Deploying

plumberDeploy::do_deploy_api(droplet, path, tfile, port = 8000, docs = TRUE,
                             forward = TRUE)
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d764ca0b2a/plumber.R[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d764ca0b2a/plumber.R
#> /tmp/UCHSKBJIYK
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d735f1d7f0[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d735f1d7f0
#> /etc/systemd/system/plumber-date.service
#> ● plumber-date.service - Plumber API
#>      Loaded: loaded (/etc/systemd/system/plumber-date.service; enabled; vendor preset: enabled)
#>      Active: active (running) since Thu 2020-10-01 16:55:36 UTC; 1s ago
#>    Main PID: 52656 (R)
#>       Tasks: 2 (limit: 1137)
#>      Memory: 63.1M
#>      CGroup: /system.slice/plumber-date.service
#>              └─52656 /usr/lib/R/bin/exec/R --no-echo --no-restore -e pr~+~<-~+~plumber::pr('/var/plumber/date/plumber.R');~+~pr$setDocs(TRUE);~+~~+~pr$run(port=8000)
#> 
#> Oct 01 16:55:36 ConfidentConspiracy systemd[1]: Started Plumber API.
#> Oct 01 16:55:36 ConfidentConspiracy Rscript[52656]: Running plumber API at http://127.0.0.1:8000
#> Oct 01 16:55:36 ConfidentConspiracy Rscript[52656]: Running swagger Docs at http://127.0.0.1:8000/__docs__/
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d71897e93b[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d71897e93b
#> /etc/nginx/sites-available/plumber-apis/date.conf
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d71d512d1a[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d71d512d1a
#> /etc/nginx/sites-available/plumber-apis/_forward.conf
pagedown::chrome_print(input = applet_url, output = output_image,
                       format = "png")
image_read(output_image)

res = httr::GET(applet_url)
httr::status_code(res)
#> [1] 200
print(res)
#> Response [http://167.172.213.184/date/]
#>   Date: 2020-10-01 16:55
#>   Status: 200
#>   Content-Type: application/json
#>   Size: 14 B

This should fail now because deleted

do_remove_api(droplet, path = path, delete = TRUE)
#> stopping service: plumber-date
#> disabling service: plumber-date
#> removing service: plumber-date
#> removing config: plumber-date
#> reloading nginx: plumber-date
#> reloading plumber folder: plumber-date
#> <droplet>ConfidentConspiracy (210178483)
#>   IP:        167.172.213.184
#>   Status:    active
#>   Region:    San Francisco 2
#>   Image:     20.04 (LTS) x64
#>   Size:      s-1vcpu-1gb
#>   Volumes:
res = httr::GET(applet_url)
httr::status_code(res)
#> [1] 404
print(res)
#> Response [http://167.172.213.184/date]
#>   Date: 2020-10-01 16:55
#>   Status: 404
#>   Content-Type: text/html
#>   Size: 162 B
#> <html>
#> <head><title>404 Not Found</title></head>
#> <body>
#> <center><h1>404 Not Found</h1></center>
#> <hr><center>nginx/1.18.0 (Ubuntu)</center>
#> </body>
#> </html>

Removing Docs=TRUE

plumberDeploy::do_deploy_api(droplet, path, tfile, port = 8000, docs = FALSE,
                             forward = TRUE)
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d764ca0b2a/plumber.R[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d764ca0b2a/plumber.R
#> /tmp/RQFASCZMTS
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d77242de46[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d77242de46
#> /etc/systemd/system/plumber-date.service
#> ● plumber-date.service - Plumber API
#>      Loaded: loaded (/etc/systemd/system/plumber-date.service; enabled; vendor preset: enabled)
#>      Active: active (running) since Thu 2020-10-01 16:55:50 UTC; 1s ago
#>    Main PID: 52824 (R)
#>       Tasks: 2 (limit: 1137)
#>      Memory: 63.1M
#>      CGroup: /system.slice/plumber-date.service
#>              └─52824 /usr/lib/R/bin/exec/R --no-echo --no-restore -e pr~+~<-~+~plumber::pr('/var/plumber/date/plumber.R');~+~pr$setDocs(TRUE);~+~~+~pr$run(port=8000)
#> 
#> Oct 01 16:55:50 ConfidentConspiracy systemd[1]: Started Plumber API.
#> Oct 01 16:55:51 ConfidentConspiracy Rscript[52824]: Running plumber API at http://127.0.0.1:8000
#> Oct 01 16:55:51 ConfidentConspiracy Rscript[52824]: Running swagger Docs at http://127.0.0.1:8000/__docs__/
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d740f0045[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d740f0045
#> /etc/nginx/sites-available/plumber-apis/date.conf
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d774dab417[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d774dab417
#> /etc/nginx/sites-available/plumber-apis/_forward.conf
pagedown::chrome_print(input = applet_url, output = output_image,
                       format = "png")
image_read(output_image)

res = httr::GET(applet_url)
httr::status_code(res)
#> [1] 200
print(res)
#> Response [http://167.172.213.184/date/]
#>   Date: 2020-10-01 16:55
#>   Status: 200
#>   Content-Type: application/json
#>   Size: 14 B
httr::content(res)
#> [[1]]
#> [1] "2020-10-01"

Removing forward

do_remove_api(droplet, path = path, delete = TRUE)
#> stopping service: plumber-date
#> disabling service: plumber-date
#> removing service: plumber-date
#> removing config: plumber-date
#> reloading nginx: plumber-date
#> reloading plumber folder: plumber-date
#> <droplet>ConfidentConspiracy (210178483)
#>   IP:        167.172.213.184
#>   Status:    active
#>   Region:    San Francisco 2
#>   Image:     20.04 (LTS) x64
#>   Size:      s-1vcpu-1gb
#>   Volumes:
plumberDeploy::do_deploy_api(droplet, path, tfile, port = 8000, docs = FALSE,
                             forward = FALSE)
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d764ca0b2a/plumber.R[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d764ca0b2a/plumber.R
#> /tmp/SEHZUJNLKX
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d7331ed10a[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d7331ed10a
#> /etc/systemd/system/plumber-date.service
#> ● plumber-date.service - Plumber API
#>      Loaded: loaded (/etc/systemd/system/plumber-date.service; enabled; vendor preset: enabled)
#>      Active: active (running) since Thu 2020-10-01 16:56:05 UTC; 1s ago
#>    Main PID: 52982 (R)
#>       Tasks: 2 (limit: 1137)
#>      Memory: 63.1M
#>      CGroup: /system.slice/plumber-date.service
#>              └─52982 /usr/lib/R/bin/exec/R --no-echo --no-restore -e pr~+~<-~+~plumber::pr('/var/plumber/date/plumber.R');~+~pr$setDocs(TRUE);~+~~+~pr$run(port=8000)
#> 
#> Oct 01 16:56:05 ConfidentConspiracy systemd[1]: Started Plumber API.
#> Oct 01 16:56:05 ConfidentConspiracy Rscript[52982]: Running plumber API at http://127.0.0.1:8000
#> Oct 01 16:56:06 ConfidentConspiracy Rscript[52982]: Running swagger Docs at http://127.0.0.1:8000/__docs__/
#> [100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d72c2e01be[100%] /private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpDmA9Mf/file27d72c2e01be
#> /etc/nginx/sites-available/plumber-apis/date.conf
pagedown::chrome_print(input = applet_url, output = output_image,
                       format = "png")
image_read(output_image)

res = httr::GET(applet_url)
httr::status_code(res)
#> [1] 200
print(res)
#> Response [http://167.172.213.184/date/]
#>   Date: 2020-10-01 16:56
#>   Status: 200
#>   Content-Type: application/json
#>   Size: 14 B
httr::content(res)
#> [[1]]
#> [1] "2020-10-01"

Created on 2020-10-01 by the reprex package (v0.3.0.9001)

Session info sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.2 (2020-06-22) #> os macOS Catalina 10.15.6 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/New_York #> date 2020-10-01 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> analogsea * 0.8.0 2020-01-30 [2] CRAN (R 4.0.0) #> askpass 1.1 2019-01-13 [2] CRAN (R 4.0.0) #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.0) #> backports 1.1.10 2020-09-15 [1] CRAN (R 4.0.2) #> cli 2.0.2 2020-02-28 [2] CRAN (R 4.0.0) #> crayon 1.3.4 2017-09-16 [2] CRAN (R 4.0.0) #> credentials 1.3.0 2020-07-21 [2] CRAN (R 4.0.2) #> curl 4.3 2019-12-02 [2] CRAN (R 4.0.0) #> digest 0.6.25 2020-02-23 [2] CRAN (R 4.0.0) #> ellipsis 0.3.1 2020-05-15 [2] CRAN (R 4.0.0) #> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.0) #> fansi 0.4.1 2020-01-08 [2] CRAN (R 4.0.0) #> fs 1.5.0 2020-07-31 [2] CRAN (R 4.0.2) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2) #> highr 0.8 2019-03-20 [2] CRAN (R 4.0.0) #> htmltools 0.5.0 2020-06-16 [2] CRAN (R 4.0.0) #> httpuv 1.5.4 2020-06-06 [2] CRAN (R 4.0.0) #> httr * 1.4.2 2020-07-20 [2] CRAN (R 4.0.2) #> jsonlite 1.7.1 2020-09-07 [1] CRAN (R 4.0.2) #> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.2) #> later 1.1.0.1 2020-06-05 [2] CRAN (R 4.0.0) #> lifecycle 0.2.0 2020-03-06 [2] CRAN (R 4.0.0) #> magick * 2.4.0 2020-06-23 [2] CRAN (R 4.0.0) #> magrittr 1.5 2014-11-22 [2] CRAN (R 4.0.0) #> mime 0.9 2020-02-04 [2] CRAN (R 4.0.0) #> openssl 1.4.2 2020-06-27 [2] CRAN (R 4.0.0) #> pagedown * 0.10 2020-05-04 [2] CRAN (R 4.0.1) #> pillar 1.4.6 2020-07-10 [2] CRAN (R 4.0.2) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.0) #> plumberDeploy * 0.1.3.9000 2020-09-30 [1] local #> png 0.1-7 2013-12-03 [2] CRAN (R 4.0.0) #> processx 3.4.4 2020-09-03 [1] CRAN (R 4.0.2) #> promises 1.1.1 2020-06-09 [2] CRAN (R 4.0.0) #> ps 1.3.4 2020-08-11 [2] CRAN (R 4.0.2) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.0.0) #> R6 2.4.1 2019-11-12 [2] CRAN (R 4.0.0) #> Rcpp 1.0.5 2020-07-06 [2] CRAN (R 4.0.0) #> reprex 0.3.0.9001 2020-09-30 [1] Github (tidyverse/reprex@d3fc4b8) #> rlang 0.4.7.9000 2020-09-09 [1] Github (r-lib/rlang@60c0151) #> rmarkdown 2.3 2020-06-18 [2] CRAN (R 4.0.0) #> rstudioapi 0.11 2020-02-07 [2] CRAN (R 4.0.0) #> servr 0.18 2020-07-28 [2] CRAN (R 4.0.2) #> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.0) #> ssh 0.7.0 2020-07-21 [2] CRAN (R 4.0.2) #> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.0.0) #> styler 1.3.2 2020-02-23 [2] CRAN (R 4.0.0) #> sys 3.4 2020-07-23 [2] CRAN (R 4.0.2) #> tibble 3.0.3 2020-07-10 [2] CRAN (R 4.0.2) #> vctrs 0.3.4 2020-08-29 [1] CRAN (R 4.0.2) #> websocket 1.3.1 2020-07-13 [2] CRAN (R 4.0.2) #> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2) #> xfun 0.18 2020-09-29 [1] CRAN (R 4.0.2) #> xml2 1.3.2 2020-04-23 [2] CRAN (R 4.0.0) #> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.0.0) #> #> [1] /Users/johnmuschelli/Library/R/4.0/library #> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
muschellij2 commented 3 years ago

@incredibeau is this resolved?