-
Notifications
You must be signed in to change notification settings - Fork 47
feat(devcontainer): improve performance and reliability of devcontainer launch #472
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
base: main
Are you sure you want to change the base?
Changes from all commits
d0fdda4
73add7d
c9992cf
d1e7095
8174a53
8414bbd
2323b86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,30 @@ | ||
| { | ||
| "name": "HVE Core - Markdown Editing", | ||
| "image": "mcr.microsoft.com/devcontainers/base:ubuntu", | ||
| // Rename the mount to /workspace for a predictable workspace paths in our scripts. | ||
| // The source path might also contain special characters, so it needs escaped double quotes. | ||
| "workspaceMount": "\"source=${localWorkspaceFolder}\",target=/workspace,type=bind", | ||
| "workspaceFolder": "/workspace", | ||
| "mounts": [ | ||
| // Put GitHub local user data in a volume | ||
| { | ||
| "type": "volume", | ||
| "source": "${devcontainerId}-userconfig", | ||
| "target": "/home/vscode/.config" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this just be the /home/vscode/.config/gh folder? |
||
| }, | ||
| // Put node modules into volume for better performance | ||
| { | ||
| "type": "volume", | ||
| "source": "${devcontainerId}-nodemodules", | ||
| "target": "/workspace/node_modules" | ||
| } | ||
| ], | ||
| "features": { | ||
| "ghcr.io/devcontainers/features/node:1": { | ||
| "version": "lts" | ||
| }, | ||
| "ghcr.io/devcontainers/features/python:1": { | ||
| "version": "3.11" | ||
| }, | ||
| "ghcr.io/devcontainers/features/git:1": {}, | ||
| "ghcr.io/devcontainers/features/github-cli:1": {}, | ||
| "ghcr.io/devcontainers/features/azure-cli:1": {}, | ||
| "ghcr.io/devcontainers/features/powershell:1": {} | ||
| }, | ||
| "customizations": { | ||
|
|
@@ -23,9 +37,21 @@ | |
| "bierner.markdown-mermaid", | ||
| "bpruitt-goddard.mermaid-markdown-syntax-highlighting", | ||
| "github.vscode-pull-request-github" | ||
| ] | ||
| ], | ||
| "settings": { | ||
| // Prevent extensions from stealing focus, see microsoft/vscode#205225 | ||
| "workbench.view.showQuietly": { | ||
| "workbench.panel.output": true | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| // This is to ensure support for config includes is properly handled, see microsoft/vscode-remote-release#2084 | ||
| "initializeCommand": { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. initializeCommand is exporting every global config key, not just identity fields but you only need: user.name, user.email, user.signingkey, commit.gpgsign, right? |
||
| "extractGitGlobals": "(git config -l --global --include || true) > .gitconfig.global", | ||
| "extractGitLocals": "(git config -l --local --include || true) > .gitconfig.local" | ||
| }, | ||
| "postAttachCommand": "/bin/bash .devcontainer/scripts/post-attach.sh", | ||
| "onCreateCommand": "bash .devcontainer/scripts/on-create.sh", | ||
| "postCreateCommand": "bash .devcontainer/scripts/post-create.sh", | ||
| "remoteUser": "vscode" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/usr/bin/env bash | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you set the SPDX and license header? |
||
| set -euo pipefail | ||
|
|
||
|
Comment on lines
+1
to
+3
|
||
| # devcontainers copy your local gitconfig but do not parse conditional includes. | ||
| # This re-configures the devcontainer git identities based on the prior exported | ||
| # global and local git configurations *after* parsing host includes. See also: | ||
| # https://github.com/microsoft/vscode-remote-release/issues/2084#issuecomment-2289987894 | ||
| copy_user_gitconfig() { | ||
| for conf in .gitconfig.global .gitconfig.local; do | ||
| if [[ -f "$conf" ]]; then | ||
| echo "*** Parsing ${conf##.gitconfig.} Git configuration export" | ||
| while IFS='=' read -r key value; do | ||
| local key value | ||
| case "$key" in | ||
| user.name | user.email | user.signingkey | commit.gpgsign) | ||
| echo "Set Git config ${key}=${value}" | ||
| git config --global "$key" "$value" | ||
|
Comment on lines
+12
to
+17
|
||
| ;; | ||
| esac | ||
| done < "$conf" | ||
| rm -f "${conf}" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| # Main execution path | ||
|
|
||
| copy_user_gitconfig | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,37 @@ | |
|
|
||
| set -euo pipefail | ||
|
|
||
| main() { | ||
| # Volume ownership is not set automatically due to a bug: | ||
| # https://github.com/microsoft/vscode-remote-release/issues/9931 | ||
| # | ||
| # IMPORTANT: workaround requires Docker base image to have password-less sudo. | ||
| fix_volume_ownership() { | ||
| local volume_path="$1" | ||
|
|
||
| if [[ ! -d "$volume_path" ]]; then | ||
| echo "ERROR: the volume path provided '$volume_path' does not exist." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Setting volume ownership for $volume_path" | ||
|
Comment on lines
+20
to
+22
|
||
| sudo chown "$USER:$USER" "$volume_path" | ||
| } | ||
|
|
||
| fix_volume_ownerships() { | ||
| echo "Applying volume ownership workaround (see microsoft/vscode-remote-release#9931)..." | ||
| fix_volume_ownership "/home/${USER}/.config" | ||
| fix_volume_ownership "/workspace/node_modules" | ||
| } | ||
|
|
||
| npm_install() { | ||
| echo "Installing NPM dependencies..." | ||
|
Comment on lines
+30
to
33
|
||
| npm ci | ||
| echo "NPM dependencies installed successfully" | ||
| } | ||
|
|
||
| main() { | ||
| fix_volume_ownerships | ||
| npm_install | ||
| } | ||
|
|
||
| main "$@" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| **/.git/ | ||
| **/node_modules/ |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,16 @@ | ||||||||||||||||||
| # Set the default behavior, in case core.autocrlf has not been set. | ||||||||||||||||||
| * text=auto | ||||||||||||||||||
|
|
||||||||||||||||||
| # Declare files that will always have LF line endings on checkout. | ||||||||||||||||||
| # Declare files that must have specific line endings on checkout. | ||||||||||||||||||
| ## Windows scripts - must be CRLF | ||||||||||||||||||
| *.ps1 text eol=crlf | ||||||||||||||||||
| *.bat text eol=crlf | ||||||||||||||||||
| *.cmd text eol=crlf | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+6
to
+9
|
||||||||||||||||||
| *.ps1 text eol=crlf | |
| *.bat text eol=crlf | |
| *.cmd text eol=crlf | |
| *.bat text eol=crlf | |
| *.cmd text eol=crlf | |
| ## Cross-platform PowerShell scripts - use LF for shebang compatibility | |
| *.ps1 text eol=lf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workspaceMountincludes literal quotes around thesource=value. Docker’s--mountparser treats those quotes as part of the path, which can cause the bind mount to fail and prevent the devcontainer from starting. Consider removing the embedded quotes and relying on the mount string being passed as a single argument (spaces in paths are already handled).