From 9ac6575483ed30aa09f1d37dc01b0bd1404c7333 Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Mon, 14 Apr 2025 22:42:30 +0000 Subject: [PATCH 1/3] feat: support '--socket*' options --- .github/workflows/test.yaml | 11 ++++++++ Makefile | 4 +++ scripts/check_unstaged.sh | 26 +++++++++++++++++++ src/code-server/README.md | 2 ++ src/code-server/devcontainer-feature.json | 10 +++++++ src/code-server/install.sh | 13 +++++++++- .../code-server-socket-with-mode.sh | 18 +++++++++++++ test/code-server/code-server-socket.sh | 17 ++++++++++++ test/code-server/scenarios.json | 17 ++++++++++++ 9 files changed, 117 insertions(+), 1 deletion(-) create mode 100755 scripts/check_unstaged.sh create mode 100644 test/code-server/code-server-socket-with-mode.sh create mode 100644 test/code-server/code-server-socket.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index be1161c..423aa07 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,6 +7,17 @@ on: workflow_dispatch: jobs: + test-docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - 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 diff --git a/Makefile b/Makefile index 144199a..cf7832c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/scripts/check_unstaged.sh b/scripts/check_unstaged.sh new file mode 100755 index 0000000..ee2f6a8 --- /dev/null +++ b/scripts/check_unstaged.sh @@ -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 diff --git a/src/code-server/README.md b/src/code-server/README.md index 700407c..07b51c8 100644 --- a/src/code-server/README.md +++ b/src/code-server/README.md @@ -30,6 +30,8 @@ VS Code in the browser | 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 | | version | The version of code-server to install. If empty, installs the latest version. | string | - | +| 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 | - | | workspace | Path to the workspace or folder to open on startup. Can be a directory or a .code-workspace file. | string | - | diff --git a/src/code-server/devcontainer-feature.json b/src/code-server/devcontainer-feature.json index d0b80d5..ee5dafe 100644 --- a/src/code-server/devcontainer-feature.json +++ b/src/code-server/devcontainer-feature.json @@ -80,6 +80,16 @@ "default": "", "description": "The version of code-server to install. If empty, installs the latest version." }, + "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." + }, "workspace": { "type": "string", "default": "", diff --git a/src/code-server/install.sh b/src/code-server/install.sh index cafe10a..af0b767 100644 --- a/src/code-server/install.sh +++ b/src/code-server/install.sh @@ -67,6 +67,16 @@ 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 @@ -74,8 +84,9 @@ 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 diff --git a/test/code-server/code-server-socket-with-mode.sh b/test/code-server/code-server-socket-with-mode.sh new file mode 100644 index 0000000..1282cf5 --- /dev/null +++ b/test/code-server/code-server-socket-with-mode.sh @@ -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 diff --git a/test/code-server/code-server-socket.sh b/test/code-server/code-server-socket.sh new file mode 100644 index 0000000..8d5aa45 --- /dev/null +++ b/test/code-server/code-server-socket.sh @@ -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 \ No newline at end of file diff --git a/test/code-server/scenarios.json b/test/code-server/scenarios.json index a1fc391..941f4f3 100644 --- a/test/code-server/scenarios.json +++ b/test/code-server/scenarios.json @@ -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" + } + } } } From 5c08b18b28c2162db0c9d0e888eb2aa3a35753cd Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Mon, 14 Apr 2025 22:47:18 +0000 Subject: [PATCH 2/3] chore: install devcontainer cli for action --- .github/workflows/test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 423aa07..612902f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,6 +12,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: "Install latest devcontainer CLI" + run: npm install -g @devcontainers/cli + - name: "Generate documentation" run: make -B docs From 2c3fcb119319c1d21a4a2acbd83fa66622c31ba7 Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Mon, 14 Apr 2025 22:53:55 +0000 Subject: [PATCH 3/3] chore: re-order devcontainer json --- src/code-server/README.md | 2 +- src/code-server/devcontainer-feature.json | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/code-server/README.md b/src/code-server/README.md index 07b51c8..f819a5c 100644 --- a/src/code-server/README.md +++ b/src/code-server/README.md @@ -29,9 +29,9 @@ 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 | -| version | The version of code-server to install. If empty, installs the latest version. | string | - | | 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 | - | diff --git a/src/code-server/devcontainer-feature.json b/src/code-server/devcontainer-feature.json index ee5dafe..f23ffbd 100644 --- a/src/code-server/devcontainer-feature.json +++ b/src/code-server/devcontainer-feature.json @@ -75,11 +75,6 @@ "default": "8080", "description": "The port to bind to for the code-server." }, - "version": { - "type": "string", - "default": "", - "description": "The version of code-server to install. If empty, installs the latest version." - }, "socket": { "type": "string", "default": "", @@ -90,6 +85,11 @@ "default": "", "description": "File mode of the socket when using the socket option." }, + "version": { + "type": "string", + "default": "", + "description": "The version of code-server to install. If empty, installs the latest version." + }, "workspace": { "type": "string", "default": "",