Skip to content

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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

add: rstudio module #327

wants to merge 27 commits into from

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Aug 13, 2025

Description

This PR brings RStudio Server module. Since full RStudio distribution is hard to install in a consistent, stable way (lib versions, deps, etc.), this module bases on Docker distribution - Rocker.

Type of Change

  • New module
  • Bug fix
  • Feature/enhancement
  • Documentation
  • Other

Module Information

Path: registry/coder/modules/rstudio
New version: v0.9.0
Breaking change: [ ] Yes [ ] No

Testing & Validation

module "rstudio-server" {
  count    = data.coder_workspace.me.start_count
  source   = "git::https://github.com/coder/registry.git//registry/coder/modules/rstudio-server?ref=rstudio-module"

  agent_id = coder_agent.main.id
  docker_socket = var.docker_socket

  #disable_auth = false
  project_path = "/home/coder"
  enable_renv = true
}
  • Tests pass (bun test)
  • Code formatted (bun run fmt)
  • Changes tested locally

@mtojek mtojek self-assigned this Aug 13, 2025
@mtojek mtojek marked this pull request as ready for review August 13, 2025 15:06
@mtojek mtojek requested review from matifali and removed request for Copilot August 13, 2025 15:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new RStudio Server module for Coder that deploys RStudio Server using the Rocker Project Docker distribution. The module provides a consistent and stable way to run RStudio Server in Coder workspaces, handling authentication, project mounting, and R environment management with renv support.

  • Adds Docker-based RStudio Server deployment with configurable authentication and project paths
  • Implements renv cache volume for dependency persistence and automatic environment restoration
  • Provides comprehensive Terraform configuration with variables for customization and Coder app integration

Reviewed Changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 5 comments.

File Description
registry/coder/modules/rstudio-server/main.tf Terraform configuration defining variables, script execution, and Coder app setup
registry/coder/modules/rstudio-server/run.sh Shell script that manages Docker operations, container lifecycle, and renv restoration
registry/coder/modules/rstudio-server/README.md Documentation with module description and basic usage example

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

delay=2
attempt=1

while ! docker ps; do
Copy link
Preview

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docker readiness check only verifies that docker ps succeeds but doesn't handle potential authentication or permission issues. Consider redirecting stderr to /dev/null and adding a more specific check like docker ps > /dev/null 2>&1 to avoid cluttering output with error messages during the retry loop.

Suggested change
while ! docker ps; do
while ! docker ps > /dev/null 2>&1; do

Copilot uses AI. Check for mistakes.

Comment on lines +46 to +47
# Make RENV_CACHE_VOLUME writable to USER
docker exec rstudio-server bash -c 'chmod -R 0777 /renv/cache'
Copy link
Preview

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting permissions to 0777 (world-writable) creates a security risk by allowing any user to modify the renv cache. Consider using more restrictive permissions like 0755 or 0775, or setting ownership to the specific user instead.

Suggested change
# Make RENV_CACHE_VOLUME writable to USER
docker exec rstudio-server bash -c 'chmod -R 0777 /renv/cache'
# Make RENV_CACHE_VOLUME owned and writable by USER (not world-writable)
docker exec rstudio-server bash -c 'chown -R "${RSTUDIO_USER}":"${RSTUDIO_USER}" /renv/cache && chmod -R 0775 /renv/cache'

Copilot uses AI. Check for mistakes.

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)'
Copy link
Preview

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The R command execution lacks error handling. If the renv::restore() command fails, the script continues without indication of failure. Consider adding error checking or using set -e behavior by checking the exit code of the docker exec command.

Suggested change
'if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv", repos="https://cloud.r-project.org"); renv::restore(prompt = FALSE)'
'if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv", repos="https://cloud.r-project.org"); renv::restore(prompt = FALSE)'
if [ $? -ne 0 ]; then
echo "Error: renv::restore() failed inside the container."
exit 1
fi

Copilot uses AI. Check for mistakes.

variable "rstudio_password" {
type = string
description = "RStudio password"
default = "rstudio"
Copy link
Preview

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a hardcoded default password 'rstudio' creates a security vulnerability as it's easily guessable. Consider generating a random password by default or requiring users to explicitly set this variable without providing a weak default.

Suggested change
default = "rstudio"

Copilot uses AI. Check for mistakes.

display_name = "rstudio-server"
icon = "/icon/rstudio.svg"
script = templatefile("${path.module}/run.sh", {
DOCKER_HOST : var.docker_socket,
Copy link
Preview

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DOCKER_HOST environment variable is set but never used in the run.sh script. The script uses the default docker commands without specifying a custom socket. Either remove this variable or update the script to use DOCKER_HOST when provided.

Suggested change
DOCKER_HOST : var.docker_socket,

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants