feat: update provisioning scripts for AI tools and enhance workspace setup

This commit is contained in:
2025-09-07 22:10:44 +00:00
parent bb469f8d2b
commit 59fdf55518
12 changed files with 107 additions and 510 deletions

View File

@@ -21,6 +21,20 @@ resource "coder_app" "code_server" {
healthcheck {
url = "http://localhost:8080/healthz"
interval = 10
Files
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
# =============================================================================
# Coder Applications - Service Access Points
# Web interfaces and tools for development services
# =============================================================================
# =============================================================================
# IDE and Code Editor Access
# =============================================================================
# VS Code Server
\}
$0
threshold = 5
}
}
@@ -270,4 +284,4 @@ resource "coder_app" "file_manager" {
icon = "/icon/folder.svg"
command = "bash -c 'export TERM=xterm-256color && cd /workspaces && ranger'"
order = 5
}
}

View File

@@ -231,20 +231,21 @@ resource "docker_volume" "workspaces" {
}
}
# Build the devcontainer image with envbuilder
resource "envbuilder_cached_image" "devcontainer" {
builder_image = "ghcr.io/coder/envbuilder:latest"
git_url = var.devcontainer_repo_url
# Use the devcontainer.json from our repository
devcontainer_dir = ".devcontainer"
# Cache settings for faster builds
cache_repo = var.envbuilder_cache_repo
}
# Temporarily use the base image until we can push the devcontainer files
# TODO: Uncomment the envbuilder block after pushing to git
# resource "envbuilder_cached_image" "devcontainer" {
# builder_image = "ghcr.io/coder/envbuilder:latest"
# git_url = var.devcontainer_repo_url
#
# # Use the devcontainer.json from our repository
# devcontainer_dir = ".devcontainer"
#
# # Cache settings for faster builds
# cache_repo = var.envbuilder_cache_repo
# }
# Development Container Image using envbuilder
# Development Container Image - using base image for now
resource "docker_image" "devcontainer" {
name = envbuilder_cached_image.devcontainer.image
name = var.devcontainer_image
keep_locally = true
}

View File

