From c92a97c15420eca79f07d1aca96b26e4b34aa499 Mon Sep 17 00:00:00 2001 From: joergklein Date: Thu, 16 Apr 2026 07:28:48 +0000 Subject: [PATCH] feat/docker-rstudio-template --- registry/joergklein/.images/avatar.jpg | Bin 0 -> 1222 bytes registry/joergklein/README.md | 11 ++ .../templates/docker-rstudio/README.md | 98 +++++++++++++ .../templates/docker-rstudio/build/Dockerfile | 46 ++++++ .../docker-rstudio/build/icon/rstudio.svg | 1 + .../templates/docker-rstudio/main.tf | 138 ++++++++++++++++++ 6 files changed, 294 insertions(+) create mode 100644 registry/joergklein/.images/avatar.jpg create mode 100644 registry/joergklein/README.md create mode 100644 registry/joergklein/templates/docker-rstudio/README.md create mode 100644 registry/joergklein/templates/docker-rstudio/build/Dockerfile create mode 100644 registry/joergklein/templates/docker-rstudio/build/icon/rstudio.svg create mode 100644 registry/joergklein/templates/docker-rstudio/main.tf diff --git a/registry/joergklein/.images/avatar.jpg b/registry/joergklein/.images/avatar.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d71831071746c626bab51ad55dbdc08bb5ebf153 GIT binary patch literal 1222 zcmex=KU|?coW@chxW@Tkz0jjJ8$}zAA zvI;30I#U-U>$dGXcJ4ZK_{h;?$4{I*b?NeztJkjIxOwa0qsLF4K70P+<*SdM zK7aZ8?fZ|PzZe;qA>IL!5Dy{wM-b>ACKeWE7Iu(-7@5j}m|2j8Rnd@5$T5&Tu~1ma zsF6d&Y2w0-2RW6EgFc8R6KQ!#m{`Vr(Mu#brIP!m}`f_n(=pZ~WQc$gW15ymXY zV9)UU-?@}z<)=4y>Qt&+%UfvdYIWgckiEUD7gu~RGZlYgY`e3>LYbxBFsVK>7)KI+?!f4Jn* zD|)0zQR~%#)%q+lUq!cFJ9u4rp`>W&+KpNt@9p*z-uc`7-3NAy_YqO5cfZX}*l?Ih zf09S;;XdPIb&KVD%cR*39?yENwzKWtw|}C7o8R8!dN4(${0mTIqvnpgvJq}O-<&;Z z>Kh%fZF_d4*zKCEH+vn`*ZIqY)h%CgC###ss^?T<=7pTl{|pi4e9PBA{dIM&aZvuo zXro1LC*{t#{XQ)<>yh@{u zvvae)yqqQa^u@6k3F$Ha8LDOKcC2T-{B`$T;}ENsqTMHzh4mi)+iY9>KJM^Gt0%XA z=uVKS{Om6I{nh>7x)pl_X7&^=IK7)Se&vIJOIc@xGw;g1ToCtn(>;ErbI;GuQ!VMw zl-K5IvJUrOd1xQUhq#4n?rz8pis&&+_|W% [!NOTE] +> This template is designed to be a starting point! Edit the Terraform to extend it for your use case. + +## Customization + +### Changing the R version + +Set the `rstudio_version` variable to any valid [rocker/rstudio tag](https://hub.docker.com/r/rocker/rstudio/tags) (for example `4.4.2`, `4.3`, or `latest`). + +### Installing additional R packages + +R packages are pre-installed via the `build/Dockerfile` so they are available immediately when the workspace starts. To add more packages, add `install.packages()` calls to the Dockerfile: + +```dockerfile +RUN R -e "install.packages(c('tidyverse', 'shiny'))" +``` + +The image is pre-configured to use [Posit Package Manager](https://packagemanager.posit.co/) which provides pre-compiled binary packages for fast installation. Packages installed at build time avoid long startup delays from compiling from source on every workspace start. + +### Adding system dependencies + +The `build/Dockerfile` extends the `rocker/rstudio` base image with system packages required by modules (e.g. `curl` for code-server, `cmake` for R package compilation). If you add modules that need additional system-level tools, add them to the `Dockerfile`: + +```dockerfile +RUN apt-get update \ + && apt-get install -y \ + curl \ + cmake \ + your-package-here \ + && rm -rf /var/lib/apt/lists/* +``` + +### Adding LaTeX for PDF rendering + +RMarkdown can render PDF output when LaTeX is available. Add the following to the startup script to install TinyTeX: + +```sh +R --quiet -e "if (!require('tinytex', quietly = TRUE)) { install.packages('tinytex', repos = 'https://cloud.r-project.org'); tinytex::install_tinytex() }" +``` diff --git a/registry/joergklein/templates/docker-rstudio/build/Dockerfile b/registry/joergklein/templates/docker-rstudio/build/Dockerfile new file mode 100644 index 000000000..d73df5c26 --- /dev/null +++ b/registry/joergklein/templates/docker-rstudio/build/Dockerfile @@ -0,0 +1,46 @@ +# syntax=docker/dockerfile:1 + +ARG RSTUDIO_VERSION=latest +FROM rocker/rstudio:${RSTUDIO_VERSION} + +USER root + +RUN apt-get update && apt-get install -y \ + curl \ + git \ + sudo \ + procps \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /tmp + +# TeX Live Installer +RUN wget https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz \ + && tar -xzf install-tl-unx.tar.gz \ + && cd install-tl-* \ + && echo "selected_scheme scheme-medium" > profile.txt \ + && ./install-tl -profile profile.txt \ + && cd / \ + && rm -rf /tmp/install-tl-* /tmp/install-tl-unx.tar.gz + +# Set PATH +ENV PATH="/usr/local/texlive/2026/bin/x86_64-linux:${PATH}" + +# Optional: LuaLaTeX-Pakete +RUN tlmgr install unicode-math luacode + +# R Pakete +RUN R -e "install.packages(c('rmarkdown'), repos='https://cloud.r-project.org')" + +# RStudio Konfiguration (kein Login nötig) +RUN echo "auth-minimum-user-id=0" >> /etc/rstudio/rserver.conf + +# Environment +ENV HOME=/home/rstudio \ + LANG=C.UTF-8 \ + LC_ALL=C.UTF-8 + +RUN chown -R rstudio:rstudio /home/rstudio + +USER rstudio +WORKDIR /home/rstudio diff --git a/registry/joergklein/templates/docker-rstudio/build/icon/rstudio.svg b/registry/joergklein/templates/docker-rstudio/build/icon/rstudio.svg new file mode 100644 index 000000000..f174e1c22 --- /dev/null +++ b/registry/joergklein/templates/docker-rstudio/build/icon/rstudio.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/registry/joergklein/templates/docker-rstudio/main.tf b/registry/joergklein/templates/docker-rstudio/main.tf new file mode 100644 index 000000000..1ee65f190 --- /dev/null +++ b/registry/joergklein/templates/docker-rstudio/main.tf @@ -0,0 +1,138 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + } + docker = { + source = "kreuzwerker/docker" + } + } +} + +# ------------------------- +# PROVIDER +# ------------------------- + +provider "docker" {} + +# ------------------------- +# DATA +# ------------------------- + +data "coder_workspace" "me" {} +data "coder_workspace_owner" "me" {} +data "coder_provisioner" "me" {} + +locals { + username = data.coder_workspace_owner.me.name +} + +# ------------------------- +# IMAGE +# ------------------------- + +resource "docker_image" "workspace" { + name = "coder-rstudio-${data.coder_workspace.me.id}" + + build { + context = "./build" + } +} + +# ------------------------- +# VOLUME +# ------------------------- + +resource "docker_volume" "home" { + name = "coder-${data.coder_workspace.me.id}-home" + + lifecycle { + ignore_changes = all + } +} + +# ------------------------- +# CODER AGENT +# ------------------------- + +resource "coder_agent" "main" { + arch = data.coder_provisioner.me.arch + os = "linux" + + env = { + HOME = "/home/rstudio" + } +} + +# ------------------------- +# CONTAINER +# ------------------------- + +resource "docker_container" "workspace" { + count = data.coder_workspace.me.start_count + + image = docker_image.workspace.image_id + + name = "coder-${local.username}-${data.coder_workspace.me.name}" + + command = [ + "bash", + "-lc", + <<-EOT + set -e + + echo "[startup] starting coder agent" + coder agent & + + echo "[startup] starting RStudio" + rserver --auth-none=1 \ + --www-port=8787 \ + --www-address=0.0.0.0 & + + wait -n + EOT + ] + + env = [ + "CODER_AGENT_TOKEN=${coder_agent.main.token}" + ] + + volumes { + container_path = "/home/rstudio" + volume_name = docker_volume.home.name + } +} + +# ------------------------- +# RSTUDIO APP +# ------------------------- + +resource "coder_app" "rstudio" { + agent_id = coder_agent.main.id + slug = "rstudio" + display_name = "RStudio" + + url = "http://localhost:8787" + + subdomain = true + share = "owner" + + healthcheck { + url = "http://localhost:8787" + interval = 5 + threshold = 30 + } +} + +# ------------------------- +# CODE-SERVER (MODUL) +# ------------------------- + +module "code-server" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/code-server/coder" + version = "~> 1.0" + + agent_id = coder_agent.main.id + folder = "/home/rstudio" +}