diff --git a/DESCRIPTION b/DESCRIPTION index 4c884e9..8830904 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: plumberDeploy Type: Package Title: Plumber Deployment -Version: 0.2.1.10000 +Version: 0.2.2 Roxygen: list(markdown = TRUE) Authors@R: c( person("Bruno", "Tremblay", role = c("cre", "ctb"), email = "cran@neoxone.com"), @@ -25,4 +25,3 @@ Imports: utils BugReports: https://github.com/meztez/plumberDeploy/issues URL: https://github.com/meztez/plumberDeploy -SystemRequirements: libssh >= 0.6.0 (the original, not libssh2) diff --git a/R/digital-ocean.R b/R/digital-ocean.R index 61d77fb..5a6076f 100644 --- a/R/digital-ocean.R +++ b/R/digital-ocean.R @@ -78,19 +78,16 @@ do_provision <- function(droplet, unstable=FALSE, example=TRUE, ...){ } droplet <- do.call(analogsea::droplet_create, createArgs) - - # I often still get a closed port after droplet_wait returns. Buffer for just a bit - Sys.sleep(25) + Sys.sleep(3) # Refresh the droplet; sometimes the original one doesn't yet have a network interface. - droplet <- analogsea::droplet(id=droplet$id) + droplet <- with_retries(analogsea::droplet(id=droplet$id)) } # Provision - lines <- droplet_capture(droplet, 'swapon | grep "/swapfile" | wc -l', keyfile = keyfile) + lines <- with_retries(droplet_capture(droplet, 'swapon | grep "/swapfile" | wc -l', keyfile = keyfile)) if (lines != "1"){ analogsea::ubuntu_add_swap(droplet) - Sys.sleep(5) } do_install_plumber(droplet, unstable) @@ -108,32 +105,41 @@ do_install_plumber = function(droplet, unstable, ...) { analogsea::droplet_ssh( droplet, "sudo echo 'DEBIAN_FRONTEND=noninteractive' >> /etc/environment", - "export R_VERSION=%s.%s" |> sprintf(R.version[["major"]], R.version[["minor"]]), - "curl -O https://cdn.rstudio.com/r/ubuntu-2404/pkgs/r-${R_VERSION}_1_amd64.deb", - "sudo apt-get update -y", - "sudo apt-get install -y ./r-${R_VERSION}_1_amd64.deb", - "sudo ln -s -f /opt/R/${R_VERSION}/bin/R /usr/local/bin/R", - "sudo ln -s -f /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript", + "curl -O https://cdn.rstudio.com/r/ubuntu-2404/pkgs/r-%s.%s_1_amd64.deb" |> sprintf(R.version[["major"]], R.version[["minor"]]), + ... + ) + with_retries( + analogsea::droplet_ssh( + droplet, + "sudo apt-get update -y", + "sudo apt-get install -y ./r-%s.%s_1_amd64.deb" |> sprintf(R.version[["major"]], R.version[["minor"]]), + ... + ) + ) + analogsea::droplet_ssh( + droplet, + "sudo ln -s -f /opt/R/%s.%s/bin/R /usr/local/bin/R" |> sprintf(R.version[["major"]], R.version[["minor"]]), + "sudo ln -s -f /opt/R/%s.%s/bin/Rscript /usr/local/bin/Rscript" |> sprintf(R.version[["major"]], R.version[["minor"]]), ... ) - Sys.sleep(3) install_plumber(droplet, unstable, ...) install_api(droplet, ...) - Sys.sleep(3) install_nginx(droplet, ...) - Sys.sleep(3) install_firewall(droplet, ...) } install_plumber <- function(droplet, unstable, ...){ - analogsea::ubuntu_apt_get_install(droplet, "libssl-dev", "make", "libsodium-dev", "libcurl4-openssl-dev", ...) + with_retries( + analogsea::ubuntu_apt_get_install(droplet, "libssl-dev", "make", "libsodium-dev", "libcurl4-openssl-dev", ...) + ) if (unstable){ analogsea::install_r_package(droplet, "remotes", repo = "https://packagemanager.posit.co/cran/__linux__/noble/latest", ...) analogsea::droplet_ssh(droplet, "Rscript -e \"remotes::install_github('rstudio/plumber')\"", ...) } else { analogsea::install_r_package(droplet, "plumber", repo = "https://packagemanager.posit.co/cran/__linux__/noble/latest", ...) + } } @@ -176,7 +182,7 @@ install_firewall <- function(droplet, ...){ } install_nginx <- function(droplet, ...){ - analogsea::ubuntu_apt_get_install(droplet, "nginx", ...) + with_retries(analogsea::ubuntu_apt_get_install(droplet, "nginx", ...)) analogsea::droplet_ssh(droplet, "rm -f /etc/nginx/sites-enabled/default", ...) # Disable the default site analogsea::droplet_ssh(droplet, "mkdir -p /var/certbot", ...) analogsea::droplet_ssh(droplet, "mkdir -p /etc/nginx/sites-available/plumber-apis/", ...) @@ -600,5 +606,27 @@ do_ip = function(droplet, path) { return(ip) } +with_retries <- with_retries <- function(expr, retries = 5L) { + attempt <- 1L + while (attempt <= retries) { + no_error <- TRUE + res <- tryCatch( + eval.parent(substitute(expr)), + error = function(e) { + message(sprintf("Error encountered : %s\n", e |> as.character())) + no_error <<- FALSE + } + ) + if (no_error) break + message(paste("Retrying attemps", attempt, "in", 3^attempt, "seconds.\n")) + Sys.sleep(3^attempt) + attempt <- attempt + 1L + if (attempt > retries) { + stop("Expression could not be evaluated.") + } + } + return(res) +} + # nocov end diff --git a/cran-comments.md b/cran-comments.md index a995478..43335f9 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,13 +1,5 @@ -## Test environments -* local R installation, R 4.0.2 -* ubuntu 16.04 (on travis-ci), R 4.0.2 -* win-builder (devel) - ## R CMD check results -0 errors | 0 warnings | 1 note - -* This is a new release. +0 errors ✔ | 0 warnings ✔ | 0 notes ✔ ---- -Fixes \value issues in Rd files, fixes ::: in examples, and fixes authors. \ No newline at end of file +R CMD check succeeded