Skip to content

fix: broken implementation and tests #8

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 5 commits into from
Apr 16, 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
1 change: 1 addition & 0 deletions src/code-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ VS Code in the browser
| disableWorkspaceTrust | Disable Workspace Trust feature. This only affects the current session. | boolean | false |
| 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 |
| logFile | Path to a file to send stdout and stderr logs to from code-server. | string | /tmp/code-server.log |
| 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 | - |
Expand Down
5 changes: 5 additions & 0 deletions src/code-server/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
"default": "127.0.0.1",
"description": "The address to bind to for the code-server. Use '0.0.0.0' to listen on all interfaces."
},
"logFile": {
"type": "string",
"default": "/tmp/code-server.log",
"description": "Path to a file to send stdout and stderr logs to from code-server."
},
"port": {
"type": "string",
"default": "8080",
Expand Down
45 changes: 22 additions & 23 deletions src/code-server/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,69 @@ if [[ -n $WORKSPACE ]]; then
CODE_SERVER_WORKSPACE="$WORKSPACE"
fi

DISABLE_FLAGS=()
FLAGS=()
FLAGS+=(--auth "$AUTH")
FLAGS+=(--bind-addr "$HOST:$PORT")

if [[ "$DISABLEFILEDOWNLOADS" == "true" ]]; then
DISABLE_FLAGS+=(--disable-file-downloads)
FLAGS+=(--disable-file-downloads)
fi

if [[ "$DISABLEFILEUPLOADS" == "true" ]]; then
DISABLE_FLAGS+=(--disable-file-uploads)
FLAGS+=(--disable-file-uploads)
fi

if [[ "$DISABLEGETTINGSTARTEDOVERRIDE" == "true" ]]; then
DISABLE_FLAGS+=(--disable-getting-started-override)
FLAGS+=(--disable-getting-started-override)
fi

if [[ "$DISABLEPROXY" == "true" ]]; then
DISABLE_FLAGS+=(--disable-proxy)
FLAGS+=(--disable-proxy)
fi

if [[ "$DISABLETELEMETRY" == "true" ]]; then
DISABLE_FLAGS+=(--disable-telemetry)
FLAGS+=(--disable-telemetry)
fi

if [[ "$DISABLEUPDATECHECK" == "true" ]]; then
DISABLE_FLAGS+=(--disable-update-check)
FLAGS+=(--disable-update-check)
fi

if [[ "$DISABLEWORKSPACETRUST" == "true" ]]; then
DISABLE_FLAGS+=(--disable-workspace-trust)
FLAGS+=(--disable-workspace-trust)
fi

CERT_FLAGS=()

if [[ -n "$CERT" ]]; then
CERT_FLAGS+=(--cert "$CERT")
FLAGS+=(--cert "$CERT")
fi

if [[ -n "$CERTHOST" ]]; then
CERT_FLAGS+=(--cert-host "$CERTHOST")
FLAGS+=(--cert-host "$CERTHOST")
fi

if [[ -n "$CERTKEY" ]]; then
CERT_FLAGS+=(--cert-key "$CERTKEY")
FLAGS+=(--cert-key "$CERTKEY")
fi

SOCKET_FLAGS=()

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

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

cat > /usr/local/bin/code-server-entrypoint \
<< EOF
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)
if [[ \$(whoami) != "$_REMOTE_USER" ]]; then
exec su $_REMOTE_USER -c /usr/local/bin/code-server-entrypoint
fi

$(declare -p FLAGS)

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

chmod +x /usr/local/bin/code-server-entrypoint
2 changes: 1 addition & 1 deletion test/code-server/code-server-auth-none.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 auth" grep $'\'code-server.* --auth "none" .*\'' < /usr/local/bin/code-server-entrypoint
check "code-server auth" grep '"--auth".*"none"' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
2 changes: 1 addition & 1 deletion test/code-server/code-server-auth-password.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 auth" grep $'\'code-server.* --auth "password" .*\'' < /usr/local/bin/code-server-entrypoint
check "code-server auth" grep '"--auth".*"password"' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
6 changes: 2 additions & 4 deletions test/code-server/code-server-cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ 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 cert" grep '"--cert".*"/path/to/cert.pem"' < /usr/local/bin/code-server-entrypoint
check "code-server cert-key" grep '"--cert-key".*"/path/to/key.pem"' < /usr/local/bin/code-server-entrypoint
check "code-server cert" grep '"--cert".*"/home/vscode/cert.pem"' < /usr/local/bin/code-server-entrypoint
check "code-server cert-key" grep '"--cert-key".*"/home/vscode/key.pem"' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
3 changes: 3 additions & 0 deletions test/code-server/code-server-cert/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mcr.microsoft.com/devcontainers/base:ubuntu

RUN su vscode -c "openssl req -x509 -newkey rsa:4096 -keyout /home/vscode/key.pem -out /home/vscode/cert.pem -sha256 -days 1 -nodes -subj \"/C=XX/ST=Texas/L=Austin/O=Coder/OU=Engineering/CN=dev.coder.com\""
16 changes: 16 additions & 0 deletions test/code-server/code-server-log-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

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

# 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 "@0.0.0.0:8080"

check "code-server log-file" test -f /tmp/code-server-log-file.log
check "code-server log-file content" grep "HTTP server listening on http://127.0.0.1:8080/" < /tmp/code-server-log-file.log

# Report results
reportResults
7 changes: 2 additions & 5 deletions test/code-server/code-server-socket-with-mode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ 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
check "code-server socket" test -S /tmp/code-server.sock
check "code-server socket-mode" grep '0777' <<< $(stat /tmp/code-server.sock)

# Report results
reportResults
8 changes: 3 additions & 5 deletions test/code-server/code-server-socket.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ 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" test -S /tmp/code-server.sock
check "code-server socket-mode" grep '0775' <<< $(stat /tmp/code-server.sock)

# Report results
reportResults
reportResults
2 changes: 1 addition & 1 deletion test/code-server/code-server-workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 workspace" grep $'\'code-server.*"/home"\'' < /usr/local/bin/code-server-entrypoint
check "code-server workspace" grep $'/home' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
16 changes: 13 additions & 3 deletions test/code-server/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@
}
},
"code-server-cert": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"code-server": {
"cert": "/path/to/cert.pem",
"certKey": "/path/to/key.pem"
"cert": "/home/vscode/cert.pem",
"certKey": "/home/vscode/key.pem"
}
}
},
Expand Down Expand Up @@ -158,5 +160,13 @@
"socketMode": "777"
}
}
},
"code-server-log-file": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"code-server": {
"logFile": "/tmp/code-server-log-file.log"
}
}
}
}
3 changes: 3 additions & 0 deletions test/code-server/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ 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 log-file" test -f /tmp/code-server.log
check "code-server log-file content" grep "HTTP server listening on http://127.0.0.1:8080/" < /tmp/code-server.log

# Report results
reportResults