-
Notifications
You must be signed in to change notification settings - Fork 73
add: rstudio module #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add: rstudio module #327
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
9218d02
Initial commit
mtojek 5947251
main.tf
mtojek 9f301d2
Merge branch 'main' into rstudio-module
mtojek acf7325
rename
mtojek 59b1b60
impl
mtojek 844efb1
fix
mtojek cc4cee5
fix
mtojek 28dda90
renv cache
mtojek a43ed67
fix
mtojek ba13e8f
fix
mtojek a4cabd7
fix
mtojek 9ace2c4
fix
mtojek 5d64bc5
fix
mtojek 32c258b
workaround: sleep
mtojek 0d8a6c9
fix
mtojek c831eeb
Rstudio image
mtojek 830bf27
fix chmod
mtojek 4632e67
WIP
mtojek 74e3c27
just FIXME
mtojek 423a0d9
retry
mtojek 20948a7
fix
mtojek b70669d
bash
mtojek db8ea05
fix
mtojek bcd57fc
fix
mtojek 8158580
fix
mtojek 069c2dd
fmt
mtojek 976d033
Merge branch 'main' into rstudio-module
DevelopmentCats 18dd978
Merge branch 'main' into rstudio-module
matifali bbc93a5
Atif's review
mtojek 40861b0
fix: bun run fmt
mtojek 9fc72cf
add note about Docker
mtojek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
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 | ||
|
||
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 | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
matifali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
mtojek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
mtojek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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' | ||
mtojek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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)' | ||
mtojek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
|
||
[ "${DISABLE_AUTH}" != "true" ] && echo "User: ${RSTUDIO_USER}" | ||
|
||
printf "\n$${BOLD}RStudio Server ${SERVER_VERSION} is running on port ${PORT}$${RESET}\n" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.