157 lines
4.8 KiB
HCL
157 lines
4.8 KiB
HCL
# =============================================================================
|
|
# Development Workspace Container
|
|
# Main development environment with all required tools
|
|
# =============================================================================
|
|
|
|
# =============================================================================
|
|
# Coder Agent - Workspace Management
|
|
# =============================================================================
|
|
|
|
resource "coder_agent" "main" {
|
|
arch = data.coder_provisioner.me.arch
|
|
os = "linux"
|
|
dir = "/workspaces"
|
|
|
|
# Environment variables for development
|
|
env = {
|
|
"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
|
|
"NODE_VERSION" = var.node_version
|
|
"PYTHON_VERSION" = var.python_version
|
|
"PATH" = "$PATH:/home/coder/.cargo/bin:/home/coder/.local/bin:/usr/local/bin"
|
|
"HOME" = "/home/coder"
|
|
"USER" = "coder"
|
|
# Service URLs for development
|
|
"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" : ""
|
|
# Additional environment variables for scripts
|
|
"ENABLE_SERVICES" = tostring(data.coder_parameter.enable_services.value)
|
|
}
|
|
|
|
# Load startup script from external file
|
|
startup_script = file("${path.module}/scripts/workspace-setup.sh")
|
|
|
|
# Performance and resource monitoring
|
|
metadata {
|
|
display_name = "CPU Usage"
|
|
key = "cpu_usage"
|
|
script = "coder stat cpu"
|
|
interval = 60
|
|
timeout = 10
|
|
}
|
|
|
|
metadata {
|
|
display_name = "RAM Usage"
|
|
key = "ram_usage"
|
|
script = "coder stat mem"
|
|
interval = 60
|
|
timeout = 10
|
|
}
|
|
|
|
metadata {
|
|
display_name = "Disk Usage"
|
|
key = "disk_usage"
|
|
script = "coder stat disk --path /workspaces"
|
|
interval = 300
|
|
timeout = 10
|
|
}
|
|
|
|
metadata {
|
|
display_name = "Git Branch"
|
|
key = "git_branch"
|
|
script = "cd /workspaces && git branch --show-current 2>/dev/null || echo 'no-repo'"
|
|
interval = 300
|
|
timeout = 5
|
|
}
|
|
}
|
|
|
|
# =============================================================================
|
|
# Main Development Container
|
|
# =============================================================================
|
|
|
|
resource "docker_container" "workspace" {
|
|
count = data.coder_workspace.me.start_count
|
|
image = docker_image.devcontainer.image_id
|
|
name = local.container_name
|
|
hostname = data.coder_workspace.me.name
|
|
|
|
# Container resource limits
|
|
memory = var.workspace_memory_limit * 1024 * 1024 # Convert MB to bytes
|
|
|
|
# Environment variables
|
|
env = [
|
|
"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}",
|
|
"NODE_VERSION=${var.node_version}",
|
|
"PYTHON_VERSION=${var.python_version}",
|
|
"CODER_AGENT_TOKEN=${coder_agent.main.token}"
|
|
]
|
|
|
|
# Network configuration
|
|
networks_advanced {
|
|
name = docker_network.workspace.name
|
|
}
|
|
|
|
# Host networking for Docker-in-Docker and reverse proxy support
|
|
host {
|
|
host = "host.docker.internal"
|
|
ip = "host-gateway"
|
|
}
|
|
|
|
# No port mappings needed - reverse proxy will handle routing
|
|
# All services run within the isolated workspace network
|
|
# Coder's port forwarding and apps will provide access via reverse proxy
|
|
|
|
|
|
# Volume mounts
|
|
volumes {
|
|
container_path = "/workspaces"
|
|
volume_name = docker_volume.workspaces.name
|
|
read_only = false
|
|
}
|
|
|
|
# Mount the existing coder-home volume for user data persistence
|
|
volumes {
|
|
container_path = "/home/coder"
|
|
volume_name = "bwk8ckcok8o84cc0o4os4sso_coder-home"
|
|
read_only = false
|
|
}
|
|
|
|
# Docker socket for Docker-in-Docker
|
|
volumes {
|
|
host_path = "/var/run/docker.sock"
|
|
container_path = "/var/run/docker.sock"
|
|
}
|
|
|
|
# Working directory
|
|
working_dir = "/workspaces"
|
|
|
|
# Keep container running
|
|
command = ["/bin/bash", "-c", "${coder_agent.main.init_script} && sleep infinity"]
|
|
|
|
# Container labels for management
|
|
labels {
|
|
label = "coder.owner"
|
|
value = data.coder_workspace_owner.me.name
|
|
}
|
|
labels {
|
|
label = "coder.workspace_id"
|
|
value = local.workspace_id
|
|
}
|
|
labels {
|
|
label = "coder.project"
|
|
value = var.project_name
|
|
}
|
|
|
|
# Dependencies
|
|
depends_on = [
|
|
docker_network.workspace,
|
|
docker_volume.workspaces,
|
|
docker_image.devcontainer
|
|
]
|
|
} |