Last active
August 1, 2018 21:51
-
-
Save HanjoStudy/0835966d819ae8a524b6be5543838904 to your computer and use it in GitHub Desktop.
Start multiple Selenium or Rstudio containers in script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
args = commandArgs(trailingOnly=TRUE) | |
library(purrr) | |
if (length(args)==0) { | |
stop("At least one argument must be supplied", call.=FALSE) | |
} | |
num_containers <- args[1] | |
if (length(args) > 1) { | |
user <- args[2] | |
pass <- args[3] | |
} else { | |
user <- "training" | |
pass <- "workshop" | |
} | |
cat("Number of Rstudio Docker containers starting up ->", num_containers, "\n") | |
rstudio_start <- possibly(function(x) { | |
rstudio <- 7000 + x | |
docker <- gsub("\n","", paste0("docker run --name rstudio",x," | |
-v /dev/shm:/dev/shm -v /$(pwd):/home/rstudio/material -d -p ",rstudio,":8787 | |
-e USER=",user," -e PASSWORD=",pass," rocker/tidyverse:latest", collapse = " ")) | |
system(docker) | |
}, NULL) | |
for(i in 1:num_containers){ | |
cat("Starting up container", i, "now\n") | |
x <- rstudio_start(i) | |
if(x == 0){ | |
cat("Success!\n") | |
} else { | |
cat("Failed...\n") | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
args = commandArgs(trailingOnly=TRUE) | |
library(purrr) | |
if (length(args)==0) { | |
stop("At least one argument must be supplied", call.=FALSE) | |
} | |
num_containers <- args[1] | |
cat("Number of Selenium Docker containers starting up ->", num_containers, "\n") | |
sel_start <- possibly(function(x) { | |
selenium <- 4444 + x | |
vnc <- 5900 + x | |
docker <- gsub("\n","", paste0("docker run --name chrome",x," | |
-v /dev/shm:/dev/shm -d -p ",selenium,":4444 | |
-p ",vnc,":5900 selenium/standalone-chrome-debug:latest", collapse = " ")) | |
system(docker) | |
}, NULL) | |
for(i in 1:num_containers){ | |
cat("Starting up container", i, "now\n") | |
x <- sel_start(i) | |
if(x == 0){ | |
cat("Success!\n") | |
} else { | |
cat("Failed...\n") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment