Skip to content

Commit 9b6fd85

Browse files
authored
added functions for running flowr through docker (#34)
* added functions for running flowr through docker * set up docker in tests for windows & mac * skip docker tests on windows and mac
1 parent 874b1e2 commit 9b6fd85

10 files changed

+111
-5
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
export(connect)
44
export(disconnect)
5+
export(exec_docker_command)
56
export(exec_flowr)
7+
export(exec_flowr_docker)
68
export(exec_node_command)
79
export(get_default_node_base_dir)
810
export(install_flowr)

R/node.R renamed to R/flowr_local.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ exec_flowr <- function(args, verbose = FALSE, base_dir = get_default_node_base_d
7979
exec_node_command("node", c(flowr_path, args), verbose, base_dir, background)
8080
}
8181

82+
#' Executes a local version of the flowR CLI with the given arguments in the given directory.
83+
#' This function expects docker to exist on the system.
84+
#'
85+
#' @param docker_args Additional arguments to pass to docker, as a character vector.
86+
#' @param flowr_ver The version of flowR to use
87+
#' @param flowr_args The arguments to pass to the flowR CLI, as a character vector.
88+
#' @param verbose Whether to print out information about the commands being executed.
89+
#' @param cmd The command to use for docker. Defaults to "docker".
90+
#' @param background Whether the command should be executed as a background process.
91+
#' @return The return value of the [exec_node_command()] call, which is the exit code if background is false, or the pid if background is true.
92+
#'
93+
#' @export
94+
exec_flowr_docker <- function(docker_args, flowr_ver, flowr_args, verbose = FALSE, cmd = "docker", background = FALSE) {
95+
exec_docker_command(c("run", "--rm", docker_args, paste0("eagleoutice/flowr:", flowr_ver), flowr_args), verbose, cmd, background)
96+
}
97+
8298
#' Executes the given Node subcommand in the given arguments in the given directory.
8399
#' This function expects Node to have been installed using [install_node()].
84100
#'
@@ -104,6 +120,27 @@ exec_node_command <- function(app = c("node", "npm", "npx"), args, verbose = FAL
104120
}
105121
}
106122

123+
#' Executes the given docker command in the given directory.
124+
#' This function expects docker to exist on the system.
125+
#'
126+
#' @param args The arguments to pass to the docker command, as a character vector.
127+
#' @param verbose Whether to print out information about the commands being executed.
128+
#' @param cmd The command to use for docker. Defaults to "docker".
129+
#' @param background Whether the command should be executed as a background process.
130+
#' @return The return value of the call, which is the exit code if background is false, or the pid if background is true.
131+
#'
132+
#' @export
133+
exec_docker_command <- function(args, verbose = FALSE, cmd = "docker", background = FALSE) {
134+
if (verbose) {
135+
print(paste0("Executing ", cmd, " ", paste0(args, collapse = " ")))
136+
}
137+
if (background) {
138+
return(sys::exec_background(cmd, args))
139+
} else {
140+
return(sys::exec_wait(cmd, args))
141+
}
142+
}
143+
107144
#' Returns the default node base directory to use when installing Node, which is the directory that the package with the given name is installed in.
108145
#'
109146
#' @param pkg_dir_name The name of the package to find the installation directory of. By default, this is "flowr", the name of this package.

man/exec_docker_command.Rd

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/exec_flowr.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/exec_flowr_docker.Rd

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/exec_node_command.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_default_node_base_dir.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/install_flowr.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/install_node.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-docker.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test_that("run flowr (docker)", {
2+
skip_on_os("windows")
3+
skip_on_os("mac")
4+
5+
expect_output(exec_flowr_docker(c(), "2.0.11", c("--version"), TRUE), paste0("flowR: ", "2.0.11"))
6+
})

0 commit comments

Comments
 (0)