Skip to content

feat: allow customizing workspace directory #2

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 4 commits into from
Apr 10, 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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: test
test:
devcontainer features test
6 changes: 5 additions & 1 deletion src/code-server/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
"extensions": {
"type": "string",
"default": ""
}
},
"workspace": {
"type": "string",
"default": ""
}
},
"entrypoint": "/usr/local/bin/code-server-entrypoint",
"dependsOn": {
Expand Down
10 changes: 8 additions & 2 deletions src/code-server/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

CODE_SERVER_INSTALL_ARGS=""

if [ -n "$VERSION" ]; then
if [[ -n $VERSION ]]; then
CODE_SERVER_INSTALL_ARGS="$CODE_SERVER_INSTALL_ARGS --version=\"$VERSION\""
fi

Expand All @@ -17,12 +17,18 @@ do
code-server --install-extension "$extension"
done

CODE_SERVER_WORKSPACE="$_REMOTE_USER_HOME"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$_REMOTE_USER_HOME should always be set


if [[ -n $WORKSPACE ]]; then
CODE_SERVER_WORKSPACE="$WORKSPACE"
fi

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

su $_REMOTE_USER -c 'code-server --bind-addr "$HOST:$PORT" \$ARGS'
su $_REMOTE_USER -c 'code-server --bind-addr "$HOST:$PORT" "$CODE_SERVER_WORKSPACE"'
EOF

chmod +x /usr/local/bin/code-server-entrypoint
15 changes: 15 additions & 0 deletions test/code-server/code-server-workspace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/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 "@127.0.0.1:8080"

check "code-server workspace" grep $'\'code-server.*"/home"\'' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
8 changes: 8 additions & 0 deletions test/code-server/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@
"version": "4.98.0"
}
}
},
"code-server-workspace": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"code-server": {
"workspace": "/home"
}
}
}
}