diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index be1161c..612902f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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 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..f819a5c 100644 --- a/src/code-server/README.md +++ b/src/code-server/README.md @@ -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 | - | diff --git a/src/code-server/devcontainer-feature.json b/src/code-server/devcontainer-feature.json index d0b80d5..f23ffbd 100644 --- a/src/code-server/devcontainer-feature.json +++ b/src/code-server/devcontainer-feature.json @@ -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": "", 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" + } + } } }