mirror of https://git.sr.ht/~hrbrmstr/splashr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.6 KiB
74 lines
2.6 KiB
#' Retrieve the Docker image for Splash
|
|
#'
|
|
#' @md
|
|
#' @param tag Splash Docker image tag to install
|
|
#' @export
|
|
#' @family splash_docker_helpers
|
|
#' @examples \dontrun{
|
|
#' install_splash()
|
|
#' splash_container <- start_splash()
|
|
#' stop_splash(splash_container)
|
|
#' }
|
|
install_splash <- function(tag="3.0") {
|
|
client <- docker::docker$from_env()
|
|
res <- client$api$pull("scrapinghub/splash", tag)
|
|
res <- jsonlite::stream_in(textConnection(res), verbose=FALSE)
|
|
invisible(lapply(res$status, function(x) { message(x) }))
|
|
}
|
|
|
|
#' Start a Splash server Docker container
|
|
#'
|
|
#' If using this in an automation context, you should consider adding a
|
|
#' `Sys.sleep(3)` (or higher) after starting the docker container.
|
|
#'
|
|
#' @param tag Splash Docker image tag to start
|
|
#' @note you need Docker running on your system and have pulled the container with
|
|
#' [install_splash] for this to work. You should save the resultant
|
|
#' object for use in [stop_splash] otherwise you'll have to kill it from the
|
|
#' command line interface.
|
|
#' @family splash_docker_helpers
|
|
#' @return `docker` `container` object
|
|
#' @export
|
|
#' @examples \dontrun{
|
|
#' install_splash()
|
|
#' splash_container <- start_splash()
|
|
#' stop_splash(splash_container)
|
|
#' }
|
|
start_splash <- function(tag="3.0") {
|
|
|
|
client <- docker::docker$from_env()
|
|
|
|
splash_inst <- client$containers$run(
|
|
sprintf("scrapinghub/splash:%s", tag), name="splashr",
|
|
detach=TRUE, ports=list('8050/tcp'='8050', '5023/tcp'='5023', '8051/tcp'='8051')
|
|
)
|
|
|
|
invisible(splash_inst)
|
|
|
|
}
|
|
|
|
#' Stop a running a Splash server Docker container
|
|
#'
|
|
#' @param splash_container Docker `container` object created by [start_splash()]
|
|
#' @note you need Docker running on your system and have pulled the container with
|
|
#' [install_splash()] and started the Splash container with [start_splash()] for this
|
|
#' to work. You will need the `container` object from [start_splash()] for this to work.
|
|
#' @family splash_docker_helpers
|
|
#' @export
|
|
#' @examples \dontrun{
|
|
#' install_splash()
|
|
#' splash_container <- start_splash()
|
|
#' stop_splash(splash_container)
|
|
#' }
|
|
stop_splash <- function(splash_container) {
|
|
splash_container$stop()
|
|
splash_container$remove()
|
|
}
|
|
|
|
|
|
# @param add_tempdir This is `FALSE` initially since you could try to run
|
|
# the splash image on a remote system. It has to be a local one for this to work.
|
|
# If `TRUE` then a local temporary directory (made with [tempdir()])
|
|
# will be added to the mount configuration for use with [render_file()]. You will need to
|
|
# ensure the necessary system temp dirs are accessible as a mounts. For
|
|
# macOS this means adding `/private` to said Docker config.
|
|
|