8000 Merge branch 'main' of https://github.com/coder/coder into bq/task-re… · coder/coder@529bb6f · GitHub
[go: up one dir, main page]

Skip to content

Commit 529bb6f

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into bq/task-resize-panel
2 parents d5bed55 + 0f3a1e9 commit 529bb6f

File tree

79 files changed

+2034
-860
lines changed

Some content is hidden

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

79 files changed

+2034
-860
lines changed

.devcontainer/devcontainer.json

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,57 @@
11
{
22
"name": "Development environments on your infrastructure",
33
"image": "codercom/oss-dogfood:latest",
4-
54
"features": {
65
// See all possible options here https://github.com/devcontainers/features/tree/main/src/docker-in-docker
76
"ghcr.io/devcontainers/features/docker-in-docker:2": {
87
"moby": "false"
9-
}
8+
},
9+
"ghcr.io/coder/devcontainer-features/code-server:1": {
10+
"auth": "none",
11+
"port": 13337
12+
},
13+
"./filebrowser": {}
1014
},
1115
// SYS_PTRACE to enable go debugging
1216
"runArgs": ["--cap-add=SYS_PTRACE"],
1317
"customizations": {
1418
"vscode": {
1519
"extensions": ["biomejs.biome"]
20+
},
21+
"coder": {
22+
"apps": [
23+
{
24+
"slug": "cursor",
25+
"displayName": "Cursor Desktop",
26+
"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}",
27+
"external": true,
28+
"icon": "/icon/cursor.svg",
29+
"order": 1
30+
},
31+
{
32+
"slug": "windsurf",
33+
"displayName": "Windsurf Editor",
34+
"url": "windsurf://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}",
35+
"external": true,
36+
"icon": "/icon/windsurf.svg",
37+
"order": 4
38+
},
39+
{
40+
"slug": "zed",
41+
"displayName": "Zed Editor",
42+
"url": "zed://ssh/${localEnv:CODER_WORKSPACE_AGENT_NAME}.${localEnv:CODER_WORKSPACE_NAME}.${localEnv:CODER_WORKSPACE_OWNER_NAME}.coder${containerWorkspaceFolder}",
43+
"external": true,
44+
"icon": "/icon/zed.svg",
45+
"order": 5
46+
}
47+
]
1648
}
17-
}
49+
},
50+
"mounts": [
51+
// Mount the entire home because conditional mounts are not supported.
52+
// See: https://github.com/devcontainers/spec/issues/132
53+
"source=${localEnv:HOME},target=/mnt/home/coder,type=bind,readonly"
54+
],< F438 /div>
55+
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
56+
"postStartCommand": "sudo service docker start"
1857
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"id": "filebrowser",
3+
"version": "0.0.1",
4+
"name": "File Browser",
5+
"description": "A web-based file browser for your development container",
6+
"options": {
7+
"port": {
8+
"type": "string",
9+
"default": "13339",
10+
"description": "The port to run filebrowser on"
11+
},
12+
// "folder": {
13+
// "type": "string",
14+
// "default": "${containerWorkspaceFolder}",
15+
// "description": "The root directory for filebrowser to serve"
16+
// },
17+
"auth": {
18+
"type": "string",
19+
"enum": [
20+
"none",
21+
"password"
22+
],
23+
"default": "none",
24+
"description": "Authentication method (none or password)"
25+
}
26+
},
27+
"entrypoint": "/usr/local/bin/filebrowser-entrypoint",
28+
"dependsOn": {
29+
"ghcr.io/devcontainers/features/common-utils:2": {}
30+
},
31+
"customizations": {
32+
"coder": {
33+
"apps": [
34+
{
35+
"slug": "filebrowser",
10000 36+
"displayName": "File Browser",
37+
"url": "http://localhost:${localEnv:FEATURE_FILEBROWSER_OPTION_PORT:13339}",
38+
"icon": "/icon/filebrowser.svg",
39+
"order": 3,
40+
"subdomain": true,
41+
"healthcheck": {
42+
"url": "http://localhost:${localEnv:FEATURE_FILEBROWSER_OPTION_PORT:13339}/health",
43+
"interval": 5,
44+
"threshold": 6
45+
}
46+
}
47+
]
48+
}
49+
}
50+
}

.devcontainer/filebrowser/install.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
BOLD='\033[0;1m'
6+
7+
printf "%sInstalling filebrowser\n\n" "${BOLD}"
8+
9+
# Check if filebrowser is installed.
10+
if ! command -v filebrowser &>/dev/null; then
11+
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
12+
fi
13+
14+
printf "🥳 Installation complete!\n\n"
15+
16+
# Create run script.
17+
cat >/usr/local/bin/filebrowser-entrypoint <<EOF
18+
#!/bin/bash
19+
20+
printf "🛠️ Configuring filebrowser\n\n"
21+
22+
AUTH="${AUTH}"
23+
PORT="${PORT}"
24+
FOLDER="$(pwd)"
25+
LOG_PATH=/tmp/filebrowser.log
26+
export FB_DATABASE="/tmp/filebrowser.db"
27+
28+
# Check if filebrowser db exists.
29+
if [[ ! -f "\${FB_DATABASE}" ]]; then
30+
filebrowser config init
31+
if [[ "\$AUTH" == "password" ]]; then
32+
filebrowser users add admin admin --perm.admin=true --viewMode=mosaic
33+
fi
34+
fi
35+
36+
# Configure filebrowser.
37+
if [[ "\$AUTH" == "none" ]]; then
38+
filebrowser config set --port="\${PORT}" --auth.method=noauth --root="\${FOLDER}"
39+
else
40+
filebrowser config set --port="\${PORT}" --auth.method=json --root="\${FOLDER}"
41+
fi
42+
43+
set -euo pipefail
44+
45+
printf "👷 Starting filebrowser...\n\n"
46+
printf "📂 Serving \${FOLDER} at http://localhost:\${PORT}\n\n"
47+
48+
filebrowser >>\${LOG_PATH} 2>&1 &
49+
50+
printf "📝 Logs at \${LOG_PATH}\n\n"
51+
EOF
52+
53+
chmod +x /usr/local/bin/filebrowser-entrypoint
54+
55+
printf "✅ File Browser installed!\n\n"
56+
printf "🚀 Run 'filebrowser-entrypoint' to start the service\n\n"

.devcontainer/postCreateCommand.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
install_devcontainer_cli() {
4+
npm install -g @devcontainers/cli
5+
}
6+
7+
install_ssh_config() {
8+
echo "🔑 Installing SSH configuration..."
9+
rsync -a /mnt/home/coder/.ssh/ ~/.ssh/
10+
chmod 0700 ~/.ssh
11+
}
12+
13+
install_git_config() {
14+
echo "📂 Installing Git configuration..."
15+
if [ -f /mnt/home/coder/git/config ]; then
16+
rsync -a /mnt/home/coder/git/ ~/.config/git/
17+
elif [ -d /mnt/home/coder/.gitconfig ]; then
18+
rsync -a /mnt/home/coder/.gitconfig ~/.gitconfig
19+
else
20+
echo "⚠️ Git configuration directory not found."
21+
fi
22+
}
23+
24+
install_dotfiles() {
25+
if [ ! -d /mnt/home/coder/.config/coderv2/dotfiles ]; then
26+
echo "⚠️ Dotfiles directory not found."
27+
return
28+
fi
29+
30+
cd /mnt/home/coder/.config/coderv2/dotfiles || return
31+
for script in install.sh install bootstrap.sh bootstrap script/bootstrap setup.sh setup script/setup; do
32+
if [ -x $script ]; then
33+
echo "📦 Installing dotfiles..."
34+
./$script || {
35+
echo "❌ Error running $script. Please check the script for issues."
36+
return
37+
}
38+
echo "✅ Dotfiles installed successfully."
39+
return
40+
fi
41+
done
42+
echo "⚠️ No install script found in dotfiles directory."
43+
}
44+
45+
personalize() {
46+
# Allow script to continue as Coder dogfood utilizes a hack to
47+
# synchronize startup script execution.
48+
touch /tmp/.coder-startup-script.done
49+
50+
if [ -x /mnt/home/coder/personalize ]; then
51+
echo "🎨 Personalizing environment..."
52+
/mnt/home/coder/personalize
53+
fi
54+
}
55+
56+
install_devcontainer_cli
57+
install_ssh_config
58+
install_dotfiles
59+
personalize

.github/workflows/dogfood.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ jobs:
3535
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3636

3737
- name: Setup Nix
38-
uses: nixbuild/nix-quick-install-action@889f3180bb5f064ee9e3201428d04ae9e41d54ad # v31
38+
uses: nixbuild/nix-quick-install-action@63ca48f939ee3b8d835f4126562537df0fee5b91 # v32
39+
with:
40+
# Pinning to 2.28 here, as Nix gets a "error: [json.exception.type_error.302] type must be array, but is string"
41+
# on version 2.29 and above.
42+
nix_version: "2.28.4"
3943

4044
- uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3
4145
with:

agent/agent.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@ func (a *agent) reportMetadata(ctx context.Context, aAPI proto.DRPCAgentClient26
565565
// channel to synchronize the results and avoid both messy
566566
// mutex logic and overloading the API.
567567
for _, md := range manifest.Metadata {
568-
md := md
569568
// We send the result to the channel in the goroutine to avoid
570569
// sending the same result multiple times. So, we don't care about
571570
// the return values.
@@ -1161,19 +1160,26 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11611160

11621161
var (
11631162
scripts = manifest.Scripts
1164-
scriptRunnerOpts []agentscripts.InitOption
11651163
devcontainerScripts map[uuid.UUID]codersdk.WorkspaceAgentScript
11661164
)
1167-
if a.devcontainers {
1165+
if a.containerAPI != nil {
1166+
// Init the container API with the manifest and client so that
1167+
// we can start accepting requests. The final start of the API
1168+
// happens after the startup scripts have been executed to
1169+
// ensure the presence of required tools. This means we can
1170+
// return existing devcontainers but actual container detection
1171+
// and creation will be deferred.
11681172
a.containerAPI.Init(
1169-
agentcontainers.WithManifestInfo(manifest.OwnerName, manifest.WorkspaceName),
1170-
agentcontainers.WithDevcontainers(manifest.Devcontainers, scripts),
1173+
agentcontainers.WithManifestInfo(manifest.OwnerName, manifest.WorkspaceName, manifest.AgentName),
1174+
agentcontainers.WithDevcontainers(manifest.Devcontainers, manifest.Scripts),
11711175
agentcontainers.WithSubAgentClient(agentcontainers.NewSubAgentClientFromAPI(a.logger, aAPI)),
11721176
)
11731177

1178+
// Since devcontainer are enabled, remove devcontainer scripts
1179+
// from the main scripts list to avoid showing an error.
11741180
scripts, devcontainerScripts = agentcontainers.ExtractDevcontainerScripts(manifest.Devcontainers, scripts)
11751181
}
1176-
err = a.scriptRunner.Init(scripts, aAPI.ScriptCompleted, scriptRunnerOpts...)
1182+
err = a.scriptRunner.Init(scripts, aAPI.ScriptCompleted)
11771183
if err != nil {
11781184
return xerrors.Errorf("init script runner: %w", err)
11791185
}
@@ -1191,9 +1197,15 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11911197
// autostarted devcontainer will be included in this time.
11921198
err := a.scriptRunner.Execute(a.gracefulCtx, agentscripts.ExecuteStartScripts)
11931199

1194-
for _, dc := range manifest.Devcontainers {
1195-
cErr := a.createDevcontainer(ctx, aAPI, dc, devcontainerScripts[dc.ID])
1196-
err = errors.Join(err, cErr)
1200+
if a.containerAPI != nil {
1201+
// Start the container API after the startup scripts have
1202+
// been executed to ensure that the required tools can be
1203+
// installed.
1204+
a.containerAPI.Start()
1205+
for _, dc := range manifest.Devcontainers {
1206+
cErr := a.createDevcontainer(ctx, aAPI, dc, devcontainerScripts[dc.ID])
1207+
err = errors.Join(err, cErr)
1208+
}
11971209
}
11981210

11991211
dur := time.Since(start).Seconds()

agent/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ func TestAgent_DevcontainerRecreate(t *testing.T) {
23722372
// devcontainer, we do it in a goroutine so we can process logs
23732373
// concurrently.
23742374
go func(container codersdk.WorkspaceAgentContainer) {
2375-
_, err := conn.RecreateDevcontainer(ctx, container.ID)
2375+
_, err := conn.RecreateDevcontainer(ctx, devcontainerID.String())
23762376
assert.NoError(t, err, "recreate devcontainer should succeed")
23772377
}(container)
23782378

0 commit comments

Comments
 (0)
0