├── .github ├── .gitignore └── workflows │ ├── pkgdown.yaml │ └── R-CMD-check.yaml ├── examples ├── bolasso │ ├── .renvignore │ ├── .gitignore │ ├── README.md │ ├── run.R │ └── index.qmd ├── ggplot2 │ ├── .renvignore │ ├── figures │ │ └── .gitignore │ ├── .gitignore │ ├── README.md │ ├── plot.R │ ├── run.R │ └── data │ │ ├── mtcars.csv │ │ └── mtcars_unnecessary.csv ├── simple │ ├── .renvignore │ ├── .gitignore │ ├── dependencies.R │ ├── README.md │ └── run.R ├── diff_dockerfile_and_context │ ├── .renvignore │ ├── .gitignore │ ├── run.R │ └── mtcars.csv └── README.md ├── man ├── figures │ ├── logo.png │ ├── logo-no-bg.png │ ├── tugboat-logo.jpg │ └── hex-sticker.R ├── build.Rd ├── binderize.Rd └── create.Rd ├── _pkgdown.yml ├── NAMESPACE ├── .Rbuildignore ├── tugboat.Rproj ├── cran-comments.md ├── tests ├── testthat.R └── testthat │ ├── test-binderize.R │ ├── test-create.R │ └── test-build.R ├── .gitignore ├── DESCRIPTION ├── R ├── dockerfile.R ├── utils.R ├── create.R ├── build.R └── binderize.R ├── NEWS.md ├── README.md └── LICENSE.md /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /examples/bolasso/.renvignore: -------------------------------------------------------------------------------- 1 | run.R -------------------------------------------------------------------------------- /examples/ggplot2/.renvignore: -------------------------------------------------------------------------------- 1 | run.R -------------------------------------------------------------------------------- /examples/simple/.renvignore: -------------------------------------------------------------------------------- 1 | run.R -------------------------------------------------------------------------------- /examples/diff_dockerfile_and_context/.renvignore: -------------------------------------------------------------------------------- 1 | run.R -------------------------------------------------------------------------------- /examples/ggplot2/figures/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /examples/simple/.gitignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | .dockerignore 3 | renv.lock 4 | -------------------------------------------------------------------------------- /examples/bolasso/.gitignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | .dockerignore 3 | renv.lock 4 | -------------------------------------------------------------------------------- /examples/ggplot2/.gitignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | .dockerignore 3 | renv.lock 4 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmolitor/tugboat/HEAD/man/figures/logo.png -------------------------------------------------------------------------------- /examples/diff_dockerfile_and_context/.gitignore: -------------------------------------------------------------------------------- 1 | **Dockerfile 2 | **.dockerignore 3 | renv.lock 4 | -------------------------------------------------------------------------------- /man/figures/logo-no-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmolitor/tugboat/HEAD/man/figures/logo-no-bg.png -------------------------------------------------------------------------------- /man/figures/tugboat-logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmolitor/tugboat/HEAD/man/figures/tugboat-logo.jpg -------------------------------------------------------------------------------- /examples/simple/dependencies.R: -------------------------------------------------------------------------------- 1 | library(jsonlite) 2 | library(rprojroot) 3 | library(stringi) 4 | library(withr) -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://dmolitor.com/tugboat/ 2 | template: 3 | bootstrap: 5 4 | bootswatch: sandstone 5 | 6 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(binderize) 4 | export(build) 5 | export(create) 6 | -------------------------------------------------------------------------------- /examples/simple/README.md: -------------------------------------------------------------------------------- 1 | # Simple 2 | 3 | An example with four packages that all have no dependencies. The packages 4 | are jsonlite, rprojroot, stringi, and withr. This example builds very 5 | quickly. 6 | -------------------------------------------------------------------------------- /examples/ggplot2/README.md: -------------------------------------------------------------------------------- 1 | # ggplot2 2 | 3 | An example where ggplot2 is the only dependency and we make a simple plot. 4 | This image still takes quite a while to build since ggplot2 has so many 5 | dependencies. 6 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^renv$ 2 | ^renv\.lock$ 3 | ^tugboat\.Rproj$ 4 | ^\.Rproj\.user$ 5 | ^LICENSE\.md$ 6 | ^\.dockerignore$ 7 | ^examples$ 8 | ^_pkgdown\.yml$ 9 | ^docs$ 10 | ^pkgdown$ 11 | ^\.github$ 12 | ^cran-comments\.md$ 13 | ^CRAN-SUBMISSION$ 14 | -------------------------------------------------------------------------------- /tugboat.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | -------------------------------------------------------------------------------- /examples/ggplot2/plot.R: -------------------------------------------------------------------------------- 1 | library(ggplot2) 2 | 3 | df <- read.csv("/ggplot2/data/mtcars.csv") 4 | 5 | ggplot(df, aes(x = hp, y = wt, color = factor(cyl))) + 6 | geom_point() + 7 | facet_wrap(~ factor(am), nrow = 3) 8 | 9 | ggsave("/ggplot2/figures/mtcars.png", height = 4, width = 6) 10 | -------------------------------------------------------------------------------- /examples/bolasso/README.md: -------------------------------------------------------------------------------- 1 | # Boostrapped Lasso - Variable Selection Analysis 2 | 3 | This directory contains a simple predictive modeling analysis with 4 | [Quarto](https://quarto.org/) and R. It serves as a simple test-case 5 | for tugboat. 6 | 7 | NOTE: this example has quite a few dependencies so building the docker image 8 | will take quite a while. 9 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | # Test environments 2 | 3 | local macOS 15.6.1 install: R-release 4 | Ubuntu-latest (on GitHub actions): R-devel, R-release, R-oldrel 5 | macOS-latest (on GitHub actions): R-devel 6 | Windows Server 2025 (on GitHub actions): R-devel 7 | Win-builder: R-devel, R-release 8 | 9 | 10 | ## R CMD check results 11 | 12 | 0 errors | 0 warnings | 0 notes 13 | 14 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | Each directory in `tugboat/examples` shows a worked example of how to use tugboat 2 | to convert an analysis directory into a corresponding Docker container. In each example, 3 | `run.R` is the script that demonstrates how to use tugboat to generate the Dockerfile/container. 4 | If you'd like to build the examples, you can interactively run/experiment with the code in `run.R`. 5 | All other files are analysis files. 6 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(tugboat) 11 | 12 | test_check("tugboat") 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Random stuff 2 | .DS_Store 3 | 4 | # Jupyter Notebook 5 | .ipynb_checkpoints 6 | 7 | # IPython 8 | profile_default/ 9 | ipython_config.py 10 | 11 | 12 | # Environments 13 | .env 14 | .venv 15 | env/ 16 | venv/ 17 | ENV/ 18 | env.bak/ 19 | venv.bak/ 20 | .Rproj.user 21 | renv/ 22 | 23 | # Build objects 24 | build 25 | __pycache__ 26 | dist 27 | *.egg-info 28 | 29 | # R stuff 30 | .Rhistory 31 | .Rprofile 32 | 33 | tugboat.yml 34 | tugboat.lock 35 | Dockerfile 36 | .dockerignore 37 | docs 38 | CRAN-SUBMISSION 39 | -------------------------------------------------------------------------------- /man/figures/hex-sticker.R: -------------------------------------------------------------------------------- 1 | library(hexSticker) 2 | library(magick) 3 | 4 | img <- image_read(here::here("man", "figures", "tugboat-logo.jpg")) 5 | img <- img |> 6 | image_convert("png") |> 7 | image_fill(color = "none") |> 8 | image_annotate( 9 | text = "tugboat", 10 | font = "Brush Script MT", 11 | style = "normal", 12 | weight = 1000, 13 | size = 70, 14 | location = "+165+390", 15 | color = "gray30" 16 | ) 17 | 18 | sticker( 19 | filename = here::here("man", "figures", "logo.png"), 20 | white_around_sticker = TRUE, 21 | img, 22 | package = "", 23 | s_x = 1.05, 24 | s_y = 1.2, 25 | s_width = 2, 26 | s_height = 14, 27 | h_fill = "white", 28 | h_color = "#A9A9A9" 29 | ) 30 | 31 | 32 | # Remove the background at remove.bg -------------------------------------------------------------------------------- /examples/bolasso/run.R: -------------------------------------------------------------------------------- 1 | # Load tugboat 2 | devtools::load_all(here::here()) 3 | 4 | # Create the Dockerfile 5 | dock <- create( 6 | project = here::here("examples/bolasso"), 7 | FROM = "rocker/rstudio", 8 | as = here::here("examples/bolasso/Dockerfile"), 9 | exclude = c("run.R") 10 | ) 11 | 12 | # Build the image 13 | image_name <- build( 14 | dockerfile = here::here("examples/bolasso/Dockerfile"), 15 | image_name = "tugboat_bolasso", 16 | platforms = "linux/arm64", 17 | build_context = here::here("examples/bolasso") 18 | ) 19 | 20 | # Run the image 21 | system( 22 | "docker run --rm -ti -e DISABLE_AUTH=true -e ROOT=true -p 8787:8787 tugboat_bolasso:latest", 23 | receive.console.signals = TRUE 24 | ) 25 | # Open the following url in your browser: http://localhost:8787 -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: tugboat 2 | Title: Build a Docker Image from a Directory or Project 3 | Version: 0.1.5 4 | Authors@R: 5 | person(given = "Daniel", 6 | family = "Molitor", 7 | role = c("aut", "cph", "cre"), 8 | email = "molitdj97@gmail.com") 9 | Description: Simple utilities to generate a Dockerfile from a directory or 10 | project, build the corresponding Docker image, push the image to 11 | DockerHub, and publicly share the project via Binder. 12 | Imports: 13 | here, 14 | renv (>= 1.0.0) 15 | Suggests: 16 | gert, 17 | usethis, 18 | yaml, 19 | rmarkdown, 20 | testthat (>= 3.0.0) 21 | License: GPL (>= 3) 22 | Encoding: UTF-8 23 | Roxygen: list(markdown = TRUE) 24 | RoxygenNote: 7.3.3 25 | URL: https://www.dmolitor.com/tugboat/ 26 | Config/testthat/edition: 3 27 | Config/testthat/start-first: create 28 | Language: en-US 29 | -------------------------------------------------------------------------------- /examples/simple/run.R: -------------------------------------------------------------------------------- 1 | # Load tugboat 2 | devtools::load_all(here::here()) 3 | 4 | # Create the Dockerfile 5 | dock <- create(project = here::here("examples/simple"), FROM = "rocker/r-ver") 6 | 7 | # Build the docker image 8 | image_name <- build( 9 | dockerfile = here::here("examples/simple/Dockerfile"), 10 | image_name = "tugboat_simple", 11 | platforms = "linux/arm64", 12 | build_context = here::here("examples/simple") 13 | ) 14 | 15 | # Check installed packages 16 | image_packages <- system( 17 | paste0( 18 | "docker run --rm ", 19 | image_name, 20 | " Rscript -e 'sort(row.names(installed.packages()))'" 21 | ), 22 | intern = TRUE 23 | ) 24 | image_packages <- gsub("\\[\\d+\\]", "", image_packages) 25 | image_packages <- unlist(strsplit(gsub('"', "", paste(image_packages, collapse = " ")), "\\s+")) 26 | image_packages <- image_packages[image_packages != ""] 27 | 28 | # Ensure that all expected packages are installed 29 | testthat::expect_in( 30 | c("jsonlite", "renv", "rprojroot", "stringi", "withr"), 31 | image_packages 32 | ) 33 | -------------------------------------------------------------------------------- /examples/diff_dockerfile_and_context/run.R: -------------------------------------------------------------------------------- 1 | # Load tugboat 2 | devtools::load_all(here::here()) 3 | 4 | # Create the Dockerfile 5 | exclude <- c("./mtcars.csv") 6 | dock <- create( 7 | project = here::here("examples/diff_dockerfile_and_context/"), 8 | as = here::here("examples/diff_dockerfile_and_context/docker/Dockerfile"), 9 | FROM = "r-base", 10 | exclude = exclude 11 | ) 12 | 13 | # Build the docker image 14 | image_name <- build( 15 | dockerfile = here::here("examples/diff_dockerfile_and_context/docker/Dockerfile"), 16 | image_name = "tugboat_diff_df_context", 17 | platforms = "linux/arm64", 18 | build_context = here::here("examples/diff_dockerfile_and_context/") 19 | ) 20 | 21 | # Check copied files 22 | files <- system( 23 | paste0( 24 | "docker run --rm ", 25 | image_name, 26 | " ls -la /diff_dockerfile_and_context" 27 | ), 28 | intern = TRUE 29 | ) |> strsplit(split = " ") |> 30 | (\(x) lapply(x, \(y) y[[length(y)]]))() |> 31 | unlist() 32 | 33 | # Ensure that all expected packages are installed 34 | testthat::expect_false(exclude %in% files) 35 | -------------------------------------------------------------------------------- /examples/bolasso/index.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Bolasso example" 3 | format: 4 | html: 5 | code-fold: false 6 | self-contained: true 7 | toc: true 8 | toc-depth: 3 9 | --- 10 | 11 | ### Load requisite packages and data 12 | 13 | ```{r echo=TRUE, message=FALSE, warning=FALSE} 14 | library(bolasso) 15 | library(mlbench) 16 | 17 | data(PimaIndiansDiabetes, package = "mlbench") 18 | 19 | # Quick overview of the dataset 20 | str(PimaIndiansDiabetes) 21 | ``` 22 | 23 | First, let's create a train/test split of our data, and then run 100-fold 24 | bootstrapped Lasso with `glmnet`. 25 | 26 | ```{r} 27 | train_idx <- sample(1:nrow(PimaIndiansDiabetes), round(0.7*nrow(PimaIndiansDiabetes))) 28 | train <- PimaIndiansDiabetes[train_idx, ] 29 | test <- PimaIndiansDiabetes[-train_idx, ] 30 | 31 | model <- bolasso( 32 | diabetes ~ ., 33 | data = train, 34 | n.boot = 100, 35 | progress = FALSE, 36 | family = "binomial" 37 | ) 38 | ``` 39 | 40 | 41 | ### Variable selection 42 | 43 | Print selected variables: 44 | ```{r} 45 | selected_vars(model, threshold = 0.9, select = "lambda.min") 46 | ``` 47 | 48 | Plot selection thresholds: 49 | ```{r} 50 | plot(model, threshold = 0.9) 51 | ``` -------------------------------------------------------------------------------- /examples/ggplot2/run.R: -------------------------------------------------------------------------------- 1 | # Load tugboat 2 | devtools::load_all(here::here()) 3 | 4 | # Create the Dockerfile 5 | dock <- create( 6 | project = here::here("examples/ggplot2"), 7 | FROM = "rocker/r-ver", 8 | as = here::here("examples/ggplot2/Dockerfile"), 9 | exclude = c("data/mtcars_unnecessary.csv", "run.R") 10 | ) 11 | 12 | # Build the image 13 | image_name <- build( 14 | dockerfile = here::here("examples/ggplot2/Dockerfile"), 15 | image_name = "tugboat_ggplot2", 16 | platforms = "linux/arm64", 17 | build_context = here::here("examples/ggplot2") 18 | ) 19 | 20 | # Run the plot.R script in the Docker container and save the plot locally 21 | system( 22 | paste0( 23 | "docker run --rm -v ", 24 | here::here("examples/ggplot2/figures"), 25 | ":/ggplot2/figures ", 26 | image_name, 27 | " Rscript /ggplot2/plot.R" 28 | ), 29 | receive.console.signals = TRUE 30 | ) 31 | 32 | # List all files in the container's /ggplot2/data directory 33 | # If working correctly mtcars_unnecessary.csv should not be there 34 | # Should only be mtcars.csv 35 | system( 36 | paste0( 37 | "docker run --rm ", 38 | image_name, 39 | " ls -la /ggplot2/data" 40 | ), 41 | receive.console.signals = TRUE 42 | ) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-binderize.R: -------------------------------------------------------------------------------- 1 | test_that("Binderizing project works as expected", { 2 | testthat::skip_on_cran() 3 | if (!interactive()) { 4 | skip("Tests only run interactively") 5 | } 6 | 7 | if (file.exists(here::here("examples/simple/Dockerfile"))) { 8 | file.remove(here::here("examples/simple/Dockerfile")) 9 | } 10 | if (file.exists(here::here("examples/simple/renv.lock"))) { 11 | file.remove(here::here("examples/simple/renv.lock")) 12 | } 13 | 14 | dock <- create( 15 | project = here::here("examples/simple/"), 16 | FROM = paste0("posit/r-base:", R.version$major, ".", R.version$minor, "-jammy"), 17 | exclude = c("run.R") 18 | ) 19 | 20 | expect_error(binderize(here::here("Dockerfile"))) # No Dockerfile exists here 21 | expect_no_error(binderize(here::here("examples/simple/Dockerfile"), add_readme_badge = FALSE)) 22 | expect_message( 23 | binderize(here::here("examples/simple/Dockerfile"), add_readme_badge = FALSE), 24 | regexp = "Your repository has been configured for Binder" 25 | ) 26 | 27 | # Ensure that the Binder Dockerfile copies files ONLY ONCE 28 | df <- readLines(here::here(".binder/Dockerfile")) 29 | COPY_lines <- grep("^COPY\\s+\\.\\s+\\S+", df) 30 | expect_true(length(COPY_lines) == 0) 31 | 32 | if (dir.exists(here::here(".binder"))) { 33 | file.remove(here::here(".binder/Dockerfile")) 34 | file.remove(here::here(".binder/")) 35 | } 36 | }) -------------------------------------------------------------------------------- /examples/ggplot2/data/mtcars.csv: -------------------------------------------------------------------------------- 1 | "mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb" 2 | 21,6,160,110,3.9,2.62,16.46,0,1,4,4 3 | 21,6,160,110,3.9,2.875,17.02,0,1,4,4 4 | 22.8,4,108,93,3.85,2.32,18.61,1,1,4,1 5 | 21.4,6,258,110,3.08,3.215,19.44,1,0,3,1 6 | 18.7,8,360,175,3.15,3.44,17.02,0,0,3,2 7 | 18.1,6,225,105,2.76,3.46,20.22,1,0,3,1 8 | 14.3,8,360,245,3.21,3.57,15.84,0,0,3,4 9 | 24.4,4,146.7,62,3.69,3.19,20,1,0,4,2 10 | 22.8,4,140.8,95,3.92,3.15,22.9,1,0,4,2 11 | 19.2,6,167.6,123,3.92,3.44,18.3,1,0,4,4 12 | 17.8,6,167.6,123,3.92,3.44,18.9,1,0,4,4 13 | 16.4,8,275.8,180,3.07,4.07,17.4,0,0,3,3 14 | 17.3,8,275.8,180,3.07,3.73,17.6,0,0,3,3 15 | 15.2,8,275.8,180,3.07,3.78,18,0,0,3,3 16 | 10.4,8,472,205,2.93,5.25,17.98,0,0,3,4 17 | 10.4,8,460,215,3,5.424,17.82,0,0,3,4 18 | 14.7,8,440,230,3.23,5.345,17.42,0,0,3,4 19 | 32.4,4,78.7,66,4.08,2.2,19.47,1,1,4,1 20 | 30.4,4,75.7,52,4.93,1.615,18.52,1,1,4,2 21 | 33.9,4,71.1,65,4.22,1.835,19.9,1,1,4,1 22 | 21.5,4,120.1,97,3.7,2.465,20.01,1,0,3,1 23 | 15.5,8,318,150,2.76,3.52,16.87,0,0,3,2 24 | 15.2,8,304,150,3.15,3.435,17.3,0,0,3,2 25 | 13.3,8,350,245,3.73,3.84,15.41,0,0,3,4 26 | 19.2,8,400,175,3.08,3.845,17.05,0,0,3,2 27 | 27.3,4,79,66,4.08,1.935,18.9,1,1,4,1 28 | 26,4,120.3,91,4.43,2.14,16.7,0,1,5,2 29 | 30.4,4,95.1,113,3.77,1.513,16.9,1,1,5,2 30 | 15.8,8,351,264,4.22,3.17,14.5,0,1,5,4 31 | 19.7,6,145,175,3.62,2.77,15.5,0,1,5,6 32 | 15,8,301,335,3.54,3.57,14.6,0,1,5,8 33 | 21.4,4,121,109,4.11,2.78,18.6,1,1,4,2 34 | -------------------------------------------------------------------------------- /examples/ggplot2/data/mtcars_unnecessary.csv: -------------------------------------------------------------------------------- 1 | "mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb" 2 | 21,6,160,110,3.9,2.62,16.46,0,1,4,4 3 | 21,6,160,110,3.9,2.875,17.02,0,1,4,4 4 | 22.8,4,108,93,3.85,2.32,18.61,1,1,4,1 5 | 21.4,6,258,110,3.08,3.215,19.44,1,0,3,1 6 | 18.7,8,360,175,3.15,3.44,17.02,0,0,3,2 7 | 18.1,6,225,105,2.76,3.46,20.22,1,0,3,1 8 | 14.3,8,360,245,3.21,3.57,15.84,0,0,3,4 9 | 24.4,4,146.7,62,3.69,3.19,20,1,0,4,2 10 | 22.8,4,140.8,95,3.92,3.15,22.9,1,0,4,2 11 | 19.2,6,167.6,123,3.92,3.44,18.3,1,0,4,4 12 | 17.8,6,167.6,123,3.92,3.44,18.9,1,0,4,4 13 | 16.4,8,275.8,180,3.07,4.07,17.4,0,0,3,3 14 | 17.3,8,275.8,180,3.07,3.73,17.6,0,0,3,3 15 | 15.2,8,275.8,180,3.07,3.78,18,0,0,3,3 16 | 10.4,8,472,205,2.93,5.25,17.98,0,0,3,4 17 | 10.4,8,460,215,3,5.424,17.82,0,0,3,4 18 | 14.7,8,440,230,3.23,5.345,17.42,0,0,3,4 19 | 32.4,4,78.7,66,4.08,2.2,19.47,1,1,4,1 20 | 30.4,4,75.7,52,4.93,1.615,18.52,1,1,4,2 21 | 33.9,4,71.1,65,4.22,1.835,19.9,1,1,4,1 22 | 21.5,4,120.1,97,3.7,2.465,20.01,1,0,3,1 23 | 15.5,8,318,150,2.76,3.52,16.87,0,0,3,2 24 | 15.2,8,304,150,3.15,3.435,17.3,0,0,3,2 25 | 13.3,8,350,245,3.73,3.84,15.41,0,0,3,4 26 | 19.2,8,400,175,3.08,3.845,17.05,0,0,3,2 27 | 27.3,4,79,66,4.08,1.935,18.9,1,1,4,1 28 | 26,4,120.3,91,4.43,2.14,16.7,0,1,5,2 29 | 30.4,4,95.1,113,3.77,1.513,16.9,1,1,5,2 30 | 15.8,8,351,264,4.22,3.17,14.5,0,1,5,4 31 | 19.7,6,145,175,3.62,2.77,15.5,0,1,5,6 32 | 15,8,301,335,3.54,3.57,14.6,0,1,5,8 33 | 21.4,4,121,109,4.11,2.78,18.6,1,1,4,2 34 | -------------------------------------------------------------------------------- /examples/diff_dockerfile_and_context/mtcars.csv: -------------------------------------------------------------------------------- 1 | "mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb" 2 | 21,6,160,110,3.9,2.62,16.46,0,1,4,4 3 | 21,6,160,110,3.9,2.875,17.02,0,1,4,4 4 | 22.8,4,108,93,3.85,2.32,18.61,1,1,4,1 5 | 21.4,6,258,110,3.08,3.215,19.44,1,0,3,1 6 | 18.7,8,360,175,3.15,3.44,17.02,0,0,3,2 7 | 18.1,6,225,105,2.76,3.46,20.22,1,0,3,1 8 | 14.3,8,360,245,3.21,3.57,15.84,0,0,3,4 9 | 24.4,4,146.7,62,3.69,3.19,20,1,0,4,2 10 | 22.8,4,140.8,95,3.92,3.15,22.9,1,0,4,2 11 | 19.2,6,167.6,123,3.92,3.44,18.3,1,0,4,4 12 | 17.8,6,167.6,123,3.92,3.44,18.9,1,0,4,4 13 | 16.4,8,275.8,180,3.07,4.07,17.4,0,0,3,3 14 | 17.3,8,275.8,180,3.07,3.73,17.6,0,0,3,3 15 | 15.2,8,275.8,180,3.07,3.78,18,0,0,3,3 16 | 10.4,8,472,205,2.93,5.25,17.98,0,0,3,4 17 | 10.4,8,460,215,3,5.424,17.82,0,0,3,4 18 | 14.7,8,440,230,3.23,5.345,17.42,0,0,3,4 19 | 32.4,4,78.7,66,4.08,2.2,19.47,1,1,4,1 20 | 30.4,4,75.7,52,4.93,1.615,18.52,1,1,4,2 21 | 33.9,4,71.1,65,4.22,1.835,19.9,1,1,4,1 22 | 21.5,4,120.1,97,3.7,2.465,20.01,1,0,3,1 23 | 15.5,8,318,150,2.76,3.52,16.87,0,0,3,2 24 | 15.2,8,304,150,3.15,3.435,17.3,0,0,3,2 25 | 13.3,8,350,245,3.73,3.84,15.41,0,0,3,4 26 | 19.2,8,400,175,3.08,3.845,17.05,0,0,3,2 27 | 27.3,4,79,66,4.08,1.935,18.9,1,1,4,1 28 | 26,4,120.3,91,4.43,2.14,16.7,0,1,5,2 29 | 30.4,4,95.1,113,3.77,1.513,16.9,1,1,5,2 30 | 15.8,8,351,264,4.22,3.17,14.5,0,1,5,4 31 | 19.7,6,145,175,3.62,2.77,15.5,0,1,5,6 32 | 15,8,301,335,3.54,3.57,14.6,0,1,5,8 33 | 21.4,4,121,109,4.11,2.78,18.6,1,1,4,2 34 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | release: 8 | types: [published] 9 | workflow_dispatch: 10 | 11 | name: pkgdown.yaml 12 | 13 | permissions: read-all 14 | 15 | jobs: 16 | pkgdown: 17 | runs-on: ubuntu-latest 18 | # Only restrict concurrency for non-PR jobs 19 | concurrency: 20 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 21 | env: 22 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 23 | permissions: 24 | contents: write 25 | steps: 26 | - uses: actions/checkout@v4 27 | 28 | - uses: r-lib/actions/setup-pandoc@v2 29 | 30 | - uses: r-lib/actions/setup-r@v2 31 | with: 32 | use-public-rspm: true 33 | 34 | - uses: r-lib/actions/setup-r-dependencies@v2 35 | with: 36 | extra-packages: any::pkgdown, local::. 37 | needs: website 38 | 39 | - name: Build site 40 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 41 | shell: Rscript {0} 42 | 43 | - name: Deploy to GitHub pages 🚀 44 | if: github.event_name != 'pull_request' 45 | uses: JamesIves/github-pages-deploy-action@v4.5.0 46 | with: 47 | clean: false 48 | branch: gh-pages 49 | folder: docs 50 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | 8 | name: R-CMD-check.yaml 9 | 10 | permissions: read-all 11 | 12 | jobs: 13 | R-CMD-check: 14 | runs-on: ${{ matrix.config.os }} 15 | 16 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 17 | 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | config: 22 | - {os: macos-latest, r: 'release'} 23 | - {os: windows-latest, r: 'release'} 24 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 25 | - {os: ubuntu-latest, r: 'release'} 26 | - {os: ubuntu-latest, r: 'oldrel-1'} 27 | 28 | env: 29 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 30 | R_KEEP_PKG_SOURCE: yes 31 | 32 | steps: 33 | - uses: actions/checkout@v4 34 | 35 | - uses: r-lib/actions/setup-pandoc@v2 36 | 37 | - uses: r-lib/actions/setup-r@v2 38 | with: 39 | r-version: ${{ matrix.config.r }} 40 | http-user-agent: ${{ matrix.config.http-user-agent }} 41 | use-public-rspm: true 42 | 43 | - uses: r-lib/actions/setup-r-dependencies@v2 44 | with: 45 | extra-packages: any::rcmdcheck 46 | needs: check 47 | 48 | - uses: r-lib/actions/check-r-package@v2 49 | with: 50 | upload-snapshots: true 51 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' 52 | -------------------------------------------------------------------------------- /tests/testthat/test-create.R: -------------------------------------------------------------------------------- 1 | test_that("Creating a Dockerfile works as expected", { 2 | testthat::skip_on_cran() 3 | if (!interactive()) { 4 | skip("Tests only run interactively") 5 | } 6 | 7 | if (file.exists(here::here("examples/simple/Dockerfile"))) { 8 | file.remove(here::here("examples/simple/Dockerfile")) 9 | } 10 | if (file.exists(here::here("examples/simple/renv.lock"))) { 11 | file.remove(here::here("examples/simple/renv.lock")) 12 | } 13 | # Create the Dockerfile 14 | dock <- suppressWarnings({ 15 | create( 16 | project = here::here("examples/simple"), 17 | FROM = paste0("posit/r-base:", R.version$major, ".", R.version$minor, "-opensuse156") 18 | ) 19 | }) 20 | # Read the lockfile 21 | lockfile <- renv::lockfile_read(here::here("examples/simple/renv.lock")) 22 | # Ensure that lockfile has all the correct dependencies 23 | testthat::expect_equal( 24 | names(lockfile$Packages), 25 | c("jsonlite", "renv", "rprojroot", "stringi", "withr") 26 | ) 27 | }) 28 | 29 | test_that("Creating a non-optimized Dockerfile works as expected", { 30 | testthat::skip_on_cran() 31 | if (!interactive()) { 32 | skip("Tests only run interactively") 33 | } 34 | 35 | if (file.exists(here::here("examples/simple/Dockerfile"))) { 36 | file.remove(here::here("examples/simple/Dockerfile")) 37 | } 38 | if (file.exists(here::here("examples/simple/renv.lock"))) { 39 | file.remove(here::here("examples/simple/renv.lock")) 40 | } 41 | # Create the Dockerfile 42 | dock <- suppressWarnings({ 43 | create( 44 | project = here::here("examples/simple"), 45 | FROM = paste0("posit/r-base:", R.version$major, ".", R.version$minor, "-opensuse156"), 46 | optimize_pak = FALSE 47 | ) 48 | }) 49 | # Basically just make sure that it just has a vanilla pak install of renv 50 | expect_true(startsWith(dock[[9]], "RUN R -e \"pak::pkg_install('renv@")) 51 | }) -------------------------------------------------------------------------------- /R/dockerfile.R: -------------------------------------------------------------------------------- 1 | dockerfile <- function(lockfile, FROM = NULL, optimize_pak = TRUE) { 2 | lock <- renv::lockfile_read(lockfile) 3 | Rversion <- lock$R$Version 4 | if (!is.null(lock$Packages$renv$Version)) { 5 | renv_version <- paste0("renv@", lock$Packages$renv$Version) 6 | } else { 7 | renv_version <- "renv" 8 | } 9 | if (is.null(FROM)) FROM <- paste0("posit/r-base:", R.Version()$major, ".", R.Version()$minor, "-noble") 10 | if (!optimize_pak) { 11 | pak_setup <- paste0("RUN R -e \"pak::pkg_install('", renv_version, "')\"") 12 | } else { 13 | pak_setup <- paste0( 14 | "RUN R -e \"dist <- pak::system_r_platform_data()[['distribution']]; rel <- pak::system_r_platform_data()[['release']]; binary_url <- subset(pak::ppm_platforms(), distribution == dist & release == rel)[['binary_url']][1]; cran_binary_url <- if (!is.na(binary_url)) { sprintf('%s/__linux__/%s/latest', pak::ppm_repo_url(), binary_url) } else { NA }; if (!is.na(cran_binary_url)) { pak::repo_add(CRAN = cran_binary_url) }; ", 15 | paste0("pak::pkg_install('", renv_version, "')"), 16 | "; if (!is.na(cran_binary_url)) { lf <- renv::lockfile_modify(repos = c('CRAN' = cran_binary_url)); tryCatch({ renv::lockfile_write(lf, './renv.lock') }, error = function(e) { invisible(NULL) }) }\"" 17 | ) 18 | } 19 | dock <- c( 20 | paste("FROM", FROM), 21 | paste("COPY", basename(lockfile), "renv.lock"), 22 | "RUN for d in /usr/local/lib/R/etc /usr/lib/R/etc; do \\", 23 | " mkdir -p \"$d\" 2>/dev/null || true; \\", 24 | " f=\"$d/Rprofile.site\"; \\", 25 | " { echo \"options(renv.config.pak.enabled = TRUE)\" >> \"$f\" 2>/dev/null || true; } \\", 26 | " done", 27 | "RUN R -e \"install.packages('pak', repos = sprintf('https://r-lib.github.io/p/pak/stable/%s/%s/%s', .Platform[['pkgType']], R.Version()[['os']], R.Version()[['arch']]))\"", 28 | pak_setup, 29 | "RUN R -e \"renv::restore()\"" 30 | ) 31 | return(dock) 32 | } -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | # Search the project directory (and children) for DESCRIPTION files 2 | description_files <- function(project) { 3 | files <- list.files( 4 | project, 5 | pattern = "^DESCRIPTION$", 6 | recursive = TRUE, 7 | full.names = TRUE 8 | ) 9 | if (length(files) == 0) { 10 | return(NULL) 11 | } 12 | return(files) 13 | } 14 | 15 | # Extract the package name from a DESCRIPTION file 16 | extract_package_name <- function(path) { 17 | description <- read.dcf(path) 18 | if ("Package" %in% colnames(description)) { 19 | return(unname(description[1, "Package", drop = TRUE])) 20 | } else { 21 | return(NULL) 22 | } 23 | } 24 | 25 | # Extract package names from a vector of DESCRIPTION files 26 | extract_package_names <- function(project) { 27 | descriptions <- description_files(project) 28 | package_names <- unlist(lapply(descriptions, extract_package_name)) 29 | return(unique(package_names)) 30 | } 31 | 32 | # Initialize the renv lockfile from the project directory 33 | init_renv <- function( 34 | project, 35 | lockfile = renv::paths$lockfile(project = project), 36 | ... 37 | ) { 38 | if (!interactive()) { 39 | pkgs_to_exclude <- unique(c( 40 | basename(project), 41 | extract_package_names(project) 42 | )) 43 | renv::install(project = project, exclude = pkgs_to_exclude) 44 | } 45 | snap <- renv::snapshot(project = project, lockfile = lockfile, ...) 46 | return(lockfile) 47 | } 48 | 49 | stop_if_docker_not_installed <- function() { 50 | is_installed <- Sys.which("docker") != "" 51 | if (!is_installed) { 52 | stop( 53 | c( 54 | "Docker is not installed. ", 55 | "Visit https://docs.docker.com/get-docker/ to get started!" 56 | ), 57 | call. = parent.frame() 58 | ) 59 | } 60 | } 61 | 62 | # Write the .dockerignore in the project directory 63 | write_dockerignore <- function(exclude, project) { 64 | if (is.null(exclude)) return(TRUE) 65 | writeLines(exclude, file.path(project, ".dockerignore")) 66 | invisible(TRUE) 67 | } -------------------------------------------------------------------------------- /man/build.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/build.R 3 | \name{build} 4 | \alias{build} 5 | \title{Build a Docker image} 6 | \usage{ 7 | build( 8 | dockerfile = here::here("Dockerfile"), 9 | image_name = "tugboat", 10 | tag = "latest", 11 | platforms = c("linux/amd64", "linux/arm64"), 12 | build_args = NULL, 13 | build_context = here::here(), 14 | push = FALSE, 15 | dh_username = NULL, 16 | dh_password = NULL, 17 | verbose = FALSE 18 | ) 19 | } 20 | \arguments{ 21 | \item{dockerfile}{The path to the Dockerfile. The default value 22 | is a file named \code{Dockerfile} in the project directory surfaced by 23 | \link[here:here]{here::here}.} 24 | 25 | \item{image_name}{A string specifying the Docker image name. Default 26 | is \code{tugboat}.} 27 | 28 | \item{tag}{A string specifying the image tag. Default is \code{latest}.} 29 | 30 | \item{platforms}{A vector of strings. Which platforms to build images for. 31 | Default is both \code{linux/amd64} and \code{linux/arm64}.} 32 | 33 | \item{build_args}{A vector of strings specifying additional build arguments 34 | to pass to the \verb{docker buildx build} command. Optional.} 35 | 36 | \item{build_context}{The directory that is the build context for the 37 | image(s). Default value is the directory returned by \link[here:here]{here::here}.} 38 | 39 | \item{push}{A boolean indicating whether to push to DockerHub.} 40 | 41 | \item{dh_username}{A string specifying the DockerHub username. Only 42 | necessary if \code{push == TRUE}.} 43 | 44 | \item{dh_password}{A string specifying the DockerHub password. Only 45 | necessary if \code{push == TRUE}.} 46 | 47 | \item{verbose}{A boolean. Whether to print the actual Docker build 48 | command or not. Defaults to \code{FALSE}.} 49 | } 50 | \value{ 51 | The name of the built Docker image as a string. 52 | } 53 | \description{ 54 | A simple utility to quickly build a Docker image from a Dockerfile. 55 | } 56 | \examples{ 57 | \dontrun{ 58 | dock <- create( 59 | project = here::here(), 60 | FROM = "rstudio/r-base:devel-bookworm", 61 | exclude = c("/data", "/examples") 62 | ) 63 | 64 | image_name <- build( 65 | dockerfile = here::here("Dockerfile"), 66 | image_name = "awesome_analysis", 67 | push = TRUE, 68 | dh_username = Sys.getenv("DH_USERNAME"), 69 | dh_password = Sys.getenv("DH_PASSWORD") 70 | ) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /man/binderize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/binderize.R 3 | \name{binderize} 4 | \alias{binderize} 5 | \title{Prepare project for Binder} 6 | \usage{ 7 | binderize( 8 | dockerfile = here::here("Dockerfile"), 9 | branch = "main", 10 | hub = "mybinder.org", 11 | urlpath = "rstudio", 12 | add_readme_badge = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{dockerfile}{Path to the tugboat-generated Dockerfile.} 17 | 18 | \item{branch}{Character string specifying the Git branch, tag, or commit hash to build. 19 | Defaults to \code{"main"}.} 20 | 21 | \item{hub}{The Binder hub to use. Currently only \code{"mybinder.org"} is supported.} 22 | 23 | \item{urlpath}{The URL path to open inside the Binder instance. 24 | Defaults to \code{"rstudio"}, which opens an RStudio Server session.} 25 | 26 | \item{add_readme_badge}{Logical. Whether to add a Binder launch badge to the README. 27 | Defaults to \code{TRUE}.} 28 | } 29 | \value{ 30 | Invisibly returns \code{NULL}. Called primarily for its side effects of creating 31 | Binder-related files and optionally committing them. 32 | } 33 | \description{ 34 | The \code{binderize()} function converts an existing tugboat project into a 35 | \href{https://mybinder.org}{Binder}–compatible project by creating a Dockerfile 36 | that launches RStudio Server via the \code{rocker/binder} base image. 37 | Optionally, it can add a Binder launch badge to the project's README. 38 | } 39 | \details{ 40 | This enables one-click, cloud-based execution of your R analysis environment 41 | directly from GitHub using Binder. 42 | 43 | Currently only GitHub repositories are supported. If \code{add_readme_badge = TRUE}, 44 | a Binder badge will be appended to the README file, linking to the live Binder instance. 45 | } 46 | \note{ 47 | Binder can only build from the remote GitHub repository. 48 | The \code{.binder/Dockerfile} and README changes must be committed and pushed before 49 | launching Binder; otherwise, the build will not reflect local modifications. 50 | } 51 | \examples{ 52 | \dontrun{ 53 | binderize( 54 | dockerfile = here::here("Dockerfile"), 55 | branch = "main", 56 | add_readme_badge = TRUE 57 | ) 58 | } 59 | 60 | } 61 | \seealso{ 62 | \itemize{ 63 | \item \code{\link[=create]{create()}} — Generates a Dockerfile from an analysis directory. 64 | \item \code{\link[=build]{build()}} — Builds the corresponding Docker image locally. 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # tugboat 0.1.5 2 | 3 | - Resolves [#17](https://github.com/dmolitor/tugboat/issues/17). This was a 4 | Windows-specific issue where RStudio would lock down the .Rproj file, causing 5 | `docker buildx build` to fail. 6 | 7 | - Adds a `verbose` argument to `build()`. This will print the full build call 8 | that is being executed. This can potentially be helpful when debugging build 9 | errors. 10 | 11 | - Resolves [#16](https://github.com/dmolitor/tugboat/issues/16). This provides 12 | slightly more efficient Binder builds and handles build errors more cleanly. 13 | 14 | # tugboat 0.1.4 15 | 16 | - Adds preliminary Binder support. See the new `binderize()` function and 17 | its corresponding documentation. 18 | 19 | - Adds a new argument `optimize_pak = TRUE` to the `create()` function. 20 | This argument should almost never need to be set to FALSE, but in some cases 21 | our method of optimizing package installation with pak can fail, in which 22 | case setting `optimize_pak = FALSE` reverts to the older, more fail-proof 23 | method and can alleviate those issues. 24 | 25 | # tugboat 0.1.3 26 | 27 | - Added better support for binaries via `pak`. Still some limitations when 28 | using less common Linux distributions (e.g. Alpine) or older distributions 29 | (e.g. Debian 11). However, for up-to-date Debian and Ubuntu distributions, 30 | this should be fairly seemless and should result in potentially huge 31 | installation speedups. See [PPM documentation](https://packagemanager.posit.co/__docs__/admin/serving-binaries.html) 32 | and [related GitHub issues](https://github.com/hadley/r-in-production/issues/22) 33 | for some light bedtime reading on this subject. 34 | 35 | # tugboat 0.1.2 36 | 37 | - Added argument `verbose` to the `tugboat::create()` function. If 38 | `verbose = TRUE`, the resulting Dockerfile will be printed to the R console. 39 | 40 | # tugboat 0.1.1 41 | 42 | - In `tugboat::build()` the default value for the build_context is now 43 | `build_context = here::here()` instead of `build_context = dirname(dockerfile)`. 44 | This resolves a potential issue where, if the user saves the Dockerfile in a 45 | different directory than the build context, `tugboat::build()` incorrectly infers 46 | the build context as the directory containing the Dockerfile. Now `tugboat::build()` 47 | will infer the build context as the current project directory regardless 48 | of the Dockerfile location. As always, the user can explicitly specify 49 | both of these arguments to override the default values. 50 | 51 | - `tugboat::create()` will now execute `renv::install()` before `renv::snapshot()` 52 | when running in non-interactive mode. This resolves the issue where 53 | `renv::snapshot()` won't snapshot packages that are not installed when 54 | being run non-interactively, thus potentially leaving essential packages out of 55 | the Docker image. 56 | 57 | - tugboat no longer relies on the dockerfiler package. This allows support for a 58 | much wider range of base images and minimizes the dependencies for tugboat. 59 | 60 | # tugboat 0.1.0 61 | 62 | * Initial CRAN submission. 63 | -------------------------------------------------------------------------------- /man/create.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create.R 3 | \name{create} 4 | \alias{create} 5 | \title{Create a Dockerfile} 6 | \usage{ 7 | create( 8 | project = here::here(), 9 | as = file.path(project, "Dockerfile"), 10 | FROM = NULL, 11 | ..., 12 | exclude = NULL, 13 | verbose = FALSE, 14 | optimize_pak = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{project}{The project directory. If no project directory is provided, 19 | by default, the here package will be used to determine the active 20 | project. If no project is currently active, then here defaults to 21 | the working directory where initially called.} 22 | 23 | \item{as}{The file path to write to. The default value is 24 | \code{file.path(project, "Dockerfile")}.} 25 | 26 | \item{FROM}{Docker image to start FROM. Default is FROM r-base:R.version.} 27 | 28 | \item{...}{Additional arguments which are passed directly to 29 | \link[renv:snapshot]{renv::snapshot}. Please see the documentation for that function for all 30 | relevant details.} 31 | 32 | \item{exclude}{A vector of strings specifying all paths (files or 33 | directories) that should NOT be included in the Docker image. By default, 34 | all files in the directory will be included. NOTE: the file and directory 35 | paths should be relative to the project directory. They do NOT need to 36 | be absolute paths.} 37 | 38 | \item{verbose}{A boolean indicating whether or not to print the resulting 39 | Dockerfile to the console. Default value is \code{FALSE}.} 40 | 41 | \item{optimize_pak}{A boolean indicating whether or not to try to optimize 42 | package installations with pak. Defaults to \code{TRUE}. This should rarely be 43 | changed from its default value. However, sometimes this optimization may 44 | cause build failures. When encountering a build error, a good first step 45 | can be to set \code{optimize_pak = FALSE} and see if the error persists.} 46 | } 47 | \value{ 48 | The Dockerfile contained as a string vector. Each vector element 49 | corresponds to a line in the Dockerfile. 50 | } 51 | \description{ 52 | This function will crawl all files in the current project/directory and 53 | (attempt to) detect all R packages and store these in a lockfile. From this 54 | lockfile, it will create a corresponding Dockerfile. It will also copy 55 | the full contents of the current directory/project into the Docker image. 56 | The directory in the Docker container containing the current directory 57 | contents will be /current-directory-name. For example if your analysis 58 | directory is named \code{incredible_analysis}, the corresponding location in 59 | the generated Docker image will be \verb{/incredible_analysis}. 60 | } 61 | \examples{ 62 | \dontrun{ 63 | # Create a Dockerfile based on the rocker/rstudio image. 64 | # Write the Dockerfile locally to here::here("Dockerfile"). 65 | # Copy all files except the /data and /examples directories. 66 | dock <- create( 67 | project = here::here(), 68 | FROM = "rocker/rstudio", 69 | exclude = c("/data", "/examples") 70 | ) 71 | } 72 | 73 | } 74 | \seealso{ 75 | \link[here:here]{here::here}; this will be used by default to determine the current 76 | project directory. 77 | 78 | \link[renv:snapshot]{renv::snapshot} which this function relies on to find all R 79 | dependencies and create a corresponding lockfile. 80 | } 81 | -------------------------------------------------------------------------------- /R/create.R: -------------------------------------------------------------------------------- 1 | #' Create a Dockerfile 2 | #' 3 | #' This function will crawl all files in the current project/directory and 4 | #' (attempt to) detect all R packages and store these in a lockfile. From this 5 | #' lockfile, it will create a corresponding Dockerfile. It will also copy 6 | #' the full contents of the current directory/project into the Docker image. 7 | #' The directory in the Docker container containing the current directory 8 | #' contents will be /current-directory-name. For example if your analysis 9 | #' directory is named `incredible_analysis`, the corresponding location in 10 | #' the generated Docker image will be `/incredible_analysis`. 11 | #' 12 | #' @param project The project directory. If no project directory is provided, 13 | #' by default, the here package will be used to determine the active 14 | #' project. If no project is currently active, then here defaults to 15 | #' the working directory where initially called. 16 | #' @param as The file path to write to. The default value is 17 | #' `file.path(project, "Dockerfile")`. 18 | #' @param FROM Docker image to start FROM. Default is FROM r-base:R.version. 19 | #' @param ... Additional arguments which are passed directly to 20 | #' [renv::snapshot]. Please see the documentation for that function for all 21 | #' relevant details. 22 | #' @param exclude A vector of strings specifying all paths (files or 23 | #' directories) that should NOT be included in the Docker image. By default, 24 | #' all files in the directory will be included. NOTE: the file and directory 25 | #' paths should be relative to the project directory. They do NOT need to 26 | #' be absolute paths. 27 | #' @param verbose A boolean indicating whether or not to print the resulting 28 | #' Dockerfile to the console. Default value is `FALSE`. 29 | #' @param optimize_pak A boolean indicating whether or not to try to optimize 30 | #' package installations with pak. Defaults to `TRUE`. This should rarely be 31 | #' changed from its default value. However, sometimes this optimization may 32 | #' cause build failures. When encountering a build error, a good first step 33 | #' can be to set `optimize_pak = FALSE` and see if the error persists. 34 | #' 35 | #' @seealso [here::here]; this will be used by default to determine the current 36 | #' project directory. 37 | #' @seealso [renv::snapshot] which this function relies on to find all R 38 | #' dependencies and create a corresponding lockfile. 39 | #' @returns The Dockerfile contained as a string vector. Each vector element 40 | #' corresponds to a line in the Dockerfile. 41 | #' @examples 42 | #' \dontrun{ 43 | #' # Create a Dockerfile based on the rocker/rstudio image. 44 | #' # Write the Dockerfile locally to here::here("Dockerfile"). 45 | #' # Copy all files except the /data and /examples directories. 46 | #' dock <- create( 47 | #' project = here::here(), 48 | #' FROM = "rocker/rstudio", 49 | #' exclude = c("/data", "/examples") 50 | #' ) 51 | #' } 52 | #' 53 | #' @export 54 | create <- function( 55 | project = here::here(), 56 | as = file.path(project, "Dockerfile"), 57 | FROM = NULL, 58 | ..., 59 | exclude = NULL, 60 | verbose = FALSE, 61 | optimize_pak = TRUE 62 | ) { 63 | lockfile <- init_renv(project = project, ...) 64 | dock <- dockerfile(lockfile, FROM = FROM, optimize_pak = optimize_pak) 65 | dock <- c(dock, paste("COPY .", paste0("/", basename(project))), "") 66 | write_dockerignore( 67 | c(exclude, c("Dockerfile", ".dockerignore", "**/.DS_Store")), 68 | project = project 69 | ) 70 | if (!is.null(as)) writeLines(dock, con = as) 71 | if (verbose) cat(dock, sep = "\n") 72 | invisible(dock) 73 | } 74 | -------------------------------------------------------------------------------- /R/build.R: -------------------------------------------------------------------------------- 1 | is_windows <- function() { 2 | is_windows <- .Platform$OS.type == "windows" 3 | return(is_windows) 4 | } 5 | 6 | build_image <- function( 7 | dockerfile, 8 | platforms, 9 | repository, 10 | tag, 11 | build_args, 12 | build_context, 13 | push, 14 | verbose 15 | ) { 16 | if (is_windows()) { 17 | tmp <- tempfile() 18 | dir.create(tmp) 19 | on.exit({ 20 | if (dir.exists(tmp)) unlink(tmp, recursive = TRUE, force = TRUE) 21 | }, add = TRUE) 22 | # Copy the build context over to a temp directory; our new build context! 23 | got_copied <- file.copy( 24 | list.files( 25 | build_context, 26 | full.names = TRUE, 27 | all.files = TRUE, 28 | no.. = TRUE 29 | ), 30 | tmp, 31 | recursive = TRUE 32 | ) 33 | stopifnot(all(got_copied)) 34 | # The temp directory is the new build context! 35 | build_context <- tmp 36 | } 37 | exec_args <- c( 38 | "buildx", 39 | "build", 40 | "-f", 41 | normalizePath(dockerfile, mustWork = FALSE), 42 | "--platform", 43 | paste0(platforms, collapse = ","), 44 | "-t", 45 | paste0(repository, ":", tag), 46 | build_args, 47 | build_context, 48 | if (push) "--push" else NULL 49 | ) 50 | if (verbose) { 51 | msg <- paste0("Building:\n", paste0(c("docker", exec_args), collapse = " ")) 52 | cat(msg, "\n") 53 | } 54 | build_status <- system2( 55 | "docker", 56 | exec_args 57 | ) 58 | if (build_status != 0) { 59 | stop("Build failed with the following status: ", build_status) 60 | } 61 | return(TRUE) 62 | } 63 | 64 | #' Build a Docker image 65 | #' 66 | #' A simple utility to quickly build a Docker image from a Dockerfile. 67 | #' 68 | #' @param dockerfile The path to the Dockerfile. The default value 69 | #' is a file named `Dockerfile` in the project directory surfaced by 70 | #' [here::here]. 71 | #' @param image_name A string specifying the Docker image name. Default 72 | #' is `tugboat`. 73 | #' @param tag A string specifying the image tag. Default is `latest`. 74 | #' @param platforms A vector of strings. Which platforms to build images for. 75 | #' Default is both `linux/amd64` and `linux/arm64`. 76 | #' @param build_args A vector of strings specifying additional build arguments 77 | #' to pass to the `docker buildx build` command. Optional. 78 | #' @param build_context The directory that is the build context for the 79 | #' image(s). Default value is the directory returned by [here::here]. 80 | #' @param push A boolean indicating whether to push to DockerHub. 81 | #' @param dh_username A string specifying the DockerHub username. Only 82 | #' necessary if `push == TRUE`. 83 | #' @param dh_password A string specifying the DockerHub password. Only 84 | #' necessary if `push == TRUE`. 85 | #' @param verbose A boolean. Whether to print the actual Docker build 86 | #' command or not. Defaults to `FALSE`. 87 | #' @returns The name of the built Docker image as a string. 88 | #' @examples 89 | #' \dontrun{ 90 | #' dock <- create( 91 | #' project = here::here(), 92 | #' FROM = "rstudio/r-base:devel-bookworm", 93 | #' exclude = c("/data", "/examples") 94 | #' ) 95 | #' 96 | #' image_name <- build( 97 | #' dockerfile = here::here("Dockerfile"), 98 | #' image_name = "awesome_analysis", 99 | #' push = TRUE, 100 | #' dh_username = Sys.getenv("DH_USERNAME"), 101 | #' dh_password = Sys.getenv("DH_PASSWORD") 102 | #' ) 103 | #' } 104 | #' @export 105 | build <- function( 106 | dockerfile = here::here("Dockerfile"), 107 | image_name = "tugboat", 108 | tag = "latest", 109 | platforms = c("linux/amd64", "linux/arm64"), 110 | build_args = NULL, 111 | build_context = here::here(), 112 | push = FALSE, 113 | dh_username = NULL, 114 | dh_password = NULL, 115 | verbose = FALSE 116 | ) { 117 | stop_if_docker_not_installed() 118 | if (push) { 119 | if (is.null(dh_username) || is.null(dh_password)) { 120 | stop("Both `dh_username` and `dh_password` must be provided") 121 | } 122 | cat(system( 123 | sprintf( 124 | "echo '%s' | docker login -u %s --password-stdin", 125 | dh_password, 126 | dh_username 127 | ), 128 | intern = TRUE, 129 | ignore.stderr = FALSE 130 | )) 131 | } 132 | if (is.null(dh_username)) { 133 | repository <- image_name 134 | } else { 135 | repository <- paste0(dh_username, "/", image_name) 136 | } 137 | build_image( 138 | dockerfile = dockerfile, 139 | platforms = platforms, 140 | repository = repository, 141 | tag = tag, 142 | build_args = build_args, 143 | build_context = build_context, 144 | push = push, 145 | verbose = verbose 146 | ) 147 | return(paste0(repository, ":", tag)) 148 | } 149 | -------------------------------------------------------------------------------- /tests/testthat/test-build.R: -------------------------------------------------------------------------------- 1 | test_that("Expected installed packages are in the Docker image", { 2 | testthat::skip_on_cran() 3 | if (!interactive()) { 4 | skip("Tests only run interactively") 5 | } 6 | 7 | if (file.exists(here::here("examples/simple/Dockerfile"))) { 8 | file.remove(here::here("examples/simple/Dockerfile")) 9 | } 10 | if (file.exists(here::here("examples/simple/renv.lock"))) { 11 | file.remove(here::here("examples/simple/renv.lock")) 12 | } 13 | 14 | dock <- create( 15 | project = here::here("examples/simple/"), 16 | FROM = paste0("posit/r-base:", R.version$major, ".", R.version$minor, "-jammy"), 17 | exclude = c("run.R") 18 | ) 19 | 20 | image_name <- build( 21 | dockerfile = here::here("examples/simple/Dockerfile"), 22 | image_name = "tugboat_simple", 23 | platforms = "linux/amd64", 24 | build_context = here::here("examples/simple") 25 | ) 26 | # Check installed packages 27 | image_packages <- system( 28 | paste0( 29 | "docker run --rm --platform linux/amd64 ", 30 | image_name, 31 | " Rscript -e 'sort(row.names(installed.packages()))'" 32 | ), 33 | intern = TRUE 34 | ) 35 | image_packages <- gsub("\\[\\d+\\]", "", image_packages) 36 | image_packages <- unlist(strsplit(gsub('"', "", paste(image_packages, collapse = " ")), "\\s+")) 37 | image_packages <- image_packages[image_packages != ""] 38 | 39 | testthat::expect_equal(image_name, "tugboat_simple:latest") 40 | testthat::expect_in( 41 | c("jsonlite", "renv", "rprojroot", "stringi", "withr"), 42 | image_packages 43 | ) 44 | }) 45 | 46 | test_that("Dockerfile in a different directory than build context works correctly", { 47 | testthat::skip_on_cran() 48 | if (!interactive()) { 49 | skip("Tests only run interactively") 50 | } 51 | 52 | if (file.exists(here::here("examples/diff_dockerfile_and_context/docker/Dockerfile"))) { 53 | file.remove(here::here("examples/diff_dockerfile_and_context/docker/Dockerfile")) 54 | } 55 | exclude <- c("./mtcars.csv") 56 | dock <- create( 57 | project = here::here("examples/diff_dockerfile_and_context/"), 58 | as = here::here("examples/diff_dockerfile_and_context/docker/Dockerfile"), 59 | FROM = paste0("posit/r-base:", R.version$major, ".", R.version$minor, "-noble"), 60 | exclude = exclude 61 | ) 62 | 63 | # Build the docker image 64 | image_name <- build( 65 | dockerfile = here::here("examples/diff_dockerfile_and_context/docker/Dockerfile"), 66 | image_name = "tugboat_diff_df_context", 67 | platforms = "linux/arm64", 68 | build_context = here::here("examples/diff_dockerfile_and_context/") 69 | ) 70 | 71 | # Check copied files 72 | files <- system( 73 | paste0( 74 | "docker run --rm --platform linux/arm64 ", 75 | image_name, 76 | " ls -la /diff_dockerfile_and_context" 77 | ), 78 | intern = TRUE 79 | ) |> strsplit(split = " ") |> 80 | (\(x) lapply(x, \(y) y[[length(y)]]))() |> 81 | unlist() 82 | 83 | # Ensure that only expected files are included 84 | testthat::expect_false(exclude %in% files) 85 | }) 86 | 87 | test_that("Non-Ubuntu image works correctly", { 88 | testthat::skip_on_cran() 89 | if (!interactive()) { 90 | skip("Tests only run interactively") 91 | } 92 | 93 | if (file.exists(here::here("examples/simple/Dockerfile"))) { 94 | file.remove(here::here("examples/simple/Dockerfile")) 95 | } 96 | if (file.exists(here::here("examples/simple/renv.lock"))) { 97 | file.remove(here::here("examples/simple/renv.lock")) 98 | } 99 | # Create the Dockerfile 100 | dock <- suppressWarnings({ 101 | create( 102 | project = here::here("examples/simple"), 103 | FROM = paste0("posit/r-base:", R.version$major, ".", R.version$minor, "-bookworm-amd64"), 104 | exclude = c("run.R") 105 | ) 106 | }) 107 | image_name <- build( 108 | dockerfile = here::here("examples/simple/Dockerfile"), 109 | image_name = "tugboat_simple_bookworm", 110 | platforms = "linux/amd64", 111 | build_context = here::here("examples/simple") 112 | ) 113 | # Check installed packages 114 | image_packages <- system( 115 | paste0( 116 | "docker run --rm --platform linux/amd64 ", 117 | image_name, 118 | " Rscript -e 'sort(row.names(installed.packages()))'" 119 | ), 120 | intern = TRUE 121 | ) 122 | image_packages <- gsub("\\[\\d+\\]", "", image_packages) 123 | image_packages <- unlist(strsplit(gsub('"', "", paste(image_packages, collapse = " ")), "\\s+")) 124 | image_packages <- image_packages[image_packages != ""] 125 | 126 | testthat::expect_equal(image_name, "tugboat_simple_bookworm:latest") 127 | testthat::expect_in( 128 | c("jsonlite", "renv", "rprojroot", "stringi", "withr"), 129 | image_packages 130 | ) 131 | }) 132 | -------------------------------------------------------------------------------- /R/binderize.R: -------------------------------------------------------------------------------- 1 | check_if_installed <- function(pkg) { 2 | if (!requireNamespace(pkg, quietly = TRUE) && interactive()) { 3 | ans <- readline(paste0("Package '", pkg, "' is required. Install it now? [Y/n]: ")) 4 | if (tolower(trimws(ans)) == "y" || ans == "") { 5 | renv::install(pkg) 6 | } else { 7 | stop(paste0("Package '", pkg, "' must be installed")) 8 | } 9 | } else if (!requireNamespace(pkg, quietly = TRUE)) { 10 | stop(paste0("Package '", pkg, "' must be installed")) 11 | } 12 | } 13 | 14 | same_dir <- function(dir, path) { 15 | normalizePath(dir, winslash = "/", mustWork = FALSE) == 16 | dirname(normalizePath(path, winslash = "/", mustWork = FALSE)) 17 | } 18 | 19 | path_first_existing <- function(paths) { 20 | path_exists <- file.exists(paths) 21 | if (!any(path_exists)) { 22 | return(NULL) 23 | } 24 | return(paths[which(path_exists)[[1]]]) 25 | } 26 | 27 | prep_binder_dockerfile <- function(dockerfile, root) { 28 | binder_df_dir <- file.path(root, ".binder") 29 | target_path <- file.path(binder_df_dir, "Dockerfile") 30 | if (file.exists(target_path)) return(invisible(NULL)) 31 | df <- readLines(dockerfile) 32 | from_idx <- grep("^FROM\\s+", df) 33 | if (length(from_idx) == 0) { 34 | stop("No FROM statement found in Dockerfile. Was it created with tugboat?") 35 | } 36 | # Remove any existing "COPY . " lines from the original tugboat Dockerfile 37 | copy_idx <- grep("^COPY\\s+\\.\\s+\\S+", df) 38 | if (length(copy_idx) > 0) { 39 | df <- df[-copy_idx] 40 | } 41 | # Hard-code the max R major version to 4 until rocker supports > 4 42 | r_major <- as.character(min(as.integer(R.Version()$major), 4)) 43 | df[[from_idx[[1]]]] <- paste0("FROM rocker/binder:", r_major) 44 | if (!dir.exists(binder_df_dir)) { 45 | dir.create(binder_df_dir) 46 | } 47 | df <- c(df, "COPY --chown=${NB_USER} . /home/rstudio") 48 | writeLines(df, target_path) 49 | return(invisible(NULL)) 50 | } 51 | 52 | #' Prepare project for Binder 53 | #' 54 | #' The `binderize()` function converts an existing tugboat project into a 55 | #' [Binder](https://mybinder.org)–compatible project by creating a Dockerfile 56 | #' that launches RStudio Server via the `rocker/binder` base image. 57 | #' Optionally, it can add a Binder launch badge to the project's README. 58 | #' 59 | #' This enables one-click, cloud-based execution of your R analysis environment 60 | #' directly from GitHub using Binder. 61 | #' 62 | #' @details 63 | #' Currently only GitHub repositories are supported. If `add_readme_badge = TRUE`, 64 | #' a Binder badge will be appended to the README file, linking to the live Binder instance. 65 | #' 66 | #' @param dockerfile Path to the tugboat-generated Dockerfile. 67 | #' @param branch Character string specifying the Git branch, tag, or commit hash to build. 68 | #' Defaults to `"main"`. 69 | #' @param hub The Binder hub to use. Currently only `"mybinder.org"` is supported. 70 | #' @param urlpath The URL path to open inside the Binder instance. 71 | #' Defaults to `"rstudio"`, which opens an RStudio Server session. 72 | #' @param add_readme_badge Logical. Whether to add a Binder launch badge to the README. 73 | #' Defaults to `TRUE`. 74 | #' 75 | #' @return Invisibly returns `NULL`. Called primarily for its side effects of creating 76 | #' Binder-related files and optionally committing them. 77 | #' 78 | #' @note 79 | #' Binder can only build from the remote GitHub repository. 80 | #' The `.binder/Dockerfile` and README changes must be committed and pushed before 81 | #' launching Binder; otherwise, the build will not reflect local modifications. 82 | #' 83 | #' @seealso 84 | #' * [tugboat::create()] — Generates a Dockerfile from an analysis directory. 85 | #' * [tugboat::build()] — Builds the corresponding Docker image locally. 86 | #' 87 | #' @examples 88 | #' \dontrun{ 89 | #' binderize( 90 | #' dockerfile = here::here("Dockerfile"), 91 | #' branch = "main", 92 | #' add_readme_badge = TRUE 93 | #' ) 94 | #' } 95 | #' 96 | #' @export 97 | binderize <- function( 98 | dockerfile = here::here("Dockerfile"), 99 | branch = "main", 100 | hub = "mybinder.org", 101 | urlpath = "rstudio", 102 | add_readme_badge = TRUE 103 | ) { 104 | hub <- match.arg(hub, c("mybinder.org")) # Add more hubs if interested later 105 | check_if_installed("gert") 106 | 107 | git_remotes <- gert::git_remote_list(dockerfile) 108 | git_remote <- git_remotes$url[git_remotes$name == "origin"][[1]] 109 | local_repo <- gert::git_find(dockerfile) 110 | username_repo <- strsplit( 111 | sub(".*github.com[:/](.*)\\.git$", "\\1", git_remote), 112 | "/" 113 | )[[1]] 114 | if (grepl("github.com", git_remote)) { 115 | binder_url <- sprintf( 116 | "https://%s/v2/gh/%s/%s?urlpath=%s", 117 | hub, 118 | paste(username_repo, collapse = "/"), 119 | branch, 120 | urlpath 121 | ) 122 | } else { 123 | stop("Only GitHub repositories are supported currently") 124 | } 125 | badge_url <- sprintf("https://%s/badge_logo.svg", hub) 126 | 127 | prep_binder_dockerfile(dockerfile, local_repo) 128 | if (add_readme_badge) { 129 | check_if_installed("usethis") 130 | usethis::use_badge("Launch RStudio Binder", binder_url, badge_url) 131 | } 132 | message("Your repository has been configured for Binder.") 133 | message("[x] Commit and push all changes") 134 | message("[x] Launch Binder at: ", binder_url) 135 | return(invisible(NULL)) 136 | } 137 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tugboat 2 | 3 | 4 | [![R-CMD-check](https://github.com/dmolitor/tugboat/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dmolitor/tugboat/actions/workflows/R-CMD-check.yaml) 5 | [![pkgdown](https://github.com/dmolitor/tugboat/actions/workflows/pkgdown.yaml/badge.svg)](https://github.com/dmolitor/tugboat/actions/workflows/pkgdown.yaml) 6 | [![CRAN status](https://www.r-pkg.org/badges/version/tugboat)](https://CRAN.R-project.org/package=tugboat) 7 | 8 | 9 | A simple R package to generate a Dockerfile and corresponding Docker image 10 | from an analysis directory. tugboat also prepares your analysis directory to be 11 | shared via [Binder](https://mybinder.readthedocs.io/en/latest/index.html). 12 | 13 | tugboat uses the [renv](https://github.com/rstudio/renv/) package to automatically 14 | detect all the packages necessary to replicate your analysis and will generate 15 | a Dockerfile that contains an exact copy of your entire directory with all 16 | the packages installed. tugboat transforms an unstructured analysis folder into a renv.lock file 17 | and constructs a Docker image that includes all your essential R packages 18 | based on this lockfile. 19 | 20 | tugboat may be of use, for example, when preparing a replication package for 21 | research. With tugboat, you can take a directory on your local computer 22 | and quickly generate a corresponding Dockerfile and Docker image that contains all the 23 | code and the necessary software to reproduce your findings. 24 | 25 | ## Installation 26 | 27 | Install tugboat from CRAN: 28 | ```r 29 | install.packages("tugboat") 30 | ``` 31 | 32 | Or install the development version from GitHub: 33 | ```r 34 | # install.packages("pak") 35 | pak::pkg_install("dmolitor/tugboat") 36 | ``` 37 | 38 | ## Usage 39 | 40 | tugboat only has three exported functions; one to create a Dockerfile from your 41 | analysis directory, one to build the corresponding Docker image, and one to make 42 | your project ready to share and run in an online, interactive compute environment 43 | via [Binder](https://mybinder.readthedocs.io/en/latest/index.html). 44 | 45 | ### Create the Dockerfile 46 | 47 | The primary function from tugboat is `create()`. This function converts 48 | your analysis directory into a Dockerfile that includes all your code 49 | and essential R packages. 50 | 51 | This function scans all files in the current analysis directory, 52 | attempts to detect all R packages, and installs these packages in 53 | the resulting Docker image. It also copies the entire contents of the 54 | analysis directory into the Docker image. For example, if 55 | your analysis directory is named `incredible_analysis`, the corresponding 56 | location of your code and data files in the generated Docker image will 57 | be `/incredible_analysis`. 58 | 59 | For the most common use-cases, there are a couple of arguments in this 60 | function that are particularly important: 61 | 62 | - `project`: This argument tells tugboat which directory is the one to generate 63 | the Dockerfile from. You can set this value yourself, or you can just use 64 | the default value. By default, tugboat uses the `here::here` function to 65 | determine what directory is the analysis directory. To get a detailed understanding 66 | of exactly how this works take a look at the [here package](https://github.com/r-lib/here/). 67 | In general, this "just works"! 68 | - `as`: This argument tells tugboat where to save the Dockerfile. In 69 | general you don't need to set this and tugboat will just save the 70 | Dockerfile in the `project` directory from above. 71 | - `exclude`: A vector of files or sub-directories in your analysis directory 72 | that should ***NOT*** be included in the Docker image. This is particularly 73 | important when you have, for example, a sub-directory with large data files 74 | that would make the resulting Docker image extremely large if included. You 75 | can tell tugboat to exclude this sub-directory and then simply mount it to 76 | a Docker container as needed. 77 | 78 | Below I'll outline a couple examples. 79 | ```r 80 | library(tugboat) 81 | 82 | # The simplest scenario where your analysis directory is your current 83 | # active project, you are fine with the default base "r-base:latest" 84 | # Docker image, and you want to include all files/directories: 85 | create() 86 | 87 | # Suppose your analysis directory is actually a sub-directory of your 88 | # main project directory: 89 | create(project = here::here("sub-directory")) 90 | 91 | # Suppose that you specifically need a Docker base image that has RStudio 92 | # installed so that you can interact with your analysis within a Docker 93 | # container. To do this, we will explicitly specify a different Docker 94 | # base image using the `FROM` argument. 95 | create(FROM = "rocker/rstudio") 96 | 97 | # Finally, suppose that we want to include all files except a couple 98 | # particularly data-heavy sub-directories: 99 | create(exclude = c("data/big_directory_1", "data/big_directory_2")) 100 | ``` 101 | 102 | ### Build the Docker image 103 | 104 | Once the Dockerfile has been created, we can build the Docker image 105 | with the `build()` function. By default this will infer the Dockerfile 106 | directory using `here::here`. This function assumes a little knowledge 107 | about Docker; if you aren't sure where to start, 108 | [this is a great starting point](https://colinfay.me/docker-r-reproducibility/). 109 | 110 | The following example will do the simplest thing and will build the 111 | image locally. 112 | ```r 113 | build(image_name = "awesome_analysis") 114 | ``` 115 | 116 | Suppose that, like above, your analysis directory is a sub-directory of 117 | your main project directory: 118 | ```r 119 | build( 120 | dockerfile = here::here("sub-directory"), 121 | image_name = "awesome_analysis" 122 | ) 123 | ``` 124 | 125 | ### Push to DockerHub 126 | 127 | If, instead of just building the Docker image locally, you want to build 128 | the image and then push to DockerHub, you can make a couple small additions 129 | to the code above: 130 | ```r 131 | build( 132 | image_name = "awesome_analysis", 133 | push = TRUE, 134 | dh_username = Sys.getenv("DH_USERNAME"), 135 | dh_password = Sys.getenv("DH_PASSWORD") 136 | ) 137 | ``` 138 | 139 | Note: If you choose to push, you also need to provide your DockerHub 140 | username and password. Typically you don't want to pass these in 141 | directly and should instead use environment variables (or a similar 142 | method) instead. 143 | 144 | ### Share your project via Binder 145 | 146 | Binder lets others instantly launch and interact with your R project in a 147 | live, cloud-based environment with no local setup required. tugboat will 148 | prepare your project to be shared with Binder. The process is simple: 149 | 150 | - First, create the Dockerfile from your analysis directory: 151 | 152 | ``` r 153 | create( 154 | project = here::here(), 155 | exclude = c("data/big_directory_1", "data/big_directory_2") 156 | ) 157 | ``` 158 | 159 | - Then, prep your directory for Binder. Your analysis directory _must_ be 160 | a GitHub repository: 161 | 162 | ``` r 163 | binderize(branch = "main") 164 | ``` 165 | By default this will add a Binder badge to your README.Rmd or README.md file. 166 | If your README file already has a section for badges, it will add the 167 | new badge automatically: 168 | 169 | ``` r 170 | ✔ Adding "Launch RStudio Binder badge" to README.md. 171 | ``` 172 | If your README file does _not_ have a section for badges, it will automatically 173 | save the badge to your clipboard and you will need to manually insert it 174 | into the README. 175 | 176 | ``` r 177 | ☐ Copy and paste the following lines into README.md: 178 | 179 | [![Launch RStudio Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/{username}/{repo}/{branch}?urlpath=rstudio) 180 | 181 | [Copied to clipboard] 182 | ``` 183 | 184 | After running `binderize()` you will see the following message: 185 | ``` 186 | Your repository has been configured for Binder. 187 | [x] Commit and push all changes 188 | [x] Launch Binder at: https://mybinder.org/v2/gh/{username}/{repo}/{branch}?urlpath=rstudio 189 | ``` 190 | 191 | You must commit and push all changes _before_ visiting the Binder link, 192 | otherwise it will likely fail. Binder can automatically detect changes 193 | to the repository and will rebuild as necessary, ensuring that the Binder 194 | repository stays up to date. 195 | 196 | ## Why tugboat? 🚢 197 | 198 | There are a few available packages with similar goals, so why tugboat? 199 | tugboat is minimal and builds directly on top of 200 | [`renv`](https://rstudio.github.io/renv/articles/renv.html) and 201 | [`pak`](https://pak.r-lib.org/). 202 | Each of these packages is actively maintained and provides specific 203 | utilities that the tugboat utilizes for maximum convenience. 204 | tugboat aims to leverage packages that are likely to remain actively 205 | maintained and handle dependency management as seamlessly as possible. 206 | 207 | - [containerit](https://o2r.info/containerit/) is a robust package that is 208 | directly comparable to tugboat. However, it implements its own method for 209 | discovering R package dependencies instead of using renv. It also relies on 210 | [sysreqsdb](https://github.com/r-hub/sysreqsdb) for system dependency 211 | discovery, which has been archived in favor of 212 | [r-system-requirements](https://github.com/rstudio/r-system-requirements), 213 | which pak is built on. It also isn't super actively maintained and isn't on 214 | CRAN. 215 | 216 | - [holepunch](https://github.com/karthik/holepunch) is related but focuses 217 | on making GitHub repositories Binder-compatible. It currently relies on MRAN, 218 | which is now obsolete, and does not use pak for system dependency management. 219 | It is also not actively maintained and is not on CRAN. 220 | 221 | - [automagic](https://github.com/cole-brokamp/automagic) focuses on 222 | automatically detecting and installing R package dependencies but uses its own 223 | method rather than relying on renv. automagic also has no utilities for 224 | creating/building Docker images. 225 | 226 | 227 | ## Examples 228 | 229 | For some worked examples of how to use tugboat in practice, see the 230 | `examples/` directory. 231 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU General Public License 2 | ========================== 3 | 4 | _Version 3, 29 June 2007_ 5 | _Copyright © 2007 Free Software Foundation, Inc. <>_ 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license 8 | document, but changing it is not allowed. 9 | 10 | ## Preamble 11 | 12 | The GNU General Public License is a free, copyleft license for software and other 13 | kinds of works. 14 | 15 | The licenses for most software and other practical works are designed to take away 16 | your freedom to share and change the works. By contrast, the GNU General Public 17 | License is intended to guarantee your freedom to share and change all versions of a 18 | program--to make sure it remains free software for all its users. We, the Free 19 | Software Foundation, use the GNU General Public License for most of our software; it 20 | applies also to any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not price. Our General 24 | Public Licenses are designed to make sure that you have the freedom to distribute 25 | copies of free software (and charge for them if you wish), that you receive source 26 | code or can get it if you want it, that you can change the software or use pieces of 27 | it in new free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you these rights or 30 | asking you to surrender the rights. Therefore, you have certain responsibilities if 31 | you distribute copies of the software, or if you modify it: responsibilities to 32 | respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether gratis or for a fee, 35 | you must pass on to the recipients the same freedoms that you received. You must make 36 | sure that they, too, receive or can get the source code. And you must show them these 37 | terms so they know their rights. 38 | 39 | Developers that use the GNU GPL protect your rights with two steps: **(1)** assert 40 | copyright on the software, and **(2)** offer you this License giving you legal permission 41 | to copy, distribute and/or modify it. 42 | 43 | For the developers' and authors' protection, the GPL clearly explains that there is 44 | no warranty for this free software. For both users' and authors' sake, the GPL 45 | requires that modified versions be marked as changed, so that their problems will not 46 | be attributed erroneously to authors of previous versions. 47 | 48 | Some devices are designed to deny users access to install or run modified versions of 49 | the software inside them, although the manufacturer can do so. This is fundamentally 50 | incompatible with the aim of protecting users' freedom to change the software. The 51 | systematic pattern of such abuse occurs in the area of products for individuals to 52 | use, which is precisely where it is most unacceptable. Therefore, we have designed 53 | this version of the GPL to prohibit the practice for those products. If such problems 54 | arise substantially in other domains, we stand ready to extend this provision to 55 | those domains in future versions of the GPL, as needed to protect the freedom of 56 | users. 57 | 58 | Finally, every program is threatened constantly by software patents. States should 59 | not allow patents to restrict development and use of software on general-purpose 60 | computers, but in those that do, we wish to avoid the special danger that patents 61 | applied to a free program could make it effectively proprietary. To prevent this, the 62 | GPL assures that patents cannot be used to render the program non-free. 63 | 64 | The precise terms and conditions for copying, distribution and modification follow. 65 | 66 | ## TERMS AND CONDITIONS 67 | 68 | ### 0. Definitions 69 | 70 | “This License” refers to version 3 of the GNU General Public License. 71 | 72 | “Copyright” also means copyright-like laws that apply to other kinds of 73 | works, such as semiconductor masks. 74 | 75 | “The Program” refers to any copyrightable work licensed under this 76 | License. Each licensee is addressed as “you”. “Licensees” and 77 | “recipients” may be individuals or organizations. 78 | 79 | To “modify” a work means to copy from or adapt all or part of the work in 80 | a fashion requiring copyright permission, other than the making of an exact copy. The 81 | resulting work is called a “modified version” of the earlier work or a 82 | work “based on” the earlier work. 83 | 84 | A “covered work” means either the unmodified Program or a work based on 85 | the Program. 86 | 87 | To “propagate” a work means to do anything with it that, without 88 | permission, would make you directly or secondarily liable for infringement under 89 | applicable copyright law, except executing it on a computer or modifying a private 90 | copy. Propagation includes copying, distribution (with or without modification), 91 | making available to the public, and in some countries other activities as well. 92 | 93 | To “convey” a work means any kind of propagation that enables other 94 | parties to make or receive copies. Mere interaction with a user through a computer 95 | network, with no transfer of a copy, is not conveying. 96 | 97 | An interactive user interface displays “Appropriate Legal Notices” to the 98 | extent that it includes a convenient and prominently visible feature that **(1)** 99 | displays an appropriate copyright notice, and **(2)** tells the user that there is no 100 | warranty for the work (except to the extent that warranties are provided), that 101 | licensees may convey the work under this License, and how to view a copy of this 102 | License. If the interface presents a list of user commands or options, such as a 103 | menu, a prominent item in the list meets this criterion. 104 | 105 | ### 1. Source Code 106 | 107 | The “source code” for a work means the preferred form of the work for 108 | making modifications to it. “Object code” means any non-source form of a 109 | work. 110 | 111 | A “Standard Interface” means an interface that either is an official 112 | standard defined by a recognized standards body, or, in the case of interfaces 113 | specified for a particular programming language, one that is widely used among 114 | developers working in that language. 115 | 116 | The “System Libraries” of an executable work include anything, other than 117 | the work as a whole, that **(a)** is included in the normal form of packaging a Major 118 | Component, but which is not part of that Major Component, and **(b)** serves only to 119 | enable use of the work with that Major Component, or to implement a Standard 120 | Interface for which an implementation is available to the public in source code form. 121 | A “Major Component”, in this context, means a major essential component 122 | (kernel, window system, and so on) of the specific operating system (if any) on which 123 | the executable work runs, or a compiler used to produce the work, or an object code 124 | interpreter used to run it. 125 | 126 | The “Corresponding Source” for a work in object code form means all the 127 | source code needed to generate, install, and (for an executable work) run the object 128 | code and to modify the work, including scripts to control those activities. However, 129 | it does not include the work's System Libraries, or general-purpose tools or 130 | generally available free programs which are used unmodified in performing those 131 | activities but which are not part of the work. For example, Corresponding Source 132 | includes interface definition files associated with source files for the work, and 133 | the source code for shared libraries and dynamically linked subprograms that the work 134 | is specifically designed to require, such as by intimate data communication or 135 | control flow between those subprograms and other parts of the work. 136 | 137 | The Corresponding Source need not include anything that users can regenerate 138 | automatically from other parts of the Corresponding Source. 139 | 140 | The Corresponding Source for a work in source code form is that same work. 141 | 142 | ### 2. Basic Permissions 143 | 144 | All rights granted under this License are granted for the term of copyright on the 145 | Program, and are irrevocable provided the stated conditions are met. This License 146 | explicitly affirms your unlimited permission to run the unmodified Program. The 147 | output from running a covered work is covered by this License only if the output, 148 | given its content, constitutes a covered work. This License acknowledges your rights 149 | of fair use or other equivalent, as provided by copyright law. 150 | 151 | You may make, run and propagate covered works that you do not convey, without 152 | conditions so long as your license otherwise remains in force. You may convey covered 153 | works to others for the sole purpose of having them make modifications exclusively 154 | for you, or provide you with facilities for running those works, provided that you 155 | comply with the terms of this License in conveying all material for which you do not 156 | control copyright. Those thus making or running the covered works for you must do so 157 | exclusively on your behalf, under your direction and control, on terms that prohibit 158 | them from making any copies of your copyrighted material outside their relationship 159 | with you. 160 | 161 | Conveying under any other circumstances is permitted solely under the conditions 162 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 163 | 164 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law 165 | 166 | No covered work shall be deemed part of an effective technological measure under any 167 | applicable law fulfilling obligations under article 11 of the WIPO copyright treaty 168 | adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention 169 | of such measures. 170 | 171 | When you convey a covered work, you waive any legal power to forbid circumvention of 172 | technological measures to the extent such circumvention is effected by exercising 173 | rights under this License with respect to the covered work, and you disclaim any 174 | intention to limit operation or modification of the work as a means of enforcing, 175 | against the work's users, your or third parties' legal rights to forbid circumvention 176 | of technological measures. 177 | 178 | ### 4. Conveying Verbatim Copies 179 | 180 | You may convey verbatim copies of the Program's source code as you receive it, in any 181 | medium, provided that you conspicuously and appropriately publish on each copy an 182 | appropriate copyright notice; keep intact all notices stating that this License and 183 | any non-permissive terms added in accord with section 7 apply to the code; keep 184 | intact all notices of the absence of any warranty; and give all recipients a copy of 185 | this License along with the Program. 186 | 187 | You may charge any price or no price for each copy that you convey, and you may offer 188 | support or warranty protection for a fee. 189 | 190 | ### 5. Conveying Modified Source Versions 191 | 192 | You may convey a work based on the Program, or the modifications to produce it from 193 | the Program, in the form of source code under the terms of section 4, provided that 194 | you also meet all of these conditions: 195 | 196 | * **a)** The work must carry prominent notices stating that you modified it, and giving a 197 | relevant date. 198 | * **b)** The work must carry prominent notices stating that it is released under this 199 | License and any conditions added under section 7. This requirement modifies the 200 | requirement in section 4 to “keep intact all notices”. 201 | * **c)** You must license the entire work, as a whole, under this License to anyone who 202 | comes into possession of a copy. This License will therefore apply, along with any 203 | applicable section 7 additional terms, to the whole of the work, and all its parts, 204 | regardless of how they are packaged. This License gives no permission to license the 205 | work in any other way, but it does not invalidate such permission if you have 206 | separately received it. 207 | * **d)** If the work has interactive user interfaces, each must display Appropriate Legal 208 | Notices; however, if the Program has interactive interfaces that do not display 209 | Appropriate Legal Notices, your work need not make them do so. 210 | 211 | A compilation of a covered work with other separate and independent works, which are 212 | not by their nature extensions of the covered work, and which are not combined with 213 | it such as to form a larger program, in or on a volume of a storage or distribution 214 | medium, is called an “aggregate” if the compilation and its resulting 215 | copyright are not used to limit the access or legal rights of the compilation's users 216 | beyond what the individual works permit. Inclusion of a covered work in an aggregate 217 | does not cause this License to apply to the other parts of the aggregate. 218 | 219 | ### 6. Conveying Non-Source Forms 220 | 221 | You may convey a covered work in object code form under the terms of sections 4 and 222 | 5, provided that you also convey the machine-readable Corresponding Source under the 223 | terms of this License, in one of these ways: 224 | 225 | * **a)** Convey the object code in, or embodied in, a physical product (including a 226 | physical distribution medium), accompanied by the Corresponding Source fixed on a 227 | durable physical medium customarily used for software interchange. 228 | * **b)** Convey the object code in, or embodied in, a physical product (including a 229 | physical distribution medium), accompanied by a written offer, valid for at least 230 | three years and valid for as long as you offer spare parts or customer support for 231 | that product model, to give anyone who possesses the object code either **(1)** a copy of 232 | the Corresponding Source for all the software in the product that is covered by this 233 | License, on a durable physical medium customarily used for software interchange, for 234 | a price no more than your reasonable cost of physically performing this conveying of 235 | source, or **(2)** access to copy the Corresponding Source from a network server at no 236 | charge. 237 | * **c)** Convey individual copies of the object code with a copy of the written offer to 238 | provide the Corresponding Source. This alternative is allowed only occasionally and 239 | noncommercially, and only if you received the object code with such an offer, in 240 | accord with subsection 6b. 241 | * **d)** Convey the object code by offering access from a designated place (gratis or for 242 | a charge), and offer equivalent access to the Corresponding Source in the same way 243 | through the same place at no further charge. You need not require recipients to copy 244 | the Corresponding Source along with the object code. If the place to copy the object 245 | code is a network server, the Corresponding Source may be on a different server 246 | (operated by you or a third party) that supports equivalent copying facilities, 247 | provided you maintain clear directions next to the object code saying where to find 248 | the Corresponding Source. Regardless of what server hosts the Corresponding Source, 249 | you remain obligated to ensure that it is available for as long as needed to satisfy 250 | these requirements. 251 | * **e)** Convey the object code using peer-to-peer transmission, provided you inform 252 | other peers where the object code and Corresponding Source of the work are being 253 | offered to the general public at no charge under subsection 6d. 254 | 255 | A separable portion of the object code, whose source code is excluded from the 256 | Corresponding Source as a System Library, need not be included in conveying the 257 | object code work. 258 | 259 | A “User Product” is either **(1)** a “consumer product”, which 260 | means any tangible personal property which is normally used for personal, family, or 261 | household purposes, or **(2)** anything designed or sold for incorporation into a 262 | dwelling. In determining whether a product is a consumer product, doubtful cases 263 | shall be resolved in favor of coverage. For a particular product received by a 264 | particular user, “normally used” refers to a typical or common use of 265 | that class of product, regardless of the status of the particular user or of the way 266 | in which the particular user actually uses, or expects or is expected to use, the 267 | product. A product is a consumer product regardless of whether the product has 268 | substantial commercial, industrial or non-consumer uses, unless such uses represent 269 | the only significant mode of use of the product. 270 | 271 | “Installation Information” for a User Product means any methods, 272 | procedures, authorization keys, or other information required to install and execute 273 | modified versions of a covered work in that User Product from a modified version of 274 | its Corresponding Source. The information must suffice to ensure that the continued 275 | functioning of the modified object code is in no case prevented or interfered with 276 | solely because modification has been made. 277 | 278 | If you convey an object code work under this section in, or with, or specifically for 279 | use in, a User Product, and the conveying occurs as part of a transaction in which 280 | the right of possession and use of the User Product is transferred to the recipient 281 | in perpetuity or for a fixed term (regardless of how the transaction is 282 | characterized), the Corresponding Source conveyed under this section must be 283 | accompanied by the Installation Information. But this requirement does not apply if 284 | neither you nor any third party retains the ability to install modified object code 285 | on the User Product (for example, the work has been installed in ROM). 286 | 287 | The requirement to provide Installation Information does not include a requirement to 288 | continue to provide support service, warranty, or updates for a work that has been 289 | modified or installed by the recipient, or for the User Product in which it has been 290 | modified or installed. Access to a network may be denied when the modification itself 291 | materially and adversely affects the operation of the network or violates the rules 292 | and protocols for communication across the network. 293 | 294 | Corresponding Source conveyed, and Installation Information provided, in accord with 295 | this section must be in a format that is publicly documented (and with an 296 | implementation available to the public in source code form), and must require no 297 | special password or key for unpacking, reading or copying. 298 | 299 | ### 7. Additional Terms 300 | 301 | “Additional permissions” are terms that supplement the terms of this 302 | License by making exceptions from one or more of its conditions. Additional 303 | permissions that are applicable to the entire Program shall be treated as though they 304 | were included in this License, to the extent that they are valid under applicable 305 | law. If additional permissions apply only to part of the Program, that part may be 306 | used separately under those permissions, but the entire Program remains governed by 307 | this License without regard to the additional permissions. 308 | 309 | When you convey a copy of a covered work, you may at your option remove any 310 | additional permissions from that copy, or from any part of it. (Additional 311 | permissions may be written to require their own removal in certain cases when you 312 | modify the work.) You may place additional permissions on material, added by you to a 313 | covered work, for which you have or can give appropriate copyright permission. 314 | 315 | Notwithstanding any other provision of this License, for material you add to a 316 | covered work, you may (if authorized by the copyright holders of that material) 317 | supplement the terms of this License with terms: 318 | 319 | * **a)** Disclaiming warranty or limiting liability differently from the terms of 320 | sections 15 and 16 of this License; or 321 | * **b)** Requiring preservation of specified reasonable legal notices or author 322 | attributions in that material or in the Appropriate Legal Notices displayed by works 323 | containing it; or 324 | * **c)** Prohibiting misrepresentation of the origin of that material, or requiring that 325 | modified versions of such material be marked in reasonable ways as different from the 326 | original version; or 327 | * **d)** Limiting the use for publicity purposes of names of licensors or authors of the 328 | material; or 329 | * **e)** Declining to grant rights under trademark law for use of some trade names, 330 | trademarks, or service marks; or 331 | * **f)** Requiring indemnification of licensors and authors of that material by anyone 332 | who conveys the material (or modified versions of it) with contractual assumptions of 333 | liability to the recipient, for any liability that these contractual assumptions 334 | directly impose on those licensors and authors. 335 | 336 | All other non-permissive additional terms are considered “further 337 | restrictions” within the meaning of section 10. If the Program as you received 338 | it, or any part of it, contains a notice stating that it is governed by this License 339 | along with a term that is a further restriction, you may remove that term. If a 340 | license document contains a further restriction but permits relicensing or conveying 341 | under this License, you may add to a covered work material governed by the terms of 342 | that license document, provided that the further restriction does not survive such 343 | relicensing or conveying. 344 | 345 | If you add terms to a covered work in accord with this section, you must place, in 346 | the relevant source files, a statement of the additional terms that apply to those 347 | files, or a notice indicating where to find the applicable terms. 348 | 349 | Additional terms, permissive or non-permissive, may be stated in the form of a 350 | separately written license, or stated as exceptions; the above requirements apply 351 | either way. 352 | 353 | ### 8. Termination 354 | 355 | You may not propagate or modify a covered work except as expressly provided under 356 | this License. Any attempt otherwise to propagate or modify it is void, and will 357 | automatically terminate your rights under this License (including any patent licenses 358 | granted under the third paragraph of section 11). 359 | 360 | However, if you cease all violation of this License, then your license from a 361 | particular copyright holder is reinstated **(a)** provisionally, unless and until the 362 | copyright holder explicitly and finally terminates your license, and **(b)** permanently, 363 | if the copyright holder fails to notify you of the violation by some reasonable means 364 | prior to 60 days after the cessation. 365 | 366 | Moreover, your license from a particular copyright holder is reinstated permanently 367 | if the copyright holder notifies you of the violation by some reasonable means, this 368 | is the first time you have received notice of violation of this License (for any 369 | work) from that copyright holder, and you cure the violation prior to 30 days after 370 | your receipt of the notice. 371 | 372 | Termination of your rights under this section does not terminate the licenses of 373 | parties who have received copies or rights from you under this License. If your 374 | rights have been terminated and not permanently reinstated, you do not qualify to 375 | receive new licenses for the same material under section 10. 376 | 377 | ### 9. Acceptance Not Required for Having Copies 378 | 379 | You are not required to accept this License in order to receive or run a copy of the 380 | Program. Ancillary propagation of a covered work occurring solely as a consequence of 381 | using peer-to-peer transmission to receive a copy likewise does not require 382 | acceptance. However, nothing other than this License grants you permission to 383 | propagate or modify any covered work. These actions infringe copyright if you do not 384 | accept this License. Therefore, by modifying or propagating a covered work, you 385 | indicate your acceptance of this License to do so. 386 | 387 | ### 10. Automatic Licensing of Downstream Recipients 388 | 389 | Each time you convey a covered work, the recipient automatically receives a license 390 | from the original licensors, to run, modify and propagate that work, subject to this 391 | License. You are not responsible for enforcing compliance by third parties with this 392 | License. 393 | 394 | An “entity transaction” is a transaction transferring control of an 395 | organization, or substantially all assets of one, or subdividing an organization, or 396 | merging organizations. If propagation of a covered work results from an entity 397 | transaction, each party to that transaction who receives a copy of the work also 398 | receives whatever licenses to the work the party's predecessor in interest had or 399 | could give under the previous paragraph, plus a right to possession of the 400 | Corresponding Source of the work from the predecessor in interest, if the predecessor 401 | has it or can get it with reasonable efforts. 402 | 403 | You may not impose any further restrictions on the exercise of the rights granted or 404 | affirmed under this License. For example, you may not impose a license fee, royalty, 405 | or other charge for exercise of rights granted under this License, and you may not 406 | initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging 407 | that any patent claim is infringed by making, using, selling, offering for sale, or 408 | importing the Program or any portion of it. 409 | 410 | ### 11. Patents 411 | 412 | A “contributor” is a copyright holder who authorizes use under this 413 | License of the Program or a work on which the Program is based. The work thus 414 | licensed is called the contributor's “contributor version”. 415 | 416 | A contributor's “essential patent claims” are all patent claims owned or 417 | controlled by the contributor, whether already acquired or hereafter acquired, that 418 | would be infringed by some manner, permitted by this License, of making, using, or 419 | selling its contributor version, but do not include claims that would be infringed 420 | only as a consequence of further modification of the contributor version. For 421 | purposes of this definition, “control” includes the right to grant patent 422 | sublicenses in a manner consistent with the requirements of this License. 423 | 424 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license 425 | under the contributor's essential patent claims, to make, use, sell, offer for sale, 426 | import and otherwise run, modify and propagate the contents of its contributor 427 | version. 428 | 429 | In the following three paragraphs, a “patent license” is any express 430 | agreement or commitment, however denominated, not to enforce a patent (such as an 431 | express permission to practice a patent or covenant not to sue for patent 432 | infringement). To “grant” such a patent license to a party means to make 433 | such an agreement or commitment not to enforce a patent against the party. 434 | 435 | If you convey a covered work, knowingly relying on a patent license, and the 436 | Corresponding Source of the work is not available for anyone to copy, free of charge 437 | and under the terms of this License, through a publicly available network server or 438 | other readily accessible means, then you must either **(1)** cause the Corresponding 439 | Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the 440 | patent license for this particular work, or **(3)** arrange, in a manner consistent with 441 | the requirements of this License, to extend the patent license to downstream 442 | recipients. “Knowingly relying” means you have actual knowledge that, but 443 | for the patent license, your conveying the covered work in a country, or your 444 | recipient's use of the covered work in a country, would infringe one or more 445 | identifiable patents in that country that you have reason to believe are valid. 446 | 447 | If, pursuant to or in connection with a single transaction or arrangement, you 448 | convey, or propagate by procuring conveyance of, a covered work, and grant a patent 449 | license to some of the parties receiving the covered work authorizing them to use, 450 | propagate, modify or convey a specific copy of the covered work, then the patent 451 | license you grant is automatically extended to all recipients of the covered work and 452 | works based on it. 453 | 454 | A patent license is “discriminatory” if it does not include within the 455 | scope of its coverage, prohibits the exercise of, or is conditioned on the 456 | non-exercise of one or more of the rights that are specifically granted under this 457 | License. You may not convey a covered work if you are a party to an arrangement with 458 | a third party that is in the business of distributing software, under which you make 459 | payment to the third party based on the extent of your activity of conveying the 460 | work, and under which the third party grants, to any of the parties who would receive 461 | the covered work from you, a discriminatory patent license **(a)** in connection with 462 | copies of the covered work conveyed by you (or copies made from those copies), or **(b)** 463 | primarily for and in connection with specific products or compilations that contain 464 | the covered work, unless you entered into that arrangement, or that patent license 465 | was granted, prior to 28 March 2007. 466 | 467 | Nothing in this License shall be construed as excluding or limiting any implied 468 | license or other defenses to infringement that may otherwise be available to you 469 | under applicable patent law. 470 | 471 | ### 12. No Surrender of Others' Freedom 472 | 473 | If conditions are imposed on you (whether by court order, agreement or otherwise) 474 | that contradict the conditions of this License, they do not excuse you from the 475 | conditions of this License. If you cannot convey a covered work so as to satisfy 476 | simultaneously your obligations under this License and any other pertinent 477 | obligations, then as a consequence you may not convey it at all. For example, if you 478 | agree to terms that obligate you to collect a royalty for further conveying from 479 | those to whom you convey the Program, the only way you could satisfy both those terms 480 | and this License would be to refrain entirely from conveying the Program. 481 | 482 | ### 13. Use with the GNU Affero General Public License 483 | 484 | Notwithstanding any other provision of this License, you have permission to link or 485 | combine any covered work with a work licensed under version 3 of the GNU Affero 486 | General Public License into a single combined work, and to convey the resulting work. 487 | The terms of this License will continue to apply to the part which is the covered 488 | work, but the special requirements of the GNU Affero General Public License, section 489 | 13, concerning interaction through a network will apply to the combination as such. 490 | 491 | ### 14. Revised Versions of this License 492 | 493 | The Free Software Foundation may publish revised and/or new versions of the GNU 494 | General Public License from time to time. Such new versions will be similar in spirit 495 | to the present version, but may differ in detail to address new problems or concerns. 496 | 497 | Each version is given a distinguishing version number. If the Program specifies that 498 | a certain numbered version of the GNU General Public License “or any later 499 | version” applies to it, you have the option of following the terms and 500 | conditions either of that numbered version or of any later version published by the 501 | Free Software Foundation. If the Program does not specify a version number of the GNU 502 | General Public License, you may choose any version ever published by the Free 503 | Software Foundation. 504 | 505 | If the Program specifies that a proxy can decide which future versions of the GNU 506 | General Public License can be used, that proxy's public statement of acceptance of a 507 | version permanently authorizes you to choose that version for the Program. 508 | 509 | Later license versions may give you additional or different permissions. However, no 510 | additional obligations are imposed on any author or copyright holder as a result of 511 | your choosing to follow a later version. 512 | 513 | ### 15. Disclaimer of Warranty 514 | 515 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 516 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 517 | PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER 518 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 519 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE 520 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 521 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 522 | 523 | ### 16. Limitation of Liability 524 | 525 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 526 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 527 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 528 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 529 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE 530 | OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE 531 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 532 | POSSIBILITY OF SUCH DAMAGES. 533 | 534 | ### 17. Interpretation of Sections 15 and 16 535 | 536 | If the disclaimer of warranty and limitation of liability provided above cannot be 537 | given local legal effect according to their terms, reviewing courts shall apply local 538 | law that most closely approximates an absolute waiver of all civil liability in 539 | connection with the Program, unless a warranty or assumption of liability accompanies 540 | a copy of the Program in return for a fee. 541 | 542 | _END OF TERMS AND CONDITIONS_ 543 | 544 | ## How to Apply These Terms to Your New Programs 545 | 546 | If you develop a new program, and you want it to be of the greatest possible use to 547 | the public, the best way to achieve this is to make it free software which everyone 548 | can redistribute and change under these terms. 549 | 550 | To do so, attach the following notices to the program. It is safest to attach them 551 | to the start of each source file to most effectively state the exclusion of warranty; 552 | and each file should have at least the “copyright” line and a pointer to 553 | where the full notice is found. 554 | 555 | 556 | Copyright (C) 557 | 558 | This program is free software: you can redistribute it and/or modify 559 | it under the terms of the GNU General Public License as published by 560 | the Free Software Foundation, either version 3 of the License, or 561 | (at your option) any later version. 562 | 563 | This program is distributed in the hope that it will be useful, 564 | but WITHOUT ANY WARRANTY; without even the implied warranty of 565 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 566 | GNU General Public License for more details. 567 | 568 | You should have received a copy of the GNU General Public License 569 | along with this program. If not, see . 570 | 571 | Also add information on how to contact you by electronic and paper mail. 572 | 573 | If the program does terminal interaction, make it output a short notice like this 574 | when it starts in an interactive mode: 575 | 576 | Copyright (C) 577 | This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. 578 | This is free software, and you are welcome to redistribute it 579 | under certain conditions; type 'show c' for details. 580 | 581 | The hypothetical commands `show w` and `show c` should show the appropriate parts of 582 | the General Public License. Of course, your program's commands might be different; 583 | for a GUI interface, you would use an “about box”. 584 | 585 | You should also get your employer (if you work as a programmer) or school, if any, to 586 | sign a “copyright disclaimer” for the program, if necessary. For more 587 | information on this, and how to apply and follow the GNU GPL, see 588 | <>. 589 | 590 | The GNU General Public License does not permit incorporating your program into 591 | proprietary programs. If your program is a subroutine library, you may consider it 592 | more useful to permit linking proprietary applications with the library. If this is 593 | what you want to do, use the GNU Lesser General Public License instead of this 594 | License. But first, please read 595 | <>. 596 | --------------------------------------------------------------------------------