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

Skip to content

[pull] main from coder:main #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "Development environments on your infrastructure",
"image": "codercom/oss-dogfood:latest",

"features": {
// See all possible options here https://github.com/devcontainers/features/tree/main/src/docker-in-docker
"ghcr.io/devcontainers/features/docker-in-docker:2": {
Expand All @@ -10,13 +9,52 @@
"ghcr.io/coder/devcontainer-features/code-server:1": {
"auth": "none",
"port": 13337
}
},
"./filebrowser": {}
},
// SYS_PTRACE to enable go debugging
"runArgs": ["--cap-add=SYS_PTRACE"],
"runArgs": [
"--cap-add=SYS_PTRACE"
],
"customizations": {
"vscode": {
"extensions": ["biomejs.biome"]
"extensions": [
"biomejs.biome"
]
},
"coder": {
"apps": [
{
"slug": "cursor",
"displayName": "Cursor Desktop",
"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}",
"external": true,
"icon": "/icon/cursor.svg",
"order": 1
},
{
"slug": "windsurf",
"displayName": "Windsurf Editor",
"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}",
"external": true,
"icon": "/icon/windsurf.svg",
"order": 4
},
{
"slug": "zed",
"displayName": "Zed Editor",
"url": "zed://ssh/${localEnv:CODER_WORKSPACE_AGENT_NAME}.${localEnv:CODER_WORKSPACE_NAME}.${localEnv:CODER_WORKSPACE_OWNER_NAME}.coder/${containerWorkspaceFolder}",
"external": true,
"icon": "/icon/zed.svg",
"order": 5
}
]
}
}
},
"mounts": [
// Mount the entire home because conditional mounts are not supported.
// See: https://github.com/devcontainers/spec/issues/132
"source=${localEnv:HOME},target=/mnt/home/coder,type=bind,readonly"
],
"postCreateCommand": "./.devcontainer/postCreateCommand.sh"
}
50 changes: 50 additions & 0 deletions .devcontainer/filebrowser/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"id": "filebrowser",
"version": "0.0.1",
"name": "File Browser",
"description": "A web-based file browser for your development container",
"options": {
"port": {
"type": "string",
"default": "13339",
"description": "The port to run filebrowser on"
},
// "folder": {
// "type": "string",
// "default": "${containerWorkspaceFolder}",
// "description": "The root directory for filebrowser to serve"
// },
"auth": {
"type": "string",
"enum": [
"none",
"password"
],
"default": "none",
"description": "Authentication method (none or password)"
}
},
"entrypoint": "/usr/local/bin/filebrowser-entrypoint",
"dependsOn": {
"ghcr.io/devcontainers/features/common-utils:2": {}
},
"customizations": {
"coder": {
"apps": [
{
"slug": "filebrowser",
"displayName": "File Browser",
"url": "http://localhost:${localEnv:FEATURE_FILEBROWSER_OPTION_PORT:13339}",
"icon": "/icon/filebrowser.svg",
"order": 3,
"subdomain": true,
"healthcheck": {
"url": "http://localhost:${localEnv:FEATURE_FILEBROWSER_OPTION_PORT:13339}/health",
"interval": 5,
"threshold": 6
}
}
]
}
}
}
56 changes: 56 additions & 0 deletions .devcontainer/filebrowser/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

set -euo pipefail

BOLD='\033[0;1m'

printf "%sInstalling filebrowser\n\n" "${BOLD}"

# Check if filebrowser is installed.
if ! command -v filebrowser &>/dev/null; then
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
fi

printf "πŸ₯³ Installation complete!\n\n"

# Create run script.
cat >/usr/local/bin/filebrowser-entrypoint <<EOF
#!/bin/bash

printf "πŸ› οΈ Configuring filebrowser\n\n"

AUTH="${AUTH}"
PORT="${PORT}"
FOLDER="$(pwd)"
LOG_PATH=/tmp/filebrowser.log
export FB_DATABASE="/tmp/filebrowser.db"

# Check if filebrowser db exists.
if [[ ! -f "\${FB_DATABASE}" ]]; then
filebrowser config init
if [[ "\$AUTH" == "password" ]]; then
filebrowser users add admin admin --perm.admin=true --viewMode=mosaic
fi
fi

# Configure filebrowser.
if [[ "\$AUTH" == "none" ]]; then
filebrowser config set --port="\${PORT}" --auth.method=noauth --root="\${FOLDER}"
else
filebrowser config set --port="\${PORT}" --auth.method=json --root="\${FOLDER}"
fi

set -euo pipefail

printf "πŸ‘· Starting filebrowser...\n\n"
printf "πŸ“‚ Serving \${FOLDER} at http://localhost:\${PORT}\n\n"

filebrowser >>\${LOG_PATH} 2>&1 &

printf "πŸ“ Logs at \${LOG_PATH}\n\n"
EOF

chmod +x /usr/local/bin/filebrowser-entrypoint

printf "βœ… File Browser installed!\n\n"
printf "πŸš€ Run 'filebrowser-entrypoint' to start the service\n\n"
54 changes: 54 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

install_ssh_config() {
echo "πŸ”‘ Installing SSH configuration..."
rsync -a /mnt/home/coder/.ssh/ ~/.ssh/
chmod 0700 ~/.ssh
}

install_git_config() {
echo "πŸ“‚ Installing Git configuration..."
if [ -f /mnt/home/coder/git/config ]; then
rsync -a /mnt/home/coder/git/ ~/.config/git/
elif [ -d /mnt/home/coder/.gitconfig ]; then
rsync -a /mnt/home/coder/.gitconfig ~/.gitconfig
else
echo "⚠️ Git configuration directory not found."
fi
}

install_dotfiles() {
if [ ! -d /mnt/home/coder/.config/coderv2/dotfiles ]; then
echo "⚠️ Dotfiles directory not found."
return
fi

cd /mnt/home/coder/.config/coderv2/dotfiles || return
for script in install.sh install bootstrap.sh bootstrap script/bootstrap setup.sh setup script/setup; do
if [ -x $script ]; then
echo "πŸ“¦ Installing dotfiles..."
./$script || {
echo "❌ Error running $script. Please check the script for issues."
return
}
echo "βœ… Dotfiles installed successfully."
return
fi
done
echo "⚠️ No install script found in dotfiles directory."
}

personalize() {
# Allow script to continue as Coder dogfood utilizes a hack to
# synchronize startup script execution.
touch /tmp/.coder-startup-script.done

if [ -x /mnt/home/coder/personalize ]; then
echo "🎨 Personalizing environment..."
/mnt/home/coder/personalize
fi
}

install_ssh_config
install_dotfiles
personalize
6 changes: 5 additions & 1 deletion .github/workflows/dogfood.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

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

- uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # v6.1.3
with:
Expand Down
1 change: 0 additions & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ func (a *agent) reportMetadata(ctx context.Context, aAPI proto.DRPCAgentClient26
// channel to synchronize the results and avoid both messy
// mutex logic and overloading the API.
for _, md := range manifest.Metadata {
md := md
// We send the result to the channel in the goroutine to avoid
// sending the same result multiple times. So, we don't care about
// the return values.
Expand Down
2 changes: 1 addition & 1 deletion agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,7 @@ func TestAgent_DevcontainerRecreate(t *testing.T) {
// devcontainer, we do it in a goroutine so we can process logs
// concurrently.
go func(container codersdk.WorkspaceAgentContainer) {
_, err := conn.RecreateDevcontainer(ctx, container.ID)
_, err := conn.RecreateDevcontainer(ctx, devcontainerID.String())
assert.NoError(t, err, "recreate devcontainer should succeed")
}(container)

Expand Down
10 changes: 8 additions & 2 deletions agent/agentcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,11 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
return xerrors.Errorf("set agent binary executable: %w", err)
}

// Make sure the agent binary is owned by a valid user so we can run it.
if _, err := api.ccli.ExecAs(ctx, container.ID, "root", "/bin/sh", "-c", fmt.Sprintf("chown $(id -u):$(id -g) %s", coderPathInsideContainer)); err != nil {
return xerrors.Errorf("set agent binary ownership: %w", err)
}

// Attempt to add CAP_NET_ADMIN to the binary to improve network
// performance (optional, allow to fail). See `bootstrap_linux.sh`.
// TODO(mafredri): Disable for now until we can figure out why this
Expand Down Expand Up @@ -1479,15 +1484,16 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
originalName := subAgentConfig.Name

for attempt := 1; attempt <= maxAttemptsToNameAgent; attempt++ {
if proc.agent, err = client.Create(ctx, subAgentConfig); err == nil {
agent, err := client.Create(ctx, subAgentConfig)
if err == nil {
proc.agent = agent // Only reassign on success.
if api.usingWorkspaceFolderName[dc.WorkspaceFolder] {
api.devcontainerNames[dc.Name] = true
delete(api.usingWorkspaceFolderName, dc.WorkspaceFolder)
}

break
}

// NOTE(DanielleMaywood):
// Ordinarily we'd use `errors.As` here, but it didn't appear to work. Not
// sure if this is because of the communication protocol? Instead I've opted
Expand Down
6 changes: 6 additions & 0 deletions agent/agentcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,7 @@ func TestAPI(t *testing.T) {
mCCLI.EXPECT().ExecAs(gomock.Any(), "test-container-id", "root", "mkdir", "-p", "/.coder-agent").Return(nil, nil),
mCCLI.EXPECT().Copy(gomock.Any(), "test-container-id", coderBin, "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), "test-container-id", "root", "chmod", "0755", "/.coder-agent", "/.coder-agent/coder").Return(nil, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), "test-container-id", "root", "/bin/sh", "-c", "chown $(id -u):$(id -g) /.coder-agent/coder").Return(nil, nil),
)

mClock.Set(time.Now()).MustWait(ctx)
Expand Down Expand Up @@ -1480,6 +1481,7 @@ func TestAPI(t *testing.T) {
mCCLI.EXPECT().ExecAs(gomock.Any(), "test-container-id", "root", "mkdir", "-p", "/.coder-agent").Return(nil, nil),
mCCLI.EXPECT().Copy(gomock.Any(), "test-container-id", coderBin, "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), "test-container-id", "root", "chmod", "0755", "/.coder-agent", "/.coder-agent/coder").Return(nil, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), "test-container-id", "root", "/bin/sh", "-c", "chown $(id -u):$(id -g) /.coder-agent/coder").Return(nil, nil),
)

// Verify that the agent has started.
Expand Down Expand Up @@ -1540,6 +1542,7 @@ func TestAPI(t *testing.T) {
mCCLI.EXPECT().ExecAs(gomock.Any(), "new-test-container-id", "root", "mkdir", "-p", "/.coder-agent").Return(nil, nil),
mCCLI.EXPECT().Copy(gomock.Any(), "new-test-container-id", coderBin, "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), "new-test-container-id", "root", "chmod", "0755", "/.coder-agent", "/.coder-agent/coder").Return(nil, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), "new-test-container-id", "root", "/bin/sh", "-c", "chown $(id -u):$(id -g) /.coder-agent/coder").Return(nil, nil),
)

fakeDCCLI.readConfig.MergedConfiguration.Customizations.Coder = []agentcontainers.CoderCustomization{
Expand Down Expand Up @@ -1941,6 +1944,7 @@ func TestAPI(t *testing.T) {
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "mkdir", "-p", "/.coder-agent").Return(nil, nil),
mCCLI.EXPECT().Copy(gomock.Any(), testContainer.ID, coderBin, "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "chmod", "0755", "/.coder-agent", "/.coder-agent/coder").Return(nil, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "/bin/sh", "-c", "chown $(id -u):$(id -g) /.coder-agent/coder").Return(nil, nil),
)

mClock.Set(time.Now()).MustWait(ctx)
Expand Down Expand Up @@ -2034,6 +2038,7 @@ func TestAPI(t *testing.T) {
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "mkdir", "-p", "/.coder-agent").Return(nil, nil),
mCCLI.EXPECT().Copy(gomock.Any(), testContainer.ID, coderBin, "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "chmod", "0755", "/.coder-agent", "/.coder-agent/coder").Return(nil, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "/bin/sh", "-c", "chown $(id -u):$(id -g) /.coder-agent/coder").Return(nil, nil),
)

mClock.Set(time.Now()).MustWait(ctx)
Expand Down Expand Up @@ -2138,6 +2143,7 @@ func TestAPI(t *testing.T) {
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "mkdir", "-p", "/.coder-agent").Return(nil, nil),
mCCLI.EXPECT().Copy(gomock.Any(), testContainer.ID, coderBin, "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "chmod", "0755", "/.coder-agent", "/.coder-agent/coder").Return(nil, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "/bin/sh", "-c", "chown $(id -u):$(id -g) /.coder-agent/coder").Return(nil, nil),
)

mClock.Set(time.Now()).MustWait(ctx)
Expand Down
2 changes: 1 addition & 1 deletion agent/agentcontainers/devcontainercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (l *devcontainerCLILogWriter) Write(p []byte) (n int, err error) {
}
if logLine.Level >= 3 {
l.logger.Info(l.ctx, "@devcontainer/cli", slog.F("line", string(line)))
_, _ = l.writer.Write([]byte(logLine.Text + "\n"))
_, _ = l.writer.Write([]byte(strings.TrimSpace(logLine.Text) + "\n"))
continue
}
// If we've successfully parsed the final log line, it will successfully parse
Expand Down
5 changes: 5 additions & 0 deletions agent/agentcontainers/devcontainercli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -343,6 +344,10 @@ func TestDevcontainerCLI_WithOutput(t *testing.T) {
t.Run("Up", func(t *testing.T) {
t.Parallel()

if runtime.GOOS == "windows" {
t.Skip("Windows uses CRLF line endings, golden file is LF")
}

// Buffers to capture stdout and stderr.
outBuf := &bytes.Buffer{}
errBuf := &bytes.Buffer{}
Expand Down
Loading