Skip to content

Enhance devcontainer.json handling with support for extensions, features, settings, and lifecycle commands #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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aliraza556
Copy link

Summary

This PR improves the handling of devcontainer.json configuration in workspace creation to provide full compatibility with GitHub Codespaces features. The implementation now properly detects, extracts, and processes all major elements from devcontainer.json files.

Changes

  • Added comprehensive parsing of devcontainer.json to extract:

    • VS Code extensions (both direct and customizations.vscode formats)
    • VS Code settings
    • Features specification
    • Port forwarding configuration
    • Environment variables (containerEnv and remoteEnv)
    • User configuration (remoteUser and containerUser)
    • Lifecycle commands (postCreateCommand and postStartCommand)
  • Created robust helper scripts:

    • install-extensions.sh with retry logic for reliable extension installation
    • setup-env.sh to properly handle environment variables
    • run-lifecycle.sh to manage lifecycle commands
  • Improved Docker installation handling for different Linux distributions

    • Automatically detects OS and installs Docker appropriately
    • Provides fallback mechanisms for reliable installation
  • Enhanced file handling with proper copying of all .devcontainer directory files

  • Added detailed logging throughout the process for better debugging

Closes: #3

Issue ticket number and link:

Bounty Link:

@aliraza556
Copy link
Author

@gonzaloaune Please review this PR.

@gonzaloaune
Copy link
Collaborator

getting this in the logs upon starting a workspace:

➜  workspace_controller git:(aliraza556-fix/devcontainer-json-support-and-port-handling) ✗ kubectl logs -n $WORKSPACE $POD -c code-server

/bin/sh: 1: [/bin/bash,: not found

git commit -m "Fix code-server container startup error with ENTRYPOINT format
"
git commit -m "Fix code-server container startup error with ENTRYPOINT format
"
@aliraza556
Copy link
Author

@gonzaloaune Done.

@gonzaloaune
Copy link
Collaborator

@aliraza556 I don't think the solution is to find a random port but why is the 8443 used if it's supposed to be used for the code-server?

@aliraza556
Copy link
Author

@gonzaloaune Please review again:

Fixed the port 8443 issue as requested. Instead of looking for alternative ports, the system now properly ensures code-server always uses port 8443 by terminating any conflicting processes. This matches our Service and Ingress configurations, resolving the connection issues.

@gonzaloaune
Copy link
Collaborator

@aliraza556 still having problems, here are my logs:

➜  workspace_controller git:(main) ✗ kubectl logs -n $WORKSPACE $POD -c code-server

No features file found, skipping feature installation
Applying user configuration from devcontainer.json
Remote user set to: root
Installing extensions from devcontainer.json...
Installing extension: stakwork.staklink
[2025-06-03T08:00:31.643Z] info  Wrote default config file to /root/.config/code-server/config.yaml
Installing extensions...
Installing extension 'stakwork.staklink'...
Extension 'stakwork.staklink' v0.0.54 was successfully installed.
Successfully installed: stakwork.staklink
Installing extension: golang.go
Installing extensions...
Extension 'golang.go' v0.46.1 is already installed. Use '--force' option to update to latest version or provide '@<version>' to install a specific version, for example: '[email protected]'.
Successfully installed: golang.go
Installing extension: esbenp.prettier-vscode
Installing extensions...
Extension 'esbenp.prettier-vscode' v11.0.0 is already installed. Use '--force' option to update to latest version or provide '@<version>' to install a specific version, for example: '[email protected]'.
Successfully installed: esbenp.prettier-vscode
=== Extension Installation Report ===
Installed extensions:
esbenp.prettier-vscode
golang.go
stakwork.staklink
=========================================
Finished installing extensions
Running lifecycle commands
Running /workspaces/post-create-command.sh...
Running in context of repository: sphinx-tribes
Running command: bash sphinx-tribes/.devcontainer/setup.sh
Could not find script at any expected location, running as command
bash: sphinx-tribes/.devcontainer/setup.sh: No such file or directory
WARNING: /workspaces/post-create-command.sh failed with exit code 127
Running /workspaces/post-start-command.sh...
Running in context of repository: sphinx-tribes
Running command: bash sphinx-tribes/.devcontainer/ports.sh
Could not find script at any expected location, running as command
bash: sphinx-tribes/.devcontainer/ports.sh: No such file or directory
WARNING: /workspaces/post-start-command.sh failed with exit code 127
Applying VS Code settings...
Setting up port forwarding...
13008
5432
5002
15552
Lifecycle commands completed
Stopping any existing code-server processes...
Terminated

as I said before, we shoudl find out the cause and not write code to circumvent the problem, 8443 should be the dedicated port for code-server, why is another process running there?

Also how are you testing this? because you should be facing the same issues I'm facing.

@gonzaloaune
Copy link
Collaborator

@aliraza556 I found the issue with the port, the nginx-ingress is using it for webhooks so it can;t be used (may have been a recent update to that pod)

However I can't see the extensions installed even though the logs says they're installed, but upon checking the code-server they're not there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Review codespace creation with devcontainer.json
2 participants