@@ -1,253 +0,0 @@
terraform {
required_version = ">= 1.0"
required_providers {
coder = {
source = "coder/coder"
version = "~> 2.0"
}
docker = {
source = "kreuzwerker/docker"
version = "~> 2.25"
}
envbuilder = {
source = "coder/envbuilder"
version = "~> 1.0"
}
}
}
provider "coder" {}
provider "docker" {
host = var.docker_socket != "" ? var.docker_socket : null
}
provider "envbuilder" {}
# Data Sources
data "coder_provisioner" "me" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
# Parameters
data "coder_parameter" "repo" {
name = "repo"
display_name = "Repository"
description = "Select a repository to clone"
mutable = true
order = 1
option {
name = "Custom Development Environment"
description = "Full-stack development with all services"
value = "custom"
}
option {
name = "vercel/next.js"
description = "The React Framework"
value = "https://github.com/vercel/next.js"
}
option {
name = "Custom URL"
description = "Specify a custom repo URL below"
value = "custom-url"
}
}
data "coder_parameter" "custom_repo_url" {
name = "custom_repo_url"
display_name = "Custom Repository URL"
description = "Enter a custom repository URL"
default = ""
mutable = true
order = 2
}
data "coder_parameter" "enable_services" {
name = "enable_services"
display_name = "Enable Database Services"
description = "Enable PostgreSQL, Redis, Qdrant, and Docker Registry"
type = "bool"
default = "true"
mutable = true
order = 3
}
data "coder_parameter" "enable_ai_tools" {
name = "enable_ai_tools"
display_name = "Enable AI Assistant Tools"
description = "Install Claude Code and AI development tools"
type = "bool"
default = "true"
mutable = true
order = 4
}
data "coder_parameter" "enable_claude_code" {
name = "enable_claude_code"
display_name = "Enable Claude Code CLI"
description = "Install Claude Code command-line interface"
type = "bool"
default = "true"
mutable = true
order = 5
}
data "coder_parameter" "enable_cursor_support" {
name = "enable_cursor_support"
display_name = "Enable Cursor IDE Support"
description = "Install Cursor IDE configuration and settings"
type = "bool"
default = "true"
mutable = true
order = 6
}
data "coder_parameter" "enable_windsurf_support" {
name = "enable_windsurf_support"
display_name = "Enable Windsurf IDE Support"
description = "Install Windsurf IDE configuration and settings"
type = "bool"
default = "true"
mutable = true
order = 7
}
data "coder_parameter" "enable_jetbrains" {
name = "enable_jetbrains"
display_name = "Enable JetBrains Gateway"
description = "Enable JetBrains Gateway integration for remote development"
type = "bool"
default = "true"
mutable = true
order = 8
}
data "coder_parameter" "enable_jupyter" {
name = "enable_jupyter"
display_name = "Enable Jupyter Lab"
description = "Enable Jupyter Lab for data science and notebook development"
type = "bool"
default = "false"
mutable = true
order = 9
}
data "coder_parameter" "enable_pgadmin" {
name = "enable_pgadmin"
display_name = "Enable pgAdmin"
description = "Enable pgAdmin web interface for PostgreSQL management"
type = "bool"
default = "true"
mutable = true
order = 10
}
# Local Variables
locals {
# Container and workspace naming - use ID for immutability
container_name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
workspace_id = data.coder_workspace.me.id
# Use workspace ID for volume naming to prevent destruction on rename
volume_suffix = substr(data.coder_workspace.me.id, 0, 8)
# Git configuration
git_author_name = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
git_author_email = data.coder_workspace_owner.me.email
# Repository URL logic
repo_url = (
data.coder_parameter.repo.value == "custom" ? "https://github.com/coder/envbuilder" :
data.coder_parameter.repo.value == "custom-url" ? data.coder_parameter.custom_repo_url.value :
data.coder_parameter.repo.value
)
# Development container image is now built by envbuilder
# devcontainer_image = var.devcontainer_image # Deprecated
# Environment variables for the development container
dev_environment = {
# Git configuration
"GIT_AUTHOR_NAME" = local.git_author_name
"GIT_AUTHOR_EMAIL" = local.git_author_email
"GIT_COMMITTER_NAME" = local.git_author_name
"GIT_COMMITTER_EMAIL" = local.git_author_email
# Development tools
"NODE_VERSION" = var.node_version
"PYTHON_VERSION" = var.python_version
"RUST_VERSION" = "stable"
# Service URLs (when services are enabled)
"POSTGRES_URL" = data.coder_parameter.enable_services.value ? "postgresql://postgres:${var.postgres_password}@postgres-${local.workspace_id}:5432/postgres" : ""
"REDIS_URL" = data.coder_parameter.enable_services.value ? "redis://:${var.redis_password}@redis-${local.workspace_id}:6379" : ""
"QDRANT_URL" = data.coder_parameter.enable_services.value ? "http://qdrant-${local.workspace_id}:6333" : ""
# Development configuration
"EDITOR" = "code"
"PYTHONPATH" = "/workspaces"
"CARGO_HOME" = "/home/coder/.cargo"
"RUSTUP_HOME" = "/home/coder/.rustup"
}
# Legacy service URLs for backward compatibility
postgres_url = "postgresql://postgres:${var.postgres_password}@postgres-${local.workspace_id}:5432/postgres"
redis_url = "redis://:${var.redis_password}@redis-${local.workspace_id}:6379"
qdrant_url = "http://qdrant-${local.workspace_id}:6333"
}
# Docker Network
resource "docker_network" "workspace" {
name = "coder-${local.workspace_id}"
driver = "bridge"
labels {
label = "coder.workspace_id"
value = local.workspace_id
}
labels {
label = "coder.owner"
value = data.coder_workspace_owner.me.name
}
labels {
label = "coder.project"
value = var.project_name
}
}
# Workspace Volume
resource "docker_volume" "workspaces" {
name = "workspaces-${local.workspace_id}"
labels {
label = "coder.workspace_id"
value = local.workspace_id
}
labels {
label = "coder.owner"
value = data.coder_workspace_owner.me.name
}
labels {
label = "coder.type"
value = "workspace-data"
}
}
# Build the devcontainer image with envbuilder
resource "envbuilder_cached_image" "devcontainer" {
builder_image = "ghcr.io/coder/envbuilder:latest"
git_url = var.devcontainer_repo_url
# Use the devcontainer.json from our repository
devcontainer_dir = ".devcontainer"
# Cache settings for faster builds
cache_repo = var.envbuilder_cache_repo != "" ? var.envbuilder_cache_repo : null
# Ensure we build for the correct architecture
force_safe = true
}
# Development Container Image using envbuilder
resource "docker_image" "devcontainer" {
name = envbuilder_cached_image.devcontainer.image
keep_locally = true
}

View File

@@ -1,93 +1,86 @@
# =============================================================================
# Provisioning Scripts - Minimal Setup
# Most tools are now installed in the devcontainer image
# Provisioning Scripts - AI Development Tools and Extensions
# Installation scripts for Cursor, Claude Code, Windsurf support
# With inline line ending fixes for GUI paste issues
# =============================================================================
# =============================================================================
# Workspace Initialization
# Claude Code CLI Installation
# =============================================================================
resource "coder_script" "workspace_init" {
resource "coder_script" "claude_code_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_claude_code.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Initialize Workspace"
icon = "/icon/tools.svg"
display_name = "Install Claude Code CLI"
icon = "/icon/ai.svg"
run_on_start = true
script = <<-EOF
#!/bin/bash
set -e
echo "🚀 Initializing workspace..."
# Ensure workspace directory has correct permissions
if [ -w /workspaces ]; then
cd /workspaces
else
echo "Warning: /workspaces is not writable, staying in current directory"
fi
# Clone repository if CODER_WORKSPACE_REPO is set and directory is empty
if [ -n "$CODER_WORKSPACE_REPO" ] && [ -z "$(ls -A .)" ]; then
echo "📥 Cloning repository: $CODER_WORKSPACE_REPO"
git clone "$CODER_WORKSPACE_REPO" .
fi
# Run any project-specific setup if present
if [ -f .devcontainer/post-start.sh ]; then
echo "🔧 Running project-specific setup..."
bash .devcontainer/post-start.sh
fi
echo "✅ Workspace initialization complete!"
EOF
script = "echo '${base64encode(file("${path.module}/scripts/claude-install.sh"))}' | base64 -d | tr -d '\\r' | bash"
}
# =============================================================================
# Service Health Check (only if services are enabled)
# Cursor IDE Support Setup
# =============================================================================
resource "coder_script" "service_health" {
count = data.coder_parameter.enable_services.value ? 1 : 0
resource "coder_script" "cursor_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_cursor_support.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Check Service Health"
icon = "/icon/database.svg"
display_name = "Configure Cursor IDE Support"
icon = "/icon/code.svg"
run_on_start = true
script = <<-EOF
#!/bin/bash
set -e
echo "🔍 Checking service connectivity..."
# Check PostgreSQL
if [ -n "$POSTGRES_URL" ]; then
if pg_isready -d "$POSTGRES_URL" 2>/dev/null; then
echo "✅ PostgreSQL is ready"
else
echo "⚠️ PostgreSQL is not responding"
fi
fi
# Check Redis
if [ -n "$REDIS_URL" ]; then
REDIS_HOST=$(echo "$REDIS_URL" | sed -E 's|redis://[^@]*@([^:]+):.*|\1|')
REDIS_PORT=$(echo "$REDIS_URL" | sed -E 's|.*:([0-9]+).*|\1|')
if redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" ping 2>/dev/null | grep -q PONG; then
echo "✅ Redis is ready"
else
echo "⚠️ Redis is not responding"
fi
fi
# Check Qdrant
if [ -n "$QDRANT_URL" ]; then
if curl -s "$QDRANT_URL/readyz" | grep -q "ok"; then
echo "✅ Qdrant is ready"
else
echo "⚠️ Qdrant is not responding"
fi
fi
echo "🏁 Service health check complete"
EOF
script = "echo '${base64encode(file("${path.module}/scripts/cursor-setup.sh"))}' | base64 -d | tr -d '\\r' | bash"
}
# =============================================================================
# Windsurf IDE Support Setup
# =============================================================================
resource "coder_script" "windsurf_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_windsurf_support.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Configure Windsurf IDE Support"
icon = "/icon/code.svg"
run_on_start = true
script = "echo '${base64encode(file("${path.module}/scripts/windsurf-setup.sh"))}' | base64 -d | tr -d '\\r' | bash"
}
# =============================================================================
# Development Tools and Extensions
# =============================================================================
resource "coder_script" "dev_extensions" {
agent_id = coder_agent.main.id
display_name = "Install Development Tools"
icon = "/icon/tools.svg"
run_on_start = true
script = "echo '${base64encode(file("${path.module}/scripts/dev-tools.sh"))}' | base64 -d | tr -d '\\r' | bash"
}
# =============================================================================
# Git Hooks and Metadata Capture Setup
# =============================================================================
resource "coder_script" "git_hooks_setup" {
agent_id = coder_agent.main.id
display_name = "Setup Git Hooks"
icon = "/icon/git.svg"
run_on_start = true
script = "echo '${base64encode(file("${path.module}/scripts/git-hooks.sh"))}' | base64 -d | tr -d '\\r' | bash"
}
# =============================================================================
# Workspace Setup (Comprehensive Environment Configuration)
# =============================================================================
resource "coder_script" "workspace_setup" {
agent_id = coder_agent.main.id
display_name = "Setup Development Workspace"
icon = "/icon/tools.svg"
run_on_start = true
script = "echo '${base64encode(file("${path.module}/scripts/workspace-setup.sh"))}' | base64 -d | tr -d '\\r' | bash"
}

