diff --git a/rocker/Dockerfile b/rocker/Dockerfile new file mode 100644 index 0000000..7ed03e8 --- /dev/null +++ b/rocker/Dockerfile @@ -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 diff --git a/rocker/README.md b/rocker/README.md new file mode 100644 index 0000000..716bc30 --- /dev/null +++ b/rocker/README.md @@ -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**). diff --git a/rocker/src/install_packages.R b/rocker/src/install_packages.R new file mode 100644 index 0000000..df6d6a8 --- /dev/null +++ b/rocker/src/install_packages.R @@ -0,0 +1 @@ +install.packages("ggplot2") diff --git a/rocker/src/plot_example.R b/rocker/src/plot_example.R new file mode 100644 index 0000000..5ae41a9 --- /dev/null +++ b/rocker/src/plot_example.R @@ -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") diff --git a/rocker/src/run_test.sh b/rocker/src/run_test.sh new file mode 100644 index 0000000..a7bad8d --- /dev/null +++ b/rocker/src/run_test.sh @@ -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