-
Notifications
You must be signed in to change notification settings - Fork 172
feat(build): improve performance and reliability of devcontainer launch (#977) #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
08c796d
a81c83b
680be18
4dbe8ab
89bcbf8
a8c2104
0b9cc24
dfdf4c8
265d54b
01aafaa
6ba4b24
8bd6188
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,6 +1,24 @@ | ||||||||||||||
| { | ||||||||||||||
| "name": "HVE Core - Markdown Editing", | ||||||||||||||
| "image": "${localEnv:HVE_DEVCONTAINER_IMAGE:mcr.microsoft.com/devcontainers/base:2-jammy}", | ||||||||||||||
| // Rename the mount to /workspace for consistency, otherwise its mounted using | ||||||||||||||
| // whatever folder name the user cloned the repo as | ||||||||||||||
| "workspaceMount": "\"source=${localWorkspaceFolder}\",target=/workspace,type=bind", | ||||||||||||||
|
stewartadam marked this conversation as resolved.
|
||||||||||||||
| "workspaceFolder": "/workspace", | ||||||||||||||
| "mounts": [ | ||||||||||||||
| // Put GitHub local user data in a volume | ||||||||||||||
| { | ||||||||||||||
| "type": "volume", | ||||||||||||||
| "source": "${devcontainerId}-userconfig", | ||||||||||||||
| "target": "/home/vscode/.config" | ||||||||||||||
|
stewartadam marked this conversation as resolved.
|
||||||||||||||
| }, | ||||||||||||||
| // Put node modules into volume for better performance | ||||||||||||||
| { | ||||||||||||||
| "type": "volume", | ||||||||||||||
| "source": "${devcontainerId}-nodemodules", | ||||||||||||||
| "target": "/workspace/node_modules" | ||||||||||||||
| } | ||||||||||||||
|
stewartadam marked this conversation as resolved.
|
||||||||||||||
| ], | ||||||||||||||
| "features": { | ||||||||||||||
| "ghcr.io/devcontainers/features/node:1": { | ||||||||||||||
| "version": "20" | ||||||||||||||
|
Collaborator
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. 🔴 High — Node.js version regression The PR branch specifies Node.js
Suggested change
|
||||||||||||||
|
|
@@ -9,28 +27,39 @@ | |||||||||||||
| "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/github-cli:1": {}, | ||||||||||||||
| "ghcr.io/devcontainers/features/powershell:1": {} | ||||||||||||||
| }, | ||||||||||||||
| "customizations": { | ||||||||||||||
| "vscode": { | ||||||||||||||
| "extensions": [ | ||||||||||||||
| "streetsidesoftware.code-spell-checker", | ||||||||||||||
| "davidanson.vscode-markdownlint", | ||||||||||||||
| "yzhang.markdown-all-in-one", | ||||||||||||||
| "bierner.markdown-preview-github-styles", | ||||||||||||||
| "bierner.markdown-mermaid", | ||||||||||||||
| "bierner.markdown-preview-github-styles", | ||||||||||||||
| "bpruitt-goddard.mermaid-markdown-syntax-highlighting", | ||||||||||||||
| "charliermarsh.ruff", | ||||||||||||||
| "davidanson.vscode-markdownlint", | ||||||||||||||
| "github.vscode-pull-request-github", | ||||||||||||||
| "ms-python.python", | ||||||||||||||
| "ms-python.vscode-pylance", | ||||||||||||||
| "charliermarsh.ruff" | ||||||||||||||
| ] | ||||||||||||||
| "streetsidesoftware.code-spell-checker", | ||||||||||||||
| "yzhang.markdown-all-in-one" | ||||||||||||||
| ], | ||||||||||||||
| "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": { | ||||||||||||||
|
stewartadam marked this conversation as resolved.
|
||||||||||||||
| "extractGitGlobals": "(git config -l --global --include || true) > .gitconfig.global", | ||||||||||||||
| "extractGitLocals": "(git config -l --local --include || true) > .gitconfig.local" | ||||||||||||||
|
Comment on lines
+58
to
+59
Collaborator
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. 🟡 Medium — This writes the entire global and local git config to plaintext files in the workspace root. While Consider filtering at the source to only extract the keys actually needed:
Suggested change
This eliminates the information disclosure window by never writing unneeded config values to disk. |
||||||||||||||
| }, | ||||||||||||||
| "postAttachCommand": "/bin/bash .devcontainer/scripts/post-attach.sh", | ||||||||||||||
| "onCreateCommand": "bash .devcontainer/scripts/on-create.sh", | ||||||||||||||
| "updateContentCommand": "npm ci", | ||||||||||||||
| "postCreateCommand": "bash .devcontainer/scripts/post-create.sh", | ||||||||||||||
|
Comment on lines
62
to
63
Collaborator
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. 🟡 Medium — Was the The base branch uses Moving I'd suggest keeping
Suggested change
|
||||||||||||||
| "remoteEnv": { | ||||||||||||||
| "HVE_GITHUB_RELEASES_URL": "${localEnv:HVE_GITHUB_RELEASES_URL}", | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env bash | ||
|
stewartadam marked this conversation as resolved.
|
||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # post-attach.sh | ||
| # Post-attach setup for HVE Core development container | ||
|
|
||
| set -euo pipefail | ||
|
|
||
|
stewartadam marked this conversation as resolved.
|
||
| # 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" | ||
| local key value | ||
| while IFS='=' read -r key value; do | ||
| case "$key" in | ||
| user.name | user.email | user.signingkey | commit.gpgsign) | ||
| echo "Set Git config ${key}=${value}" | ||
| git config --global "$key" "$value" | ||
|
stewartadam marked this conversation as resolved.
|
||
| ;; | ||
| esac | ||
| done < "$conf" | ||
| rm -f "${conf}" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| # Main execution path | ||
|
|
||
| copy_user_gitconfig | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,36 @@ set -euo pipefail | |||||
| main() { | ||||||
| echo "Creating logs directory..." | ||||||
| mkdir -p logs | ||||||
|
|
||||||
| fix_volume_ownerships | ||||||
| npm_clean_install | ||||||
| } | ||||||
|
|
||||||
| # 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." >&2 | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| echo "Setting volume ownership for $volume_path" | ||||||
|
stewartadam marked this conversation as resolved.
|
||||||
| sudo -n chown "${USER}":"${USER}" "$volume_path" | ||||||
| } | ||||||
|
Collaborator
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. 🔵 Informational —
|
||||||
|
|
||||||
| 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" | ||||||
| } | ||||||
|
Collaborator
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. 🟢 Low — Hardcoded This hardcodes Consider using
Suggested change
|
||||||
|
|
||||||
| npm_clean_install() { | ||||||
| echo "Running npm ci..." | ||||||
| npm ci | ||||||
| } | ||||||
|
|
||||||
| main "$@" | ||||||
|
Collaborator
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. 🔵 Informational — The devcontainer uses |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| **/.git/ | ||
| **/node_modules/ |
Uh oh!
There was an error while loading. Please reload this page.