feat: 更新 Dockerfile 和 devcontainer.json,优化开发环境配置和扩展推荐
All checks were successful
CI/CD Pipeline / playwright (push) Successful in 2m17s
CI/CD Pipeline / build-and-deploy (push) Successful in 2m26s

This commit is contained in:
严浩
2025-11-07 08:18:45 +00:00
parent ce2f5338de
commit 8d052bcac8
2 changed files with 115 additions and 114 deletions

View File

@@ -1,87 +1,78 @@
FROM debian:13.1-slim FROM debian:13.1-slim
# 元数据
LABEL maintainer="i@oo1.dev" \
description="Development container for Claude and Gemini development"
# 安装中文语言包 # 构建参数
RUN apt-get update && apt-get install -y locales && \ ARG GIT_DELTA_VERSION=0.18.2
sed -i 's/^# *zh_CN.UTF-8/zh_CN.UTF-8/' /etc/locale.gen && \ ARG ZSH_IN_DOCKER_VERSION=1.2.1
locale-gen zh_CN.UTF-8 && \ ARG PNPM_HOME="/home/usr_vscode/.local/share/pnpm"
update-locale LANG=zh_CN.UTF-8 ARG PATH="$PNPM_HOME:$PATH"
# 环境变量
ENV LANG=zh_CN.UTF-8 \
LC_ALL=zh_CN.UTF-8 \
# Set `DEVCONTAINER` environment variable to help with orientation
DEVCONTAINER=true \
# Set the default shell to zsh rather than sh
SHELL=/bin/zsh \
# Set the default editor and visual
EDITOR=nano \
VISUAL=nano \
POWERLEVEL9K_DISABLE_GITSTATUS=true
# 安装所有系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \ # 语言包
wget \ locales \
curl # 基础工具
ca-certificates wget curl \
# 开发工具
less git procps sudo fzf zsh man-db unzip gnupg2 gh \
# 网络工具
iptables ipset iproute2 dnsutils aggregate \
# 编辑器和实用工具
jq nano vim \
# 配置中文环境
&& sed -i 's/^# *zh_CN.UTF-8/zh_CN.UTF-8/' /etc/locale.gen \
&& locale-gen zh_CN.UTF-8 \
&& update-locale LANG=zh_CN.UTF-8 \
# 清理缓存
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install basic development tools and iptables/ipset # 创建用户和配置 sudo
RUN apt-get update && apt-get install -y --no-install-recommends \
less \
git \
procps \
sudo \
fzf \
zsh \
man-db \
unzip \
gnupg2 \
gh \
iptables \
ipset \
iproute2 \
dnsutils \
aggregate \
jq \
nano \
vim \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# 创建 usr_vscode 用户和组UID 和 GID 都是 1000 # https://github.com/nodejs/docker-node/blob/27dd50d60e181b3da84a17d9c5037dcfeb94b781/24/bookworm/Dockerfile#L3
RUN groupadd --gid 1000 usr_vscode \ RUN groupadd --gid 1000 usr_vscode \
&& useradd --uid 1000 --gid usr_vscode --shell /bin/bash --create-home usr_vscode \ && useradd --uid 1000 --gid usr_vscode --shell /bin/zsh --create-home usr_vscode \
# Show the contents of /etc/passwd && echo "usr_vscode ALL=(root) NOPASSWD: ALL" > /etc/sudoers.d/usr_vscode_user_config \
&& chmod 0440 /etc/sudoers.d/usr_vscode_user_config \
&& cat /etc/passwd && cat /etc/passwd
RUN echo "usr_vscode ALL=(root) NOPASSWD: ALL" > /etc/sudoers.d/usr_vscode_user_config && \ # 配置命令历史
chmod 0440 /etc/sudoers.d/usr_vscode_user_config RUN mkdir -p /commandhistory \
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
&& mkdir /commandhistory \
&& touch /commandhistory/.bash_history \ && touch /commandhistory/.bash_history \
&& chown -R usr_vscode /commandhistory && chown -R usr_vscode:usr_vscode /commandhistory
# Set `DEVCONTAINER` environment variable to help with orientation # 创建工作目录
ENV DEVCONTAINER=true RUN mkdir -p /workspace /home/usr_vscode/.claude \
&& chown -R usr_vscode:usr_vscode /workspace /home/usr_vscode/.claude
# Create workspace and config directories and set permissions # 安装 git-delta https://github.com/dandavison/delta/releases
RUN mkdir -p /workspace /home/usr_vscode/.claude && \
chown -R usr_vscode:usr_vscode /workspace /home/usr_vscode/.claude
WORKDIR /workspace
# https://github.com/dandavison/delta/releases
ARG GIT_DELTA_VERSION=0.18.2
RUN ARCH=$(dpkg --print-architecture) && \ RUN ARCH=$(dpkg --print-architecture) && \
curl -L -o "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" "https://github.com/dandavison/delta/releases/download/${GIT_DELTA_VERSION}/git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \ curl -L -o "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" "https://github.com/dandavison/delta/releases/download/${GIT_DELTA_VERSION}/git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \
sudo dpkg -i "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \ sudo dpkg -i "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \
rm "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" rm "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb"
# Set up non-root user WORKDIR /workspace
# 切换到非 root 用户
USER usr_vscode USER usr_vscode
# Set the default shell to zsh rather than sh # 配置 Zsh https://github.com/deluan/zsh-in-docker/releases
ENV SHELL=/bin/zsh
# Set the default editor and visual
ENV EDITOR=nano
ENV VISUAL=nano
# https://github.com/deluan/zsh-in-docker/releases
# Default powerline10k theme # Default powerline10k theme
ENV POWERLEVEL9K_DISABLE_GITSTATUS=true RUN touch /home/usr_vscode/.zshrc \
ARG ZSH_IN_DOCKER_VERSION=1.2.1 && sh -c "$(curl -L -o - https://github.com/deluan/zsh-in-docker/releases/download/v${ZSH_IN_DOCKER_VERSION}/zsh-in-docker.sh)" -- \
RUN touch /home/usr_vscode/.zshrc
RUN sh -c "$(curl -L -o - https://github.com/deluan/zsh-in-docker/releases/download/v${ZSH_IN_DOCKER_VERSION}/zsh-in-docker.sh)" -- \
-p git \ -p git \
-p fzf \ -p fzf \
-a "source <(fzf --zsh)" \ -a "source <(fzf --zsh)" \
@@ -90,16 +81,14 @@ RUN sh -c "$(curl -L -o - https://github.com/deluan/zsh-in-docker/releases/downl
# -a "source /usr/share/doc/fzf/examples/key-bindings.zsh" \ # -a "source /usr/share/doc/fzf/examples/key-bindings.zsh" \
# -a "source /usr/share/doc/fzf/examples/completion.zsh" \ # -a "source /usr/share/doc/fzf/examples/completion.zsh" \
# 安装 pnpm 和 Node.js
# https://pnpm.io/installation#in-a-docker-container # https://pnpm.io/installation#in-a-docker-container
ARG PNPM_HOME="/home/usr_vscode/.local/share/pnpm"
ARG PATH="$PNPM_HOME:$PATH"
RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.zshrc" SHELL="$(which zsh)" zsh - \ RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.zshrc" SHELL="$(which zsh)" zsh - \
&& pnpm --version \ && pnpm --version \
&& pnpm env use lts --global \ && pnpm env use lts --global \
&& pnpm config set store-dir /home/usr_vscode/.pnpm-store && pnpm config set store-dir /home/usr_vscode/.pnpm-store
# Install Claude # 安装 AI 工具
RUN pnpm install -g \ RUN pnpm install -g \
@google/gemini-cli@latest \ @google/gemini-cli@latest \
@anthropic-ai/claude-code@latest \ @anthropic-ai/claude-code@latest \

View File

@@ -25,19 +25,25 @@
"customizations": { "customizations": {
"vscode": { "vscode": {
"extensions": [ "extensions": [
// AI
"anthropic.claude-code", "anthropic.claude-code",
"google.gemini-cli-vscode-ide-companion", "google.gemini-cli-vscode-ide-companion",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"eamodio.gitlens",
"oxc.oxc-vscode",
"editorconfig.editorconfig",
"vitest.explorer",
"vue.volar",
"kilocode.kilo-code", "kilocode.kilo-code",
"alibaba-cloud.tongyi-lingma", "alibaba-cloud.tongyi-lingma",
// >>>>>
"vue.volar",
"lokalise.i18n-ally",
"eamodio.gitlens",
"vitest.explorer",
// <<<<<
// 代码质量 / 格式化 / Lint
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"stylelint.vscode-stylelint", "stylelint.vscode-stylelint",
"lokalise.i18n-ally" "oxc.oxc-vscode",
"esbenp.prettier-vscode"
], ],
"settings": { "settings": {
"editor.formatOnSave": true, "editor.formatOnSave": true,
@@ -47,24 +53,25 @@
}, },
"terminal.integrated.defaultProfile.linux": "zsh", "terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": { "terminal.integrated.profiles.linux": {
"bash": { "bash": { "path": "bash", "icon": "terminal-bash" },
"path": "bash", "zsh": { "path": "zsh", "icon": "terminal-debian" }
"icon": "terminal-bash"
}, },
"zsh": {
"path": "zsh", // https://stackoverflow.com/questions/75708866/vscode-dev-container-fails-to-load-ms-vscode-js-debug-extension-correctly
"icon": "terminal-debian" // 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"
} }
} }
}, },
"remoteUser": "usr_vscode",
"mounts": [
// "source=dev-container-config-${devcontainerId},target=/root/.claude,type=volume",
// "source=node_modules-u_node-${devcontainerId},target=/workspace/node_modules,type=volume",
// "source=dev-container-bashhistory-${devcontainerId},target=/commandhistory,type=volume"
],
"containerEnv": { "containerEnv": {
// "CLAUDE_CONFIG_DIR": "/home/usr_vscode/.claude", // "CLAUDE_CONFIG_DIR": "/home/usr_vscode/.claude",
"ANTHROPIC_AUTH_TOKEN": "${localEnv:ANTHROPIC_AUTH_TOKEN}", "ANTHROPIC_AUTH_TOKEN": "${localEnv:ANTHROPIC_AUTH_TOKEN}",
@@ -73,9 +80,14 @@
"GOOGLE_GEMINI_BASE_URL": "${localEnv:GOOGLE_GEMINI_BASE_URL}", "GOOGLE_GEMINI_BASE_URL": "${localEnv:GOOGLE_GEMINI_BASE_URL}",
"NODE_OPTIONS": "--max-old-space-size=4096" "NODE_OPTIONS": "--max-old-space-size=4096"
}, },
// "postCreateCommand": "pnpm install", // 容器创建后执行 "remoteUser": "usr_vscode",
"mounts": [
// "source=dev-container-bashhistory-${devcontainerId},target=/commandhistory,type=volume"
"source=${localWorkspaceFolderBasename}-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume"
],
"postCreateCommand": "sudo chown usr_vscode node_modules", // 容器创建后执行 https://code.visualstudio.com/remote/advancedcontainers/improve-performance
"postStartCommand": "pnpm -v", // 每次容器启动时执行 "postStartCommand": "pnpm -v", // 每次容器启动时执行
"postAttachCommand": "pnpm config get store-dir", // 连接到容器后执行 // "postAttachCommand": "pnpm config get store-dir", // 连接到容器后执行
// "updateRemoteUserUID": true, // "updateRemoteUserUID": true,
// "waitFor": "postStartCommand" // "waitFor": "postStartCommand"
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated", "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated",