Skip to content

feat: support --socket* options #7

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 3 commits into from
Apr 15, 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
14 changes: 14 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ on:
workflow_dispatch:

jobs:
test-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: "Install latest devcontainer CLI"
run: npm install -g @devcontainers/cli

- name: "Generate documentation"
run: make -B docs

- name: "Check for unstaged"
run: ./scripts/check_unstaged.sh

test-autogenerated:
runs-on: ubuntu-latest
continue-on-error: true
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.PHONY: test
test:
devcontainer features test

.PHONY: docs
docs: src/code-server/README.md
cd src && devcontainer features generate-docs -n coder/devcontainer-features
26 changes: 26 additions & 0 deletions scripts/check_unstaged.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -euo pipefail

FILES="$(git ls-files --other --modified --exclude-standard)"
if [[ "$FILES" != "" ]]; then
mapfile -t files <<<"$FILES"

echo
echo "The following files contain unstaged changes:"
echo
for file in "${files[@]}"; do
echo " - $file"
done

echo
echo "These are the changes:"
echo
for file in "${files[@]}"; do
git --no-pager diff "$file" 1>&2
done

echo
echo "ERROR: Unstaged changes, see above for details."
exit 1
fi
2 changes: 2 additions & 0 deletions src/code-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ VS Code in the browser
| extensions | Comma-separated list of VS Code extensions to install. Format: 'publisher.extension[@version]' (e.g., 'ms-python.python,ms-azuretools.vscode-docker'). | string | - |
| host | The address to bind to for the code-server. Use '0.0.0.0' to listen on all interfaces. | string | 127.0.0.1 |
| port | The port to bind to for the code-server. | string | 8080 |
| socket | Path to a socket. When specified, host and port will be ignored. | string | - |
| socketMode | File mode of the socket when using the socket option. | string | - |
| version | The version of code-server to install. If empty, installs the latest version. | string | - |
| workspace | Path to the workspace or folder to open on startup. Can be a directory or a .code-workspace file. | string | - |

Expand Down
10 changes: 10 additions & 0 deletions src/code-server/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@
"default": "8080",
"description": "The port to bind to for the code-server."
},
"socket": {
"type": "string",
"default": "",
"description": "Path to a socket. When specified, host and port will be ignored."
},
"socketMode": {
"type": "string",
"default": "",
"description": "File mode of the socket when using the socket option."
},
"version": {
"type": "string",
"default": "",
Expand Down
13 changes: 12 additions & 1 deletion src/code-server/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,26 @@ if [[ -n "$CERTKEY" ]]; then
CERT_FLAGS+=(--cert-key "$CERTKEY")
fi

SOCKET_FLAGS=()

if [[ -n "$SOCKET" ]]; then
SOCKET_FLAGS+=(--socket "$SOCKET")
fi

if [[ -n "$SOCKETMODE" ]]; then
SOCKET_FLAGS+=(--socket-mode "$SOCKETMODE")
fi

cat > /usr/local/bin/code-server-entrypoint \
<< EOF
#!/usr/bin/env bash
set -e

$(declare -p DISABLE_FLAGS)
$(declare -p CERT_FLAGS)
$(declare -p SOCKET_FLAGS)

su $_REMOTE_USER -c 'code-server --auth "$AUTH" --bind-addr "$HOST:$PORT" "\${DISABLE_FLAGS[@]}" "\${CERT_FLAGS[@]}" "$CODE_SERVER_WORKSPACE"'
su $_REMOTE_USER -c 'code-server --auth "$AUTH" --bind-addr "$HOST:$PORT" "\${DISABLE_FLAGS[@]}" "\${CERT_FLAGS[@]}" "\${SOCKET_FLAGS[@]}" "$CODE_SERVER_WORKSPACE"'
EOF

chmod +x /usr/local/bin/code-server-entrypoint
18 changes: 18 additions & 0 deletions test/code-server/code-server-socket-with-mode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

cat /usr/local/bin/code-server-entrypoint

# Feature-specific tests
check "code-server version" code-server --version
check "code-server running" pgrep -f 'code-server/lib/node.*/code-server'
check "code-server listening" lsof -i "@127.0.0.1:8080"

check "code-server socket" grep '"--socket".*"/tmp/code-server.sock"' < /usr/local/bin/code-server-entrypoint
check "code-server socket-mode" grep '"--socket-mode".*"777"' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
17 changes: 17 additions & 0 deletions test/code-server/code-server-socket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

cat /usr/local/bin/code-server-entrypoint

# Feature-specific tests
check "code-server version" code-server --version
check "code-server running" pgrep -f 'code-server/lib/node.*/code-server'
check "code-server listening" lsof -i "@127.0.0.1:8080"

check "code-server socket" grep '"--socket".*"/tmp/code-server.sock"' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
17 changes: 17 additions & 0 deletions test/code-server/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,22 @@
"certHost": "coder.com"
}
}
},
"code-server-socket": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"code-server": {
"socket": "/tmp/code-server.sock"
}
}
},
"code-server-socket-with-mode": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"code-server": {
"socket": "/tmp/code-server.sock",
"socketMode": "777"
}
}
}
}