Content-Length: 52077 | pFad | http://github.com/coder/coder/pull/18907.diff
thub.com diff --git a/docs/about/contributing/backend.md b/docs/about/contributing/backend.md index ad5d91bcda879..cfc70af53e74a 100644 --- a/docs/about/contributing/backend.md +++ b/docs/about/contributing/backend.md @@ -49,7 +49,7 @@ Coder's backend is built using a collection of robust, modern Go libraries and i The Coder backend is organized into multiple packages and directories, each with a specific purpose. Here's a high-level overview of the most important ones: -* [agent](https://github.com/coder/coder/tree/main/agent): core logic of a workspace agent, supports DevContainers, remote SSH, startup/shutdown script execution. Protobuf definitions for DRPC communication with `coderd` are kept in [proto](https://github.com/coder/coder/tree/main/agent/proto). +* [agent](https://github.com/coder/coder/tree/main/agent): core logic of a workspace agent, supports dev containers, remote SSH, startup/shutdown script execution. Protobuf definitions for DRPC communication with `coderd` are kept in [proto](https://github.com/coder/coder/tree/main/agent/proto). * [cli](https://github.com/coder/coder/tree/main/cli): CLI interface for `coder` command built on [coder/serpent](https://github.com/coder/serpent). Input controls are defined in [cliui](https://github.com/coder/coder/tree/docs-backend-contrib-guide/cli/cliui), and [testdata](https://github.com/coder/coder/tree/docs-backend-contrib-guide/cli/testdata) contains golden files for common CLI calls * [cmd](https://github.com/coder/coder/tree/main/cmd): entry points for CLI and services, including `coderd` * [coderd](https://github.com/coder/coder/tree/main/coderd): the main API server implementation with [chi](https://github.com/go-chi/chi) endpoints @@ -72,7 +72,7 @@ The Coder backend is organized into multiple packages and directories, each with * [dbpurge](https://github.com/coder/coder/tree/main/coderd/database/dbpurge): simple wrapper for periodic database cleanup operations * [migrations](https://github.com/coder/coder/tree/main/coderd/database/migrations): an ordered list of up/down database migrations, use `./create_migration.sh my_migration_name` to modify the database schema * [pubsub](https://github.com/coder/coder/tree/main/coderd/database/pubsub): PubSub implementation using PostgreSQL and in-memory drop-in replacement - * [queries](https://github.com/coder/coder/tree/main/coderd/database/queries): contains SQL files with queries, `sqlc` compiles them to [Go functions](https://github.com/coder/coder/blob/docs-backend-contrib-guide/coderd/database/queries.sql.go) + * [queries](https://github.com/coder/coder/tree/main/coderd/database/queries): contains SQL files with queries, `sqlc` compiles them to [Go functions](https://github.com/coder/coder/tree/main/coderd/database/queries.sql.go) * [sqlc.yaml](https://github.com/coder/coder/tree/main/coderd/database/sqlc.yaml): defines mappings between SQL types and custom Go structures * [codersdk](https://github.com/coder/coder/tree/main/codersdk): user-facing API entities used by CLI and site to communicate with `coderd` endpoints * [dogfood](https://github.com/coder/coder/tree/main/dogfood): Terraform definition of the dogfood cluster deployment diff --git a/docs/admin/templates/extending-templates/advanced-dev-containers.md b/docs/admin/templates/extending-templates/advanced-dev-containers.md new file mode 100644 index 0000000000000..6cba8db818354 --- /dev/null +++ b/docs/admin/templates/extending-templates/advanced-dev-containers.md @@ -0,0 +1,100 @@ +# Advanced Dev Container Configuration + +This page extends the [dev containers documentation](./devcontainers.md) with patterns for multiple dev containers, +user-controlled startup, repository selection, and infrastructure tuning. + +## Run Multiple Dev Containers + +Run independent dev containers in the same workspace so each component appears as its own agent. + +In this example, there are two: repositories called `frontend` and `backend`: + +```terraform +# Clone each repo +module "git-clone-frontend" { + count = data.coder_workspace.me.start_count + source = "dev.registry.coder.com/modules/git-clone/coder" + + agent_id = coder_agent.main.id + url = "https://github.com/your-org/frontend.git" +} + +module "git-clone-backend" { + count = data.coder_workspace.me.start_count + source = "dev.registry.coder.com/modules/git-clone/coder" + + agent_id = coder_agent.main.id + url = "https://github.com/your-org/backend.git" +} + +# Dev container resources +resource "coder_devcontainer" "frontend" { + count = data.coder_workspace.me.start_count + agent_id = coder_agent.main.id + workspace_folder = module.git-clone-frontend[0].repo_dir +} + +resource "coder_devcontainer" "backend" { + count = data.coder_workspace.me.start_count + agent_id = coder_agent.main.id + workspace_folder = module.git-clone-backend[0].repo_dir +} +``` + +Each dev container appears as a separate agent, so developers can connect to each separately. + +## Conditional Startup + +Use `coder_parameter` booleans to let workspace creators choose which dev containers start automatically, +reducing resource usage for unneeded components: + +```terraform +data "coder_parameter" "autostart_frontend" { + type = "bool" + name = "Autostart frontend container" + default = true + mutable = true + order = 3 +} + +resource "coder_devcontainer" "frontend" { + count = data.coder_parameter.autostart_frontend.value ? data.coder_workspace.me.start_count : 0 + agent_id = coder_agent.main.id + workspace_folder = module.git-clone-frontend[0].repo_dir +} +``` + +## Repository-selection Patterns + +Prompt users to pick a repository or team at workspace creation time and clone the selected repo(s) automatically into the workspace: + +1. Add a parameter to the template: + + ```terraform + data "coder_parameter" "project" { + name = "project" + display_name = "Choose a project" + type = "string" + default = "https://github.com/coder/coder.git" + + option { + name = "coder/coder" + value = "https://github.com/coder/coder.git" + } + option { + name = "terraform-provider-coder" + value = "https://github.com/coder/terraform-provider-coder.git" + } + } + ``` + +1. Change the `git-clone` module to accept the `value` as the `url`: + + ```terraform + module "git-clone" { + count = data.coder_workspace.me.start_count + source = "dev.registry.coder.com/modules/git-clone/coder" + agent_id = coder_agent.main.id + url = data.coder_parameter.project.value + } + ``` diff --git a/docs/admin/templates/extending-templates/dev-containers-envbuilder.md b/docs/admin/templates/extending-templates/dev-containers-envbuilder.md new file mode 100644 index 0000000000000..4a8d53091b0dd --- /dev/null +++ b/docs/admin/templates/extending-templates/dev-containers-envbuilder.md @@ -0,0 +1,23 @@ +# Choose an Approach To Dev Containers + +Coder supports two independent ways to run Dev Containers inside a workspace. + +Both implement the [Dev Container specification](https://containers.dev/), but they differ in how the container is built, +who controls it, and which runtime requirements exist. + +Use this page to decide which path fits your project or platform needs. + +## Options at a Glance + +| Capability / Trait | Dev Containers integration | Envbuilder | +|------------------------------------------|--------------------------------------------|-------------------------------------------| +| How it's built | `@devcontainers/cli` and Docker | Envbuilder transforms the workspace image | +| Docker-in-Docker? | Yes (parent workspace and child container) | No (modifies the parent container) | +| Multiple dev containers per workspace | Yes | No | +| Rebuild when `devcontainer.json` changes | Yes - user-initiated | Requires full workspace restart | + +## Related Reading + +- [Dev Containers integration](./devcontainers.md) +- [Dev Containers specification](https://containers.dev/) +- [Envbuilder on GitHub](https://github.com/coder/envbuilder) diff --git a/docs/admin/templates/extending-templates/devcontainers.md b/docs/admin/templates/extending-templates/devcontainers.md index d4284bf48efde..83cc80537c0f2 100644 --- a/docs/admin/templates/extending-templates/devcontainers.md +++ b/docs/admin/templates/extending-templates/devcontainers.md @@ -1,79 +1,191 @@ -# Configure a template for dev containers +# Configure a Template for Dev Containers -To enable dev containers in workspaces, configure your template with the dev containers +Dev containers provide consistent, reproducible development environments using the +[Development Containers specification](https://containers.dev/). +Coder's dev container support allows developers to work in fully configured environments with their preferred tools and extensions. + +To enable dev containers in workspaces, [configure your template](../creating-templates.md) with the dev containers modules and configurations outlined in this doc. +## Why Use Dev Containers + +Dev containers improve consistency across environments by letting developers define their development setup within +the code repository. + +When integrated with Coder templates, dev containers provide: + +- **Project-specific environments**: Each repository can define its own tools, extensions, and configuration. +- **Zero setup time**: Developers start workspace with fully configured environments without additional installation. +- **Consistency across teams**: Everyone works in identical environments regardless of their local machine. +- **Version-controlled environments**: Development environment changes are tracked alongside code changes. + +The Dev Container integration replaces the legacy Envbuilder integration. +Visit [Choose an approach to Dev Containers](./dev-containers-envbuilder.md) for more information about how they compare. + +## Prerequisites + +- Dev containers require Docker to build and run containers inside the workspace. + + Ensure your workspace infrastructure has Docker configured with container creation permissions and sufficient resources. + + If it doesn't, follow the steps in [Docker in workspaces](./docker-in-workspaces.md). + +- The `devcontainers-cli` module requires npm. + + - You can use an image that already includes npm, such as `codercom/enterprise-node:ubuntu`. + ## Install the Dev Containers CLI Use the [devcontainers-cli](https://registry.coder.com/modules/devcontainers-cli) module -to ensure the `@devcontainers/cli` is installed in your workspace: +to install `devcontainers/cli` in your workspace: ```terraform module "devcontainers-cli" { count = data.coder_workspace.me.start_count - source = "dev.registry.coder.com/modules/devcontainers-cli/coder" - agent_id = coder_agent.dev.id + source = "registry.coder.com/modules/devcontainers-cli/coder" + agent_id = coder_agent.main.id } ``` -Alternatively, install the devcontainer CLI manually in your base image. +Alternatively, install `@devcontainer/cli` manually in your base image: -## Configure Automatic Dev Container Startup +```shell +RUN npm install -g @devcontainers/cli +``` + +## Define the Dev Container Resource -The -[`coder_devcontainer`](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/devcontainer) -resource automatically starts a dev container in your workspace, ensuring it's -ready when you access the workspace: +If you don't use the [`git-clone`](#clone-the-repository) module, point the resource at the folder that contains `devcontainer.json`: ```terraform resource "coder_devcontainer" "my-repository" { count = data.coder_workspace.me.start_count - agent_id = coder_agent.dev.id - workspace_folder = "/home/coder/my-repository" + agent_id = coder_agent.main.id + workspace_folder = "/home/coder/project" # or /home/coder/project/.devcontainer } ``` > [!NOTE] -> > The `workspace_folder` attribute must specify the location of the dev > container's workspace and should point to a valid project folder containing a > `devcontainer.json` file. - +## Add Dev Container Features -> [!TIP] -> -> Consider using the [`git-clone`](https://registry.coder.com/modules/git-clone) -> module to ensure your repository is cloned into the workspace folder and ready -> for automatic startup. +Enhance your dev container experience with additional features. +For more advanced use cases, consult the [advanced dev containers doc](./advanced-dev-containers.md). -## Enable Dev Containers Integration +### Custom applications -To enable the dev containers integration in your workspace, you must set the -`CODER_AGENT_DEVCONTAINERS_ENABLE` environment variable to `true` in your -workspace container: +Add apps to the dev container workspace resource for one-click access. ```terraform -resource "docker_container" "workspace" { - count = data.coder_workspace.me.start_count - image = "codercom/oss-dogfood:latest" - env = [ - "CODER_AGENT_DEVCONTAINERS_ENABLE=true", - # ... Other environment variables. - ] - # ... Other container configuration. + "coder": { + "apps": [ + { + "slug": "cursor", + "displayName": "Cursor", + "url": "cursor://coder.coder-remote/openDevContainer?owner=${localEnv:CODER_WORKSPACE_OWNER_NAME}&workspace=${localEnv:CODER_WORKSPACE_NAME}&agent=${localEnv:CODER_WORKSPACE_PARENT_AGENT_NAME}&url=${localEnv:CODER_URL}&token=$SESSION_TOKEN&devContainerName=${localEnv:CONTAINER_ID}&devContainerFolder=${containerWorkspaceFolder}&localWorkspaceFolder=${localWorkspaceFolder}", + "external": true, + "icon": "/icon/cursor.svg", + "order": 1 + }, +``` + +Fetched URL: http://github.com/coder/coder/pull/18907.diff
Alternative Proxies: