refactor: devcontainer
This commit is contained in:
@@ -10,12 +10,10 @@
|
||||
"ANTHROPIC_AUTH_TOKEN": "${localEnv:ANTHROPIC_AUTH_TOKEN}",
|
||||
"ANTHROPIC_BASE_URL": "${localEnv:ANTHROPIC_BASE_URL}",
|
||||
"GEMINI_API_KEY": "${localEnv:GEMINI_API_KEY}",
|
||||
"GOOGLE_GEMINI_BASE_URL": "${localEnv:GOOGLE_GEMINI_BASE_URL}",
|
||||
"PATH": "${containerEnv:PATH}:${containerWorkspaceFolder}/node_modules/.bin:${containerEnv:HOME}/.bun/bin:${containerEnv:HOME}/.bun/bin/bun-node-fallback-bin"
|
||||
"GOOGLE_GEMINI_BASE_URL": "${localEnv:GOOGLE_GEMINI_BASE_URL}"
|
||||
},
|
||||
"containerEnv": {
|
||||
"HOME": "/home/usr_vscode",
|
||||
// "NODE_OPTIONS": "--max-old-space-size=4096",
|
||||
"NODE_OPTIONS": "--max-old-space-size=4096",
|
||||
"TZ": "${localEnv:TZ:Asia/Shanghai}"
|
||||
},
|
||||
"customizations": {
|
||||
@@ -55,88 +53,23 @@
|
||||
// * 尽管使用了“/.*/”,但有些还是会失败,因为有几个错误的默认值:
|
||||
// * https://github.com/microsoft/vscode/issues/266651#issuecomment-3292581459
|
||||
"chat.tools.terminal.ignoreDefaultAutoApproveRules": true,
|
||||
"tasks": {
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "dev",
|
||||
"label": "🚀 Dev: Run on Folder Open",
|
||||
"runOptions": {
|
||||
"runOn": "folderOpen"
|
||||
},
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"panel": "dedicated"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
// https://stackoverflow.com/questions/75708866/vscode-dev-container-fails-to-load-ms-vscode-js-debug-extension-correctly
|
||||
// https://davidwesst.com/blog/missing-bootloader-in-vscode-devcontainer/
|
||||
/**
|
||||
* autoAttachFilter 存在问题:会在 NODE_OPTIONS 中注入 bootloader.js 的 --require 参数,
|
||||
* 并错误地重复拼接 --max-old-space-size,形成类似:
|
||||
* NODE_OPTIONS= --require /home/.../bootloader.js --max-old-space-size=4096--max-old-space-size=4096
|
||||
* 导致启动时报错:
|
||||
* Error: illegal value for flag --max-old-space-size=4096--max-old-space-size=4096 of type size_t
|
||||
* 将其设置为 "disabled" 以规避该问题。
|
||||
*/
|
||||
// "debug.javascript.autoAttachFilter": "disabled",
|
||||
"terminal.integrated.defaultProfile.linux": "💲zsh",
|
||||
"terminal.integrated.profiles.linux": {
|
||||
"💲zsh": {
|
||||
"path": "zsh",
|
||||
"icon": "terminal-cmd",
|
||||
"overrideName": true,
|
||||
"color": "terminal.ansiGreen"
|
||||
}
|
||||
}
|
||||
"tasks": { "version": "2.0.0", "tasks": [] },
|
||||
"terminal.integrated.defaultProfile.linux": "zsh"
|
||||
}
|
||||
}
|
||||
},
|
||||
"mounts": [
|
||||
{
|
||||
// 不挂载可能会遇到:`Cannot run macOS (Mach-O) executable in Docker: Exec format error`
|
||||
"type": "volume",
|
||||
"source": "${localWorkspaceFolderBasename}-node_modules",
|
||||
"target": "${containerWorkspaceFolder}/node_modules"
|
||||
},
|
||||
{
|
||||
"type": "volume",
|
||||
"source": "devcontainer-pnpm-store",
|
||||
"target": "/home/usr_vscode/.pnpm-store"
|
||||
},
|
||||
{
|
||||
"type": "volume",
|
||||
"source": "devcontainer-bun-install-cache",
|
||||
"target": "/home/usr_vscode/.bun/install/cache"
|
||||
// rm -rf ~/.bun/install/cache/*
|
||||
},
|
||||
{
|
||||
"type": "bind",
|
||||
"source": "${localWorkspaceFolder}/.devcontainer/onCreateCommand.d",
|
||||
"target": "/usr/local/etc/onCreateCommand.d"
|
||||
}
|
||||
// 不挂载还可能会遇到:`Cannot run macOS (Mach-O) executable in Docker: Exec format error`
|
||||
"source=${localWorkspaceFolderBasename}-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume",
|
||||
"source=${localWorkspaceFolder}/.devcontainer/lifecycle-scripts.d,target=/usr/local/etc/lifecycle-scripts.d,type=bind,consistency=delegated"
|
||||
],
|
||||
/**
|
||||
* 执行顺序总结
|
||||
1. initializeCommand (本地主机,容器创建前)
|
||||
2. 容器创建
|
||||
3. onCreateCommand (容器首次创建时执行一次)
|
||||
4. updateContentCommand ()
|
||||
5. postCreateCommand (每次容器启动时执行)
|
||||
6. 容器启动
|
||||
7. postStartCommand (容器内,每次启动)
|
||||
8. VS Code 附加到容器
|
||||
9. postAttachCommand (容器内,每次附加)
|
||||
*/
|
||||
"initializeCommand": "echo '↘️ 准备创建容器...'; docker pull ghcr.io/yanhao98/h-devcontainer:main;",
|
||||
"onCreateCommand": "echo '↘️ 容器首次创建!'; /usr/local/bin/onCreateCommand.sh",
|
||||
"updateContentCommand": "echo '↘️ 容器内容已更新!'; zsh -c 'time pnpm install;'",
|
||||
"postCreateCommand": "echo '↘️ 容器已创建!';",
|
||||
"postStartCommand": "echo '↘️ 容器启动了!'",
|
||||
"postAttachCommand": "echo '↘️ VS Code 已附加到容器!'; zsh -c 'source ~/.zshrc; echo \"$(date +%Y-%m-%dT%H:%M:%S%z) - Welcome to your Dev Container!\"';",
|
||||
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/${localWorkspaceFolderBasename},type=bind,consistency=delegated",
|
||||
"initializeCommand": "docker pull ghcr.io/yanhao98/h-devcontainer:main;",
|
||||
"onCreateCommand": "/usr/local/bin/run-lifecycle-scripts.sh onCreateCommand",
|
||||
"updateContentCommand": "/usr/local/bin/run-lifecycle-scripts.sh updateContentCommand",
|
||||
"postCreateCommand": "/usr/local/bin/run-lifecycle-scripts.sh postCreateCommand",
|
||||
"postStartCommand": "/usr/local/bin/run-lifecycle-scripts.sh postStartCommand",
|
||||
"postAttachCommand": "/usr/local/bin/run-lifecycle-scripts.sh postAttachCommand",
|
||||
"waitFor": "updateContentCommand",
|
||||
"remoteUser": "usr_vscode"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user