Skip to content

Commit

Permalink
Add Docker (#44)
Browse files Browse the repository at this point in the history
* Run `golem::add_dockerfile_with_renv()`

* Rename files

* Clean up base Dockerfile

* Clean up main Dockerfile

* Remove dev dependencies from `renv.lock.prod`

* Update deployment instructions

* Update README; add overview and Deployment section
  • Loading branch information
milanmlft authored Aug 28, 2024
1 parent 4d2159e commit c82e88a
Show file tree
Hide file tree
Showing 7 changed files with 1,305 additions and 0 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ $run_dev.*
^\.github$
^\.lintr$
^\.renvignore$
^deploy$
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

The goal of calypso is to provide a summary of OMOP data and display it in a public data catalogue

## Overview

1. [Installation](#installation)
2. [Development](#development)
- [Set up](#set-up)
- [Updating the `renv` lockfile](#updating-the-renv-lockfile)
- [Design](#design)
- [Coding style](#coding-style)
3. [Deployment](./deploy/README.md)

## Installation

You can install the development version of calypso from within R like so:
Expand Down Expand Up @@ -120,3 +130,7 @@ lintr::lint_package()
```

(or have it [run automatically in your IDE](https://lintr.r-lib.org/articles/editors.html)).

## Deployment

See the [deployment docs](./deploy/README.md).
16 changes: 16 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM calypso_base:4.4.1

WORKDIR /app
COPY renv.lock.prod renv.lock

RUN R -e 'renv::restore()'

COPY calypso_*.tar.gz /app.tar.gz
RUN R -e 'remotes::install_local("/app.tar.gz", upgrade="never")' && \
rm /app.tar.gz

EXPOSE 3838
CMD ["R", "-e", "options('shiny.port'=3838,shiny.host='0.0.0.0');library(calypso);calypso::run_app()"]

# to build: docker build -t calypso .
# to run: docker run -p 3838:3838 calypso
19 changes: 19 additions & 0 deletions deploy/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM rocker/shiny-verse:4.4.1
SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"]

RUN mkdir -p /usr/local/lib/R/etc/ /usr/lib/R/etc/

# Set R options
RUN echo "options(renv.config.pak.enabled = FALSE, repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl', Ncpus = 4)" |\
tee /usr/local/lib/R/etc/Rprofile.site | \
tee /usr/lib/R/etc/Rprofile.site

# Install renv
RUN R -e 'install.packages("remotes")' && \
R -e 'remotes::install_version("renv", version = "1.0.7")'

# Restore renv environment
RUN mkdir /app
WORKDIR /app
COPY renv.lock.prod renv.lock
RUN R -e 'renv::restore()'
41 changes: 41 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Deploy

## Build the package

From the package root directory, run from `R`:

```r
pkgbuild::build(path = ".", dest_path = "deploy")
```

## Create `renv.lock.prod`

From the package root directory, run from `R`:

```r
renv::snapshot(project = ".", lockfile = "./deploy/renv.lock.prod", type = "explicit")
```

## Build Docker images

In the `deploy/` directory, run:

```shell
# Assuming R version 4.4.1
docker build -f Dockerfile.base --platform=linux/amd64 -t calypso_base:4.4.1 .
docker build -f Dockerfile --platform=linux/amd64 -t calypso:latest .
```

The `calypso_base` image acts as a cached image with most of the necessary dependencies installed,
to speed up the build process of the `calypso` image. The base image is not intended to be run and
is only expected to be rebuilt in case of major dependency changes.

Note that the `calypso` image also includes a `renv::restore()` step, so any dependencies not present
in the base image will still be installed.

## Run Docker container

```shell
docker run -p 3838:3838 calypso:latest
# then go to 127.0.0.1:80
```
Binary file added deploy/calypso_0.0.0.9000.tar.gz
Binary file not shown.
Loading

0 comments on commit c82e88a

Please sign in to comment.