diff --git a/Dockerfile b/Dockerfile index ac7b996..edc8d41 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,10 @@ RUN git config --system --add safe.directory '*' \ && git config --system pull.rebase false \ && git config --system init.defaultBranch main +COPY scripts/container-entrypoint.sh /usr/local/bin/container-entrypoint.sh +RUN chmod +x /usr/local/bin/container-entrypoint.sh + WORKDIR /workspace -ENTRYPOINT ["/usr/bin/tini", "--"] +ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/container-entrypoint.sh"] CMD ["claude"] diff --git a/docker-compose.yml b/docker-compose.yml index 7c92900..a5277fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,8 @@ services: GIT_COMMITTER_NAME: ${GIT_AUTHOR_NAME:-Claude Agent} GIT_COMMITTER_EMAIL: ${GIT_AUTHOR_EMAIL:-claude-agent@local} TERM: xterm-256color + # 传宿主 HOME 给 entrypoint,让 installed_plugins.json 里的绝对路径可解析 + HOST_HOME: ${HOME} volumes: # REPOS_DIR 默认指向 ai-ops 的父目录;队友可在 .env 里改成自己的工作目录 - ${REPOS_DIR:-..}/chat-gw:/workspace/chat-gw @@ -35,6 +37,10 @@ services: - ./CLAUDE.md:/workspace/CLAUDE.md:ro - ./.claude:/workspace/.claude - claude-home:/root/.claude + # 共享宿主 Claude Code 的 plugins + skills(只读) + # 让容器里的 claude 能看到 superpowers / oh-my-claudecode / frontend-design 等 + - ${HOME}/.claude/plugins:/root/.claude/plugins:ro + - ${HOME}/.claude/skills:/root/.claude/skills:ro - pip-cache:/root/.cache/pip - go-cache:/root/go/pkg - npm-cache:/root/.npm diff --git a/scripts/container-entrypoint.sh b/scripts/container-entrypoint.sh new file mode 100755 index 0000000..ed05a62 --- /dev/null +++ b/scripts/container-entrypoint.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# 容器启动时运行的初始化脚本: +# 1) 如果 HOST_HOME 被传入且与 $HOME 不同,建立 symlink 让绝对路径兼容 +# (例:宿主机 /Users/alice/.claude 里的 installed_plugins.json 含 +# 绝对路径 /Users/alice/.claude/plugins/cache/... —— 需要容器里 +# /Users/alice 也能解析到 /root,否则插件加载失败) +# 2) 最后 exec 真实命令 +set -euo pipefail + +if [[ -n "${HOST_HOME:-}" && "$HOST_HOME" != "$HOME" && "$HOST_HOME" != "/" ]]; then + if [[ ! -e "$HOST_HOME" ]]; then + parent=$(dirname "$HOST_HOME") + mkdir -p "$parent" + ln -sfn "$HOME" "$HOST_HOME" + fi +fi + +exec "$@"