stevedore

:cloud::rowboat::whale::cloud: Docker client for R

https://github.com/richfitz/stevedore

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 3 committers (33.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.7%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

:cloud::rowboat::whale::cloud: Docker client for R

Basic Info
Statistics
  • Stars: 136
  • Watchers: 9
  • Forks: 9
  • Open Issues: 16
  • Releases: 0
Created over 8 years ago · Last pushed over 2 years ago
Metadata Files
Readme Changelog License

README.Rmd


# stevedore


[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R build status](https://github.com/richfitz/stevedore/workflows/R-CMD-check/badge.svg)](https://github.com/richfitz/stevedore/actions)
[![codecov.io](https://codecov.io/github/richfitz/stevedore/coverage.svg?branch=master)](https://app.codecov.io/github/richfitz/stevedore?branch=master)
[![](https://www.r-pkg.org/badges/version/stevedore)](https://cran.r-project.org/package=stevedore)


A docker client for R

```{r, prep, include = FALSE}
knitr::opts_chunk$set(error = FALSE)
has_internet <- function() {
  !is.null(suppressWarnings(utils::nsl("www.google.com")))
}
if (has_internet()) {
  d <- stevedore::docker_client()
  try(d$image$remove("alpine:3.1"), silent = TRUE)
}
```

![hello world example of stevedore](https://raw.githubusercontent.com/richfitz/stevedore/master/demo/hello.gif)


## Background

**What is docker?** Docker is a platform for "containerising" applications - running them in isolation from one another, removing differences of how they are built, what they are built from, and what resources they need (disk, ports, users, etc).  It's similar conceptually to virtualisation, but much more light weight.

**Why would one want to use docker from R?** Whenever you need to control external processes from an R script or package, it might be useful to interact with this process from in containers using docker

- *package authors* might want a clean environment to test their code (similar to travis)
- *a developer using an external database* in a package or in an analysis script might use docker to create disposable copies of the database, or to create a copy isolated from their production database
- *a researcher* might use docker to do a reproducible analysis, or preserve the artefacts that were created along with a copy of the environment that created them

These are discussed further in the [applications vignette](https://richfitz.github.io/stevedore/articles/examples.html)


## Usage

The main function in the package is `docker_client`; this will construct an object with which we can talk with the docker server.

```{r, create}
docker <- stevedore::docker_client()
docker
```

With this you can run containers:

```{r, run}
docker$container$run("alpine:3.1", c("echo", "hello world"))
```

Or run containers in the background

```{r, background}
docker$container$run("bfirsh/reticulate-splines", detach = TRUE)
```

You can manage containers

```{r, list}
docker$container$list()
id <- docker$container$list(limit = 1L)$id
container <- docker$container$get(id)
container
```

And control containers

```{r, control}
container$inspect()$config$image
container$logs()
container$stop(t = 0)
container$remove()
```

And manage images

```{r, images}
head(docker$image$list())
```

Some of these functions have many arguments, but `stevedore` includes help inline:

```{r, help}
docker$container$create
```

as well as via an `help()` method on each object (e.g., `docker$help()`, `docker$container$help()`) which will display help for the API version that you are using.

## Approach

The Docker API is [versioned](https://docs.docker.com/develop/sdk/#api-version-matrix) and each version includes a [machine-readable API specification](https://docs.docker.com/engine/api/v1.29).  Rather than manually write wrappers that fit the output docker gives, `stevedore` _generates_ an interface directly from the spefification.  Currently `stevedore` supports docker API versions `r stevedore:::DOCKER_API_VERSION_MIN` to `r stevedore:::DOCKER_API_VERSION_MAX` (defaulting to `r stevedore:::DOCKER_API_VERSION_DEFAULT`).

This approach means that the output will be type-stable - there is no inference on what to return based on what the server chooses to return.  With a given API version, the same fields will always be returned.  Some of this information is very rich, for example, for the backgrounded container above:

```{r, inspect}
container$inspect(reload = FALSE)
```

## Windows support

Windows support for docker through this package is currently incomplete.  The [appveyor build](https://ci.appveyor.com/project/richfitz/stevedore) tests only the parts of the package that don't actually call docker due to difficult-to-debug issues with container compatibility on that platform.

### Current situation

The support for windows is not as comprehensive as for other platforms (but I'm not sure how common using docker is on windows yet).  The reason for this is that [`curl`](https://cran.r-project.org/package=curl) (and the underlying `libcurl` library) do not support communicating over "named pipes" which is how docker works on windows 10.

The package includes a small wrapper around the python sdk's docker support.  On the R side this requires the `reticulate` package.  It also requires that you have a python installation that includes both the `docker` package and `pypiwin32` - once python is installed you can add these packages to python with

```
pip install docker pypiwin32
```

(or `pip3` instead of `pip` to use python3).

You can check that everything is configured by running

```r
stevedore:::httppipe_available(verbose = TRUE)
```

which will return `TRUE` if everything is OK, and otherwise print some information about errors loading the package.  In the case of error consult the reticulate documentation (`vignette("versions", package = "reticulate")` will be especially useful).  Improvements to installation documentation and process are welcome!

### Limitations

The primary limitation of the `httppipe` interface is that streaming connections are not supported.  This affects the following methods

* container logs with `follow = TRUE`: completely unsupported
* container run - works completely with `detach = TRUE`, and with `detach = FALSE` works but prints output only at the end (not streaming output)
* image build - works but information printed only at end of build rather than streaming
* image pull - works but information printed only at end of pull
* exec start - works but information printed only at end of execution

### Going forward

The support in this package is a duplicate of the micropackage [`httppipe`](https://github.com/richfitz/httppipe/).  This implements the minimum functionality with windows named pipes to support docker.  I would **love** for someone to help port this to a python-free package.  This probably requires a bit of C/C++ and knowledge of the win32 API.

## Development and testing

See the [development guide](https://github.com/richfitz/stevedore/blob/master/development.md) if you want to get started developing `stevedore` - it provides pointers to the core objects.

## Package limitations

Endpoints that require "http hijacking" are not fully supported (primarily `attach`) but the foundations are there to support this - stdin is likely to be a major hassle though and I'm not sure if it's possible from within R's REPL.

## Installation

`stevedore` can be installed from CRAN using

```r
install.packages("stevedore")
```

On windows you will also need `reticulate`

```r
install.packages("reticulate")
```

You will also need a python installation and the `docker` and `pypiwin32` packages, which can be installed with pip (see [above](#windows-support)).

Once installed, find out if everything is set up to use docker by running

```{r, available}
stevedore::docker_available()
```

To install the development version from GitHub, you can use `remotes`:

```r
remotes::install_github("richfitz/stevedore", upgrade = FALSE)
```

## Licence

MIT © [Rich FitzJohn](https://github.com/richfitz).

Please note that this project is released with a [Contributor Code of Conduct](https://github.com/richfitz/stevedore/blob/master/CONDUCT.md). By participating in this project you agree to abide by its terms.

Owner

  • Name: Rich FitzJohn
  • Login: richfitz
  • Kind: user
  • Location: London, UK
  • Company: @mrc-ide, @vimc, @reside-ic, @ropensci

GitHub Events

Total
  • Watch event: 2
  • Pull request event: 1
Last Year
  • Watch event: 2
  • Pull request event: 1

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 850
  • Total Committers: 3
  • Avg Commits per committer: 283.333
  • Development Distribution Score (DDS): 0.005
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Rich FitzJohn r****n@g****m 846
Teofil t****n@g****m 3
Daniel Nüst d****t@u****e 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 59
  • Total pull requests: 8
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 4 months
  • Total issue authors: 14
  • Total pull request authors: 6
  • Average comments per issue: 1.36
  • Average comments per pull request: 1.13
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • richfitz (44)
  • teofiln (2)
  • mskyttner (2)
  • ilarischeinin (1)
  • hermandr (1)
  • Waschoi (1)
  • nuest (1)
  • tellyshia (1)
  • fvalenduc (1)
  • cboettig (1)
  • bomeara (1)
  • englianhu (1)
  • leungi (1)
  • ismailsunni (1)
Pull Request Authors
  • richfitz (3)
  • olivroy (2)
  • teofiln (1)
  • karthik (1)
  • cderv (1)
  • nuest (1)
Top Labels
Issue Labels
testing (7) api (4) interface (3) hacktoberfest (2) docs (2) help wanted (1)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 416 last-month
  • Total docker downloads: 20,358
  • Total dependent packages: 4
    (may contain duplicates)
  • Total dependent repositories: 12
    (may contain duplicates)
  • Total versions: 9
  • Total maintainers: 1
proxy.golang.org: github.com/richfitz/stevedore
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 11 months ago
cran.r-project.org: stevedore

Docker Client

  • Versions: 6
  • Dependent Packages: 4
  • Dependent Repositories: 12
  • Downloads: 416 Last month
  • Docker Downloads: 20,358
Rankings
Stargazers count: 3.0%
Forks count: 7.3%
Dependent repos count: 8.3%
Dependent packages count: 9.3%
Average: 11.8%
Docker downloads count: 12.6%
Downloads: 30.0%
Maintainers (1)
Last synced: 10 months ago

Dependencies

DESCRIPTION cran
  • crayon * imports
  • curl >= 2.3.0 imports
  • jsonlite * imports
  • yaml >= 2.1.18 imports
  • knitr * suggests
  • openssl * suggests
  • redux * suggests
  • reticulate * suggests
  • rmarkdown * suggests
  • testthat * suggests
  • withr * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v3 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
inst/images/iterate/Dockerfile docker
  • alpine latest build
inst/images/tester/Dockerfile docker
  • rocker/r-ver latest build
tests/testthat/images/curl/Dockerfile docker
  • alpine latest build
tests/testthat/images/error/Dockerfile docker
  • alpine latest build
tests/testthat/images/fail/Dockerfile docker
  • alpine latest build
tests/testthat/images/iterate/Dockerfile docker
  • alpine latest build
vignettes_src/iterate/Dockerfile docker
  • alpine latest build