Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e1c6eb

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/cors
2 parents 3dc00e1 + 1da27a1 commit 5e1c6eb

File tree

6,499 files changed

+174290
-63560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,499 files changed

+174290
-63560
lines changed

.cursorrules

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Cursor Rules
2+
3+
This project is called "Coder" - an application for managing remote development environments.
4+
5+
Coder provides a platform for creating, managing, and using remote development environments (also known as Cloud Development Environments or CDEs). It leverages Terraform to define and provision these environments, which are referred to as "workspaces" within the project. The system is designed to be extensible, secure, and provide developers with a seamless remote development experience.
6+
7+
# Core Architecture
8+
9+
The heart of Coder is a control plane that orchestrates the creation and management of workspaces. This control plane interacts with separate Provisioner processes over gRPC to handle workspace builds. The Provisioners consume workspace definitions and use Terraform to create the actual infrastructure.
10+
11+
The CLI package serves dual purposes - it can be used to launch the control plane itself and also provides client functionality for users to interact with an existing control plane instance. All user-facing frontend code is developed in TypeScript using React and lives in the `site/` directory.
12+
13+
The database layer uses PostgreSQL with SQLC for generating type-safe database code. Database migrations are carefully managed to ensure both forward and backward compatibility through paired `.up.sql` and `.down.sql` files.
14+
15+
# API Design
16+
17+
Coder's API architecture combines REST and gRPC approaches. The REST API is defined in `coderd/coderd.go` and uses Chi for HTTP routing. This provides the primary interface for the frontend and external integrations.
18+
19+
Internal communication with Provisioners occurs over gRPC, with service definitions maintained in `.proto` files. This separation allows for efficient binary communication with the components responsible for infrastructure management while providing a standard REST interface for human-facing applications.
20+
21+
# Network Architecture
22+
23+
Coder implements a secure networking layer based on Tailscale's Wireguard implementation. The `tailnet` package provides connectivity between workspace agents and clients through DERP (Designated Encrypted Relay for Packets) servers when direct connections aren't possible. This creates a secure overlay network allowing access to workspaces regardless of network topology, firewalls, or NAT configurations.
24+
25+
## Tailnet and DERP System
26+
27+
The networking system has three key components:
28+
29+
1. **Tailnet**: An overlay network implemented in the `tailnet` package that provides secure, end-to-end encrypted connections between clients, the Coder server, and workspace agents.
30+
31+
2. **DERP Servers**: These relay traffic when direct connections aren't possible. Coder provides several options:
32+
- A built-in DERP server that runs on the Coder control plane
33+
- Integration with Tailscale's global DERP infrastructure
34+
- Support for custom DERP servers for lower latency or offline deployments
35+
36+
3. **Direct Connections**: When possible, the system establishes peer-to-peer connections between clients and workspaces using STUN for NAT traversal. This requires both endpoints to send UDP traffic on ephemeral ports.
37+
38+
## Workspace Proxies
39+
40+
Workspace proxies (in the Enterprise edition) provide regional relay points for browser-based connections, reducing latency for geo-distributed teams. Key characteristics:
41+
42+
- Deployed as independent servers that authenticate with the Coder control plane
43+
- Relay connections for SSH, workspace apps, port forwarding, and web terminals
44+
- Do not make direct database connections
45+
- Managed through the `coder wsproxy` commands
46+
- Implemented primarily in the `enterprise/wsproxy/` package
47+
48+
# Agent System
49+
50+
The workspace agent runs within each provisioned workspace and provides core functionality including:
51+
- SSH access to workspaces via the `agentssh` package
52+
- Port forwarding
53+
- Terminal connectivity via the `pty` package for pseudo-terminal support
54+
- Application serving
55+
- Healthcheck monitoring
56+
- Resource usage reporting
57+
58+
Agents communicate with the control plane using the tailnet system and authenticate using secure tokens.
59+
60+
# Workspace Applications
61+
62+
Workspace applications (or "apps") provide browser-based access to services running within workspaces. The system supports:
63+
64+
- HTTP(S) and WebSocket connections
65+
- Path-based or subdomain-based access URLs
66+
- Health checks to monitor application availability
67+
- Different sharing levels (owner-only, authenticated users, or public)
68+
- Custom icons and display settings
69+
70+
The implementation is primarily in the `coderd/workspaceapps/` directory with components for URL generation, proxying connections, and managing application state.
71+
72+
# Implementation Details
73+
74+
The project structure separates frontend and backend concerns. React components and pages are organized in the `site/src/` directory, with Jest used for testing. The backend is primarily written in Go, with a strong emphasis on error handling patterns and test coverage.
75+
76+
Database interactions are carefully managed through migrations in `coderd/database/migrations/` and queries in `coderd/database/queries/`. All new queries require proper database authorization (dbauthz) implementation to ensure that only users with appropriate permissions can access specific resources.
77+
78+
# Authorization System
79+
80+
The database authorization (dbauthz) system enforces fine-grained access control across all database operations. It uses role-based access control (RBAC) to validate user permissions before executing database operations. The `dbauthz` package wraps the database store and performs authorization checks before returning data. All database operations must pass through this layer to ensure security.
81+
82+
# Testing Framework
83+
84+
The codebase has a comprehensive testing approach with several key components:
85+
86+
1. **Parallel Testing**: All tests must use `t.Parallel()` to run concurrently, which improves test suite performance and helps identify race conditions.
87+
88+
2. **coderdtest Package**: This package in `coderd/coderdtest/` provides utilities for creating test instances of the Coder server, setting up test users and workspaces, and mocking external components.
89+
90+
3. **Integration Tests**: Tests often span multiple components to verify system behavior, such as template creation, workspace provisioning, and agent connectivity.
91+
92+
4. **Enterprise Testing**: Enterprise features have dedicated test utilities in the `coderdenttest` package.
93+
94+
# Open Source and Enterprise Components
95+
96+
The repository contains both open source and enterprise components:
97+
98+
- Enterprise code lives primarily in the `enterprise/` directory
99+
- Enterprise features focus on governance, scalability (high availability), and advanced deployment options like workspace proxies
100+
- The boundary between open source and enterprise is managed through a licensing system
101+
- The same core codebase supports both editions, with enterprise features conditionally enabled
102+
103+
# Development Philosophy
104+
105+
Coder emphasizes clear error handling, with specific patterns required:
106+
- Concise error messages that avoid phrases like "failed to"
107+
- Wrapping errors with `%w` to maintain error chains
108+
- Using sentinel errors with the "err" prefix (e.g., `errNotFound`)
109+
110+
All tests should run in parallel using `t.Parallel()` to ensure efficient testing and expose potential race conditions. The codebase is rigorously linted with golangci-lint to maintain consistent code quality.
111+
112+
Git contributions follow a standard format with commit messages structured as `type: <message>`, where type is one of `feat`, `fix`, or `chore`.
113+
114+
# Development Workflow
115+
116+
Development can be initiated using `scripts/develop.sh` to start the application after making changes. Database schema updates should be performed through the migration system using `create_migration.sh <name>` to generate migration files, with each `.up.sql` migration paired with a corresponding `.down.sql` that properly reverts all changes.
117+
118+
If the development database gets into a bad state, it can be completely reset by removing the PostgreSQL data directory with `rm -rf .coderv2/postgres`. This will destroy all data in the development database, requiring you to recreate any test users, templates, or workspaces after restarting the application.
119+
120+
Code generation for the database layer uses `coderd/database/generate.sh`, and developers should refer to `sqlc.yaml` for the appropriate style and patterns to follow when creating new queries or tables.
121+
122+
The focus should always be on maintaining security through proper database authorization, clean error handling, and comprehensive test coverage to ensure the platform remains robust and reliable.

.devcontainer/devcontainer.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
}
1010
},
1111
// SYS_PTRACE to enable go debugging
12-
"runArgs": ["--cap-add=SYS_PTRACE"]
12+
"runArgs": ["--cap-add=SYS_PTRACE"],
13+
"customizations": {
14+
"vscode": {
15+
"extensions": ["biomejs.biome"]
16+
}
17+
}
1318
}

.dockerignore

-6
This file was deleted.

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Generated files
2+
agent/agentcontainers/acmock/acmock.go linguist-generated=true
3+
agent/agentcontainers/dcspec/dcspec_gen.go linguist-generated=true
4+
agent/agentcontainers/testdata/devcontainercli/*/*.log linguist-generated=true
25
coderd/apidoc/docs.go linguist-generated=true
36
docs/reference/api/*.md linguist-generated=true
47
docs/reference/cli/*.md linguist-generated=true

.github/.linkspector.yml

+6
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@ ignorePatterns:
1818
- pattern: "i.imgur.com"
1919
- pattern: "code.visualstudio.com"
2020
- pattern: "www.emacswiki.org"
21+
- pattern: "linux.die.net/man"
22+
- pattern: "www.gnu.org"
23+
- pattern: "wiki.ubuntu.com"
24+
- pattern: "mutagen.io"
25+
- pattern: "docs.github.com"
26+
- pattern: "claude.ai"
2127
aliveStatusCodes:
2228
- 200

.github/ISSUE_TEMPLATE/1-bug.yaml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: "🐞 Bug"
2+
description: "File a bug report."
3+
title: "bug: "
4+
labels: ["needs-triage"]
5+
body:
6+
- type: checkboxes
7+
id: existing_issues
8+
attributes:
9+
label: "Is there an existing issue for this?"
10+
description: "Please search to see if an issue already exists for the bug you encountered."
11+
options:
12+
- label: "I have searched the existing issues"
13+
required: true
14+
15+
- type: textarea
16+
id: issue
17+
attributes:
18+
label: "Current Behavior"
19+
description: "A concise description of what you're experiencing."
20+
placeholder: "Tell us what you see!"
21+
validations:
22+
required: false
23+
24+
- type: textarea
25+
id: logs
26+
attributes:
27+
label: "Relevant Log Output"
28+
description: "Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks."
29+
render: shell
30+
31+
- type: textarea
32+
id: expected
33+
attributes:
34+
label: "Expected Behavior"
35+
description: "A concise description of what you expected to happen."
36+
validations:
37+
required: false
38+
39+
- type: textarea
40+
id: steps_to_reproduce
41+
attributes:
42+
label: "Steps to Reproduce"
43+
description: "Provide step-by-step instructions to reproduce the issue."
44+
placeholder: |
45+
1. First step
46+
2. Second step
47+
3. Another step
48+
4. Issue occurs
49+
validations:
50+
required: true
51+
52+
- type: textarea
53+
id: environment
54+
attributes:
55+
label: "Environment"
56+
description: |
57+
Provide details about your environment:
58+
- **Host OS**: (e.g., Ubuntu 24.04, Debian 12)
59+
- **Coder Version**: (e.g., v2.18.4)
60+
placeholder: |
61+
Run `coder version` to get Coder version
62+
value: |
63+
- Host OS:
64+
- Coder version:
65+
validations:
66+
required: false
67+
68+
- type: dropdown
69+
id: additional_info
70+
attributes:
71+
label: "Additional Context"
72+
description: "Select any applicable options:"
73+
multiple: true
74+
options:
75+
- "The issue occurs consistently"
76+
- "The issue is new (previously worked fine)"
77+
- "The issue happens on multiple deployments"
78+
- "I have tested this on the latest version"

.github/ISSUE_TEMPLATE/config.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
contact_links:
2+
- name: Questions, suggestion or feature requests?
3+
url: https://github.com/coder/coder/discussions/new/choose
4+
about: Our preferred starting point if you have any questions or suggestions about configuration, features or unexpected behavior.
5+
- name: Coder Docs
6+
url: https://coder.com/docs
7+
about: Check our docs.
8+
- name: Coder Discord Community
9+
url: https://discord.gg/coder
10+
about: Get in touch with the Coder developers and community for support.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "Install cosign"
2+
description: |
3+
Cosign Github Action.
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Install cosign
8+
uses: sigstore/cosign-installer@d7d6bc7722e3daa8354c50bcb52f4837da5e9b6a # v3.8.1
9+
with:
10+
cosign-release: "v2.4.3"
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "Install syft"
2+
description: |
3+
Downloads Syft to the Action tool cache and provides a reference.
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Install syft
8+
uses: anchore/sbom-action/download-syft@f325610c9f50a54015d37c8d16cb3b0e2c8f4de0 # v0.18.0
9+
with:
10+
syft-version: "v1.20.0"
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "Setup Go tools"
2+
description: |
3+
Set up tools for `make gen`, `offlinedocs` and Schmoder CI.
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: go install tools
8+
shell: bash
9+
run: |
10+
go install google.golang.org/protobuf/cmd/[email protected]
11+
go install storj.io/drpc/cmd/[email protected]
12+
go install golang.org/x/tools/cmd/[email protected]
13+
go install github.com/mikefarah/yq/[email protected]
14+
go install go.uber.org/mock/[email protected]

.github/actions/setup-go/action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: |
44
inputs:
55
version:
66
description: "The Go version to use."
7-
default: "1.22.8"
7+
default: "1.24.2"
88
runs:
99
using: "composite"
1010
steps:
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Setup ImDisk"
2+
if: runner.os == 'Windows'
3+
description: |
4+
Sets up the ImDisk toolkit for Windows and creates a RAM disk on drive R:.
5+
runs:
6+
using: "composite"
7+
steps:
8+
- name: Download ImDisk
9+
if: runner.os == 'Windows'
10+
shell: bash
11+
run: |
12+
mkdir imdisk
13+
cd imdisk
14+
curl -L -o files.cab https://github.com/coder/imdisk-artifacts/raw/92a17839ebc0ee3e69be019f66b3e9b5d2de4482/files.cab
15+
curl -L -o install.bat https://github.com/coder/imdisk-artifacts/raw/92a17839ebc0ee3e69be019f66b3e9b5d2de4482/install.bat
16+
cd ..
17+
18+
- name: Install ImDisk
19+
shell: cmd
20+
run: |
21+
cd imdisk
22+
install.bat /silent
23+
24+
- name: Create RAM Disk
25+
shell: cmd
26+
run: |
27+
imdisk -a -s 4096M -m R: -p "/fs:ntfs /q /y"

.github/actions/setup-sqlc/action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ runs:
77
- name: Setup sqlc
88
uses: sqlc-dev/setup-sqlc@c0209b9199cd1cce6a14fc27cabcec491b651761 # v4.0.0
99
with:
10-
sqlc-version: "1.25.0"
10+
sqlc-version: "1.27.0"

.github/actions/setup-tf/action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ runs:
77
- name: Install Terraform
88
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
99
with:
10-
terraform_version: 1.9.8
10+
terraform_version: 1.11.4
1111
terraform_wrapper: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: "Download Test Cache"
2+
description: |
3+
Downloads the test cache and outputs today's cache key.
4+
A PR job can use a cache if it was created by its base branch, its current
5+
branch, or the default branch.
6+
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
7+
outputs:
8+
cache-key:
9+
description: "Today's cache key"
10+
value: ${{ steps.vars.outputs.cache-key }}
11+
inputs:
12+
key-prefix:
13+
description: "Prefix for the cache key"
14+
required: true
15+
cache-path:
16+
description: "Path to the cache directory"
17+
required: true
18+
# This path is defined in testutil/cache.go
19+
default: "~/.cache/coderv2-test"
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Get date values and cache key
24+
id: vars
25+
shell: bash
26+
run: |
27+
export YEAR_MONTH=$(date +'%Y-%m')
28+
export PREV_YEAR_MONTH=$(date -d 'last month' +'%Y-%m')
29+
export DAY=$(date +'%d')
30+
echo "year-month=$YEAR_MONTH" >> $GITHUB_OUTPUT
31+
echo "prev-year-month=$PREV_YEAR_MONTH" >> $GITHUB_OUTPUT
32+
echo "cache-key=${{ inputs.key-prefix }}-${YEAR_MONTH}-${DAY}" >> $GITHUB_OUTPUT
33+
34+
# TODO: As a cost optimization, we could remove caches that are older than
35+
# a day or two. By default, depot keeps caches for 14 days, which isn't
36+
# necessary for the test cache.
37+
# https://depot.dev/docs/github-actions/overview#cache-retention-policy
38+
- name: Download test cache
39+
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
40+
with:
41+
path: ${{ inputs.cache-path }}
42+
key: ${{ steps.vars.outputs.cache-key }}
43+
# > If there are multiple partial matches for a restore key, the action returns the most recently created cache.
44+
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
45+
# The second restore key allows non-main branches to use the cache from the previous month.
46+
# This prevents PRs from rebuilding the cache on the first day of the month.
47+
# It also makes sure that once a month, the cache is fully reset.
48+
restore-keys: |
49+
${{ inputs.key-prefix }}-${{ steps.vars.outputs.year-month }}-
50+
${{ github.ref != 'refs/heads/main' && format('{0}-{1}-', inputs.key-prefix, steps.vars.outputs.prev-year-month) || '' }}

0 commit comments

Comments
 (0)