Skip to content

Commit

Permalink
add rocker sample
Browse files Browse the repository at this point in the history
  • Loading branch information
rkm committed Dec 9, 2024
1 parent 452f646 commit 625b4b3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rocker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM docker.io/rocker/rstudio:latest@sha256:ee7c4efa46f0b5d46e051393ef05f262aceb959463b15fc3648955965290d231

USER root
RUN mkdir /safe_data /safe_outputs /scratch /root/src

COPY ./src /root/src

WORKDIR /root/src

RUN r install_packages.R
22 changes: 22 additions & 0 deletions rocker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# TRE Rocker example

## Running

Run with `ces-run --debug --opt-file ./opt_file.txt` where `opt-file.txt` contains the following lines:

```txt
-p 8787:8787
-e PASSWORD=test
```

Note that the password can be changed or left out entirely. In this case, the container will generate a new password to use, which will be printed in the same terminal where `ces-run` was called.

## Notes

This example takes a rocker image, creates the TRE file system directories and an extra directory for source files `src`. A script that produces a plot is copied inside `src`, along with another containing a list of required packages and a bash script to automate the test. The required packages are then installed through the script and the rstudio instance is started, which can be accessed at localhost:8787 using a browser.

The user can run the code directly, create the plot and copy it to safe_outputs through the rstudio interface or run the `run_test.sh` script, which will perform these steps automatically.

The container uses rootless mode operation by default (assumes that the user starting the container in the host is not root). When run using podman (as in `ces-run`) the login user is **root**, while in docker **rstudio**. Forcing a user change results in rstudio not starting.

The example is tailored to podman, and the files are copied under the `/root/src` directory for ease of access when rstudio is first started. When using docker, they could for example be placed in `/home/rstudio/src` with appropriate permissions (the owner should be changed to the user **rstudio**).
1 change: 1 addition & 0 deletions rocker/src/install_packages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install.packages("ggplot2")
20 changes: 20 additions & 0 deletions rocker/src/plot_example.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# library
library(ggplot2)

# basic graph
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point()

# a data frame with all the annotation info
annotation <- data.frame(
x = c(2,4.5),
y = c(20,25),
label = c("label 1", "label 2")
)

# Add text
p + geom_text(data=annotation, aes( x=x, y=y, label=label), ,
color="orange",
size=7 , angle=45, fontface="bold" )

ggsave("test_figure.png")
9 changes: 9 additions & 0 deletions rocker/src/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

cd /root/src

# Run example script
r plot_example.R

# Copy output to /safe_outputs
mv *.png /safe_outputs

0 comments on commit 625b4b3

Please sign in to comment.