View File

@@ -1,72 +0,0 @@
# =============================================================================
# Provisioning Scripts - AI Development Tools and Extensions
# Simplified scripts to avoid carriage return issues
# =============================================================================
# =============================================================================
# Claude Code CLI Installation
# =============================================================================
resource "coder_script" "claude_code_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_claude_code.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Install Claude Code CLI"
icon = "/icon/ai.svg"
run_on_start = true
script = "#!/bin/sh\ncommand -v claude >/dev/null 2>&1 || curl -fsSL https://claude.ai/install.sh | sh || echo 'Claude Code CLI installation skipped'"
}
# =============================================================================
# Cursor IDE Support Setup
# =============================================================================
resource "coder_script" "cursor_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_cursor_support.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Configure Cursor IDE Support"
icon = "/icon/code.svg"
run_on_start = true
script = "#!/bin/sh\nmkdir -p /home/coder/.config/cursor && printf '{\\n \"workspaceFolder\": \"/workspaces\",\\n \"remote.SSH.defaultExtensions\": [\\n \"ms-python.python\",\\n \"esbenp.prettier-vscode\",\\n \"dbaeumer.vscode-eslint\"\\n ]\\n}' > /home/coder/.config/cursor/settings.json"
}
# =============================================================================
# Windsurf IDE Support Setup
# =============================================================================
resource "coder_script" "windsurf_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_windsurf_support.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Configure Windsurf IDE Support"
icon = "/icon/code.svg"
run_on_start = true
script = "#!/bin/sh\nmkdir -p /home/coder/.config/windsurf && printf '{\\n \"workspaceFolder\": \"/workspaces\",\\n \"codeium.enabled\": true\\n}' > /home/coder/.config/windsurf/settings.json"
}
# =============================================================================
# Development Tools and Extensions
# =============================================================================
resource "coder_script" "dev_extensions" {
agent_id = coder_agent.main.id
display_name = "Install Development Tools"
icon = "/icon/tools.svg"
run_on_start = true
script = "#!/bin/sh\ncommand -v ranger >/dev/null 2>&1 || (sudo apt-get update && sudo apt-get install -y ranger) || true"
}
# =============================================================================
# Git Hooks and Metadata Capture Setup
# =============================================================================
resource "coder_script" "git_hooks_setup" {
agent_id = coder_agent.main.id
display_name = "Setup Git Hooks"
icon = "/icon/git.svg"
run_on_start = true
script = "#!/bin/sh\ngit config --global user.name \"${local.git_author_name}\" && git config --global user.email \"${local.git_author_email}\" && git config --global init.defaultBranch main"
}

View File

@@ -1,86 +0,0 @@
# =============================================================================
# Provisioning Scripts - AI Development Tools and Extensions
# Installation scripts for Cursor, Claude Code, Windsurf support
# Using base64 encoding to avoid line ending issues
# =============================================================================
# =============================================================================
# Claude Code CLI Installation
# =============================================================================
resource "coder_script" "claude_code_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_claude_code.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Install Claude Code CLI"
icon = "/icon/ai.svg"
run_on_start = true
script = file("${path.module}/scripts/claude-install.sh")
}
# =============================================================================
# Cursor IDE Support Setup
# =============================================================================
resource "coder_script" "cursor_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_cursor_support.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Configure Cursor IDE Support"
icon = "/icon/code.svg"
run_on_start = true
script = file("${path.module}/scripts/cursor-setup.sh")
}
# =============================================================================
# Windsurf IDE Support Setup
# =============================================================================
resource "coder_script" "windsurf_setup" {
count = data.coder_parameter.enable_ai_tools.value && data.coder_parameter.enable_windsurf_support.value ? 1 : 0
agent_id = coder_agent.main.id
display_name = "Configure Windsurf IDE Support"
icon = "/icon/code.svg"
run_on_start = true
script = file("${path.module}/scripts/windsurf-setup.sh")
}
# =============================================================================
# Development Tools and Extensions
# =============================================================================
resource "coder_script" "dev_extensions" {
agent_id = coder_agent.main.id
display_name = "Install Development Tools"
icon = "/icon/tools.svg"
run_on_start = true
script = file("${path.module}/scripts/dev-tools.sh")
}
# =============================================================================
# Git Hooks and Metadata Capture Setup
# =============================================================================
resource "coder_script" "git_hooks_setup" {
agent_id = coder_agent.main.id
display_name = "Setup Git Hooks"
icon = "/icon/git.svg"
run_on_start = true
script = file("${path.module}/scripts/git-hooks.sh")
}
# =============================================================================
# Workspace Setup (Comprehensive Environment Configuration)
# =============================================================================
resource "coder_script" "workspace_setup" {
agent_id = coder_agent.main.id
display_name = "Setup Development Workspace"
icon = "/icon/tools.svg"
run_on_start = true
script = file("${path.module}/scripts/workspace-setup.sh")
}

View File

@@ -37,8 +37,8 @@ if ! command -v npm >/dev/null 2>&1; then
exit 1
fi
echo "📥 Installing Claude Code globally via npm..."
npm install -g @anthropic-ai/claude
echo "📥 Installing Claude Code CLI..."
npm install -g @anthropic-ai/claude-code
# Verify installation
if command -v claude >/dev/null 2>&1; then

View File

@@ -48,8 +48,8 @@ if [[ "$SYSTEM" == "windows" ]]; then
BIN_DIR="$HOME_DIR/bin"
CONFIG_DIR="$HOME_DIR/.config"
else
HOME_DIR="${HOME:-/home/coder}"
USER_NAME="${USER:-coder}"
HOME_DIR="${HOME:-/home/$(whoami)}"
USER_NAME="${USER:-$(whoami)}"
WORKSPACES_DIR="/workspaces"
TEMP_DIR="/tmp"
BIN_DIR="$HOME_DIR/bin"

View File

@@ -340,4 +340,4 @@ resource "docker_container" "jupyter" {
label = "coder.workspace_id"
value = local.workspace_id
}
}
}

View File

@@ -14,7 +14,7 @@ environment = "dev"
# =============================================================================
docker_socket = ""
# devcontainer_image is deprecated, using devcontainer_repo_url instead
devcontainer_repo_url = "http://git.lab/vasceannie/code-tools.git"
devcontainer_repo_url = "https://github.com/vasceannie/code-tools.git"
envbuilder_cache_repo = "local" # Set to your registry URL for faster builds, e.g. "ghcr.io/username/cache"
# =============================================================================
@@ -104,4 +104,4 @@ common_tags = {
Environment = "development"
ManagedBy = "terraform"
Purpose = "remote-development"
}
}

View File

@@ -48,7 +48,7 @@ variable "devcontainer_image" {
variable "devcontainer_repo_url" {
description = "Git repository URL containing the devcontainer configuration"
type = string
default = "http://git.lab/vasceannie/code-tools.git"
default = "https://github.com/vasceannie/code-tools.git"
}
variable "envbuilder_cache_repo" {
@@ -349,4 +349,4 @@ variable "common_tags" {
ManagedBy = "terraform"
Purpose = "remote-development"
}
}
}

View File

@@ -236,4 +236,4 @@ module "jetbrains_gateway" {
version = "2025.1"
}
}
}
}