mirror of
https://github.com/coder/registry.git
synced 2026-06-02 20:48:14 +00:00
add: rstudio module (#327)
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><path fill="#75aadb" d="M71.4 38.8c-1.5-.6-3.9-1-6.9-1.1-4.2-.1-9 .4-9.2.5v20c13.3.6 15.5-1.7 15.5-1.7 11.6-5.9 4.3-16.2.6-17.7z"/><path fill="#75aadb" d="M64 0C28.6 0 0 28.6 0 64s28.6 64 64 64 64-28.6 64-64S99.3 0 64 0zm28.6 89.8H82L64.4 63.5h-9V84h9v5.8H41.5v-5.7l7.6-.1-.1-45.9c-.8-.2-7.5-.8-7.5-.8V32c1 1 7.9 1.2 7.9 1.2 1.6.1 3.9.2 5.2-.1 9.3-1.7 16.4-.4 16.4-.4 14 3.2 14.2 15.8 10.3 22.6-3.5 5.8-10.3 7.2-10.3 7.2l14.4 21.8 7.2-.1v5.6z"/><path d="M41.595 87.073v-2.726l1.82-.141a59.125 59.125 0 013.752-.144h1.931V37.996l-.938-.127c-.516-.07-2.204-.248-3.752-.397l-2.813-.27v-2.51c0-2.332.027-2.495.39-2.3 1.583.847 10.7 1.07 15.83.388 4.202-.558 11.495-.425 14.035.257 5.483 1.472 9.11 4.646 10.824 9.473.717 2.018.817 5.847.216 8.224-.903 3.572-2.39 6.048-4.865 8.101-1.482 1.23-4.847 3.03-6.145 3.29-.397.079-.772.224-.832.321-.06.098 3.123 5.072 7.075 11.054l7.184 10.876 3.633-.068 3.634-.068V89.8l-5.242-.008-5.24-.007-8.82-13.234-8.817-13.234h-9.178V84.061h9.049V89.8H41.595zm25.158-29.162c3.476-.55 7.265-2.774 8.973-5.263 2.511-3.663 1.537-8.99-2.294-12.547-1.357-1.26-2.205-1.63-4.794-2.1-2.124-.386-8.66-.454-11.706-.122l-1.544.168-.058 10.083-.057 10.082.72.106c1.366.2 8.67-.075 10.76-.407z" fill="#fff" stroke="#fff" stroke-width=".788"/></svg>
|
||||||
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 302 KiB |
@@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
display_name: RStudio Server
|
||||||
|
description: Deploy the Rocker Project distribution of RStudio Server in your Coder workspace.
|
||||||
|
icon: ../../../../.icons/rstudio.svg
|
||||||
|
verified: true
|
||||||
|
tags: [rstudio, ide, web]
|
||||||
|
---
|
||||||
|
|
||||||
|
# RStudio Server
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This module requires `docker` to be available in the workspace. Check [Docker in Workspaces](https://coder.com/docs/admin/templates/extending-templates/docker-in-workspaces) to learn how you can set it up.
|
||||||
|
|
||||||
|
Deploy the Rocker Project distribution of RStudio Server in your Coder workspace.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```tf
|
||||||
|
module "rstudio-server" {
|
||||||
|
count = data.coder_workspace.me.start_count
|
||||||
|
source = "registry.coder.com/coder/rstudio-server/coder"
|
||||||
|
version = "0.9.0"
|
||||||
|
agent_id = coder_agent.example.id
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">= 1.0"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
coder = {
|
||||||
|
source = "coder/coder"
|
||||||
|
version = ">= 2.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add required variables for your modules and remove any unneeded variables
|
||||||
|
variable "agent_id" {
|
||||||
|
type = string
|
||||||
|
description = "The ID of a Coder agent."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "docker_socket" {
|
||||||
|
type = string
|
||||||
|
description = "(Optional) Docker socket URI"
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "rstudio_server_version" {
|
||||||
|
type = string
|
||||||
|
description = "RStudio Server version"
|
||||||
|
default = "4.5.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "disable_auth" {
|
||||||
|
type = bool
|
||||||
|
description = "Disable auth"
|
||||||
|
default = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "rstudio_user" {
|
||||||
|
type = string
|
||||||
|
description = "RStudio user"
|
||||||
|
default = "rstudio"
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "rstudio_password" {
|
||||||
|
type = string
|
||||||
|
description = "RStudio password"
|
||||||
|
default = "rstudio"
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "project_path" {
|
||||||
|
type = string
|
||||||
|
description = "The path to RStudio project, it will be mounted in the container."
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "port" {
|
||||||
|
type = number
|
||||||
|
description = "The port to run rstudio-server on."
|
||||||
|
default = 8787
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "enable_renv" {
|
||||||
|
type = bool
|
||||||
|
description = "If renv.lock exists, renv will restore the environment and install dependencies"
|
||||||
|
default = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "renv_cache_volume" {
|
||||||
|
type = string
|
||||||
|
description = "The name of the volume used by Renv to preserve dependencies between container restarts"
|
||||||
|
default = "renv-cache-volume"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "share" {
|
||||||
|
type = string
|
||||||
|
default = "owner"
|
||||||
|
validation {
|
||||||
|
condition = var.share == "owner" || var.share == "authenticated" || var.share == "public"
|
||||||
|
error_message = "Incorrect value. Please set either 'owner', 'authenticated', or 'public'."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "order" {
|
||||||
|
type = number
|
||||||
|
description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "group" {
|
||||||
|
type = string
|
||||||
|
description = "The name of a group that this app belongs to."
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "coder_script" "rstudio-server" {
|
||||||
|
agent_id = var.agent_id
|
||||||
|
display_name = "rstudio-server"
|
||||||
|
icon = "/icon/rstudio.svg"
|
||||||
|
script = templatefile("${path.module}/run.sh", {
|
||||||
|
DOCKER_HOST : var.docker_socket,
|
||||||
|
SERVER_VERSION : var.rstudio_server_version,
|
||||||
|
DISABLE_AUTH : var.disable_auth,
|
||||||
|
RSTUDIO_USER : var.rstudio_user,
|
||||||
|
RSTUDIO_PASSWORD : var.rstudio_password,
|
||||||
|
PROJECT_PATH : var.project_path,
|
||||||
|
PORT : var.port,
|
||||||
|
ENABLE_RENV : var.enable_renv,
|
||||||
|
RENV_CACHE_VOLUME : var.renv_cache_volume,
|
||||||
|
})
|
||||||
|
run_on_start = true
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "coder_app" "rstudio-server" {
|
||||||
|
agent_id = var.agent_id
|
||||||
|
slug = "rstudio-server"
|
||||||
|
display_name = "RStudio Server"
|
||||||
|
url = "http://localhost:${var.port}"
|
||||||
|
icon = "/icon/rstudio.svg"
|
||||||
|
subdomain = true
|
||||||
|
share = var.share
|
||||||
|
order = var.order
|
||||||
|
group = var.group
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
BOLD='\033[0;1m'
|
||||||
|
RESET='\033[0m'
|
||||||
|
|
||||||
|
printf "$${BOLD}Starting RStudio Server (Rocker)...$${RESET}\n"
|
||||||
|
|
||||||
|
# Wait for docker to become ready
|
||||||
|
max_attempts=10
|
||||||
|
delay=2
|
||||||
|
attempt=1
|
||||||
|
|
||||||
|
while ! docker ps; do
|
||||||
|
if [ $attempt -ge $max_attempts ]; then
|
||||||
|
echo "Failed to list containers after $${max_attempts} attempts."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Attempt $${attempt} failed, retrying in $${delay}s..."
|
||||||
|
sleep $delay
|
||||||
|
attempt=$(expr "$attempt" + 1)
|
||||||
|
delay=$(expr "$delay" \* 2) # exponential backoff
|
||||||
|
done
|
||||||
|
|
||||||
|
# Pull the specified version
|
||||||
|
IMAGE="rocker/rstudio:${SERVER_VERSION}"
|
||||||
|
docker pull "$${IMAGE}"
|
||||||
|
|
||||||
|
# Create (or reuse) a persistent renv cache volume
|
||||||
|
docker volume create "${RENV_CACHE_VOLUME}"
|
||||||
|
|
||||||
|
# Run container (auto-remove on stop)
|
||||||
|
docker run -d --rm \
|
||||||
|
--name rstudio-server \
|
||||||
|
-p "${PORT}:8787" \
|
||||||
|
-e DISABLE_AUTH="${DISABLE_AUTH}" \
|
||||||
|
-e USER="${RSTUDIO_USER}" \
|
||||||
|
-e PASSWORD="${RSTUDIO_PASSWORD}" \
|
||||||
|
-e RENV_PATHS_CACHE="/renv/cache" \
|
||||||
|
-v "${PROJECT_PATH}:/home/${RSTUDIO_USER}/project" \
|
||||||
|
-v "${RENV_CACHE_VOLUME}:/renv/cache" \
|
||||||
|
"$${IMAGE}"
|
||||||
|
|
||||||
|
# Make RENV_CACHE_VOLUME writable to USER
|
||||||
|
docker exec rstudio-server bash -c 'chmod -R 0777 /renv/cache'
|
||||||
|
|
||||||
|
# Optional renv restore
|
||||||
|
if [ "${ENABLE_RENV}" = "true" ] && [ -f "${PROJECT_PATH}/renv.lock" ]; then
|
||||||
|
echo "Restoring R environment via renv..."
|
||||||
|
docker exec -u "${RSTUDIO_USER}" rstudio-server R -q -e \
|
||||||
|
'if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv", repos="https://cloud.r-project.org"); renv::restore(prompt = FALSE)'
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ "${DISABLE_AUTH}" != "true" ] && echo "User: ${RSTUDIO_USER}"
|
||||||
|
|
||||||
|
printf "\n$${BOLD}RStudio Server ${SERVER_VERSION} is running on port ${PORT}$${RESET}\n"
|
||||||
Reference in New Issue
Block a user