feat(devcontainer): ビルド時に完全なClaude設定をイメージに組み込み - #327
Conversation
## Why(なぜ) 新しいリポジトリでconfig-baseイメージを使用する際、ファイルのコピーや 手動設定なしでClaude Code環境をすぐに利用できるようにするため。 ## What(何を) - setup-claude-build.sh: ビルド時専用セットアップスクリプトを追加 - hookifyプラグインのパッチ適用 - known_marketplaces.jsonの生成 - Dockerfile: プラグインインストール後にビルド時セットアップを実行 - 必要なライブラリファイルをCOPY - setup-claude-build.shをUSER vscodeで実行 - docs/using-config-base-image.md: 使用方法ドキュメントを追加 - 最小構成、推奨構成、プロジェクト固有設定の3パターンを記載 ## How(どのように) Dockerビルド時に以下を実行: 1. Claude設定ファイル、コマンド、エージェント、hooksをCOPY 2. プラグインをインストール(install-claude-plugins.sh) 3. hookifyパッチ適用とknown_marketplaces.json生成(setup-claude-build.sh) これにより、新しいリポジトリでは devcontainer.json で イメージを指定するだけで、すべてのClaude設定が利用可能になります。 ## Risk(リスク) - イメージサイズが若干増加(設定ファイルとライブラリの追加) - ビルド時間が若干増加(setup-claude-build.shの実行) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdds a build-time Claude setup flow: copies templates and scripts into the devcontainer image, runs a new Changes
Sequence Diagram(s)sequenceDiagram
participant DockerBuild as Docker Build
participant SetupScript as /tmp/setup-claude-build.sh
participant Libs as script/lib
participant ClaudeCLI as Claude CLI
participant FileSystem as File System
DockerBuild->>SetupScript: Copy scripts/libs and make executable
DockerBuild->>SetupScript: Run as user vscode
SetupScript->>Libs: Source output.sh & claude_plugins.sh
SetupScript->>ClaudeCLI: Check presence
alt Claude CLI and plugins present
SetupScript->>ClaudeCLI: Run plugin install / apply hookify
SetupScript->>FileSystem: Generate known_marketplaces.json from template
SetupScript->>FileSystem: chown files to vscode
SetupScript->>DockerBuild: Exit success
else Missing CLI or plugins
SetupScript->>DockerBuild: Log warning and exit early (continue build)
end
DockerBuild->>DockerBuild: Revert to root user
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ShellCheckのwarning SC2034を修正。 setup-claude-build.shではプラグインリストは不要なため削除。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In @.devcontainer/Dockerfile:
- Around line 101-104: The Dockerfile currently swallows errors from RUN bash
/tmp/setup-claude-build.sh via "|| echo ..." which hides failures (e.g., the
chown permission error in setup-claude-build.sh); update the Dockerfile to run
the setup script without silent failure and move any filesystem ownership
operations (the chown referenced in setup-claude-build.sh) to run as root after
USER vscode returns to USER root so permission changes succeed, or alternatively
have the script itself exit successfully only when allowable errors occur and
explicitly log warnings; specifically, remove the "|| echo" suppression, ensure
setup-claude-build.sh either handles expected missing-credential cases and exits
0 or propagate failure, and perform chown as root after switching back to USER
root to fix permission errors.
In @script/setup-claude-build.sh:
- Around line 23-24: The script defines an unused variable PLUGINS_FILE; remove
the PLUGINS_FILE assignment line (the
PLUGINS_FILE="${CLAUDE_DIR}/plugins/plugins.txt" statement) so only CLAUDE_DIR
remains, and ensure no other code in the file references PLUGINS_FILE (delete or
update any references if present).
- Around line 54-56: The chown invocation in setup-claude-build.sh (the chown -R
vscode:vscode "$CLAUDE_DIR" line) fails because the script runs as USER vscode
and requires root; remove that chown from setup-claude-build.sh and instead
perform the ownership change in the Dockerfile after the script completes (i.e.,
run chown -R vscode:vscode "$CLAUDE_DIR" as root in the Dockerfile), or if you
prefer the alternative, run the script itself as root and switch to vscode
inside the script—prefer the Dockerfile-change approach.
🧹 Nitpick comments (1)
script/setup-claude-build.sh (1)
45-52: Consider using$CLAUDE_DIRfor consistency.The hardcoded
/home/vscodepath should be derived from the$CLAUDE_DIRvariable to maintain a single source of truth. This improves maintainability if the user home directory ever changes.♻️ Proposed refactor
# known_marketplaces.json の生成 if [[ -f "${CLAUDE_DIR}/plugins/known_marketplaces.json.template" ]]; then log_info "known_marketplaces.json を生成中..." + HOME_DIR="${CLAUDE_DIR%/.claude}" - sed "s|{{HOME}}|/home/vscode|g" \ + sed "s|{{HOME}}|${HOME_DIR}|g" \ "${CLAUDE_DIR}/plugins/known_marketplaces.json.template" \ > "${CLAUDE_DIR}/plugins/known_marketplaces.json" log_success "known_marketplaces.json を生成しました" fi
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.devcontainer/Dockerfiledocs/using-config-base-image.mdscript/setup-claude-build.sh
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Publish DevContainer images to ghcr.io/keito4/config-base with semantic versioning
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/docker-image.yml : Build DevContainer images automatically with semantic versioning and multi-platform support in .github/workflows/docker-image.yml
Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T04:05:56.913Z
Learning: Use automated Claude commands from `.claude/commands/` directory for maintenance, Git workflows, code analysis, quality checks, dependency management, security reviews, and tool configuration
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/claude.yml : Trigger automatic AI assistance on claude mentions in issues, PRs, and comments using .github/workflows/claude.yml
📚 Learning: 2026-01-04T04:05:56.913Z
Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T04:05:56.913Z
Learning: Use automated Claude commands from `.claude/commands/` directory for maintenance, Git workflows, code analysis, quality checks, dependency management, security reviews, and tool configuration
Applied to files:
script/setup-claude-build.shdocs/using-config-base-image.md.devcontainer/Dockerfile
📚 Learning: 2026-01-04T04:05:56.913Z
Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T04:05:56.913Z
Learning: Refer to `CLAUDE.md` for quality standards, AI prompt design guidelines, and CI integration
Applied to files:
docs/using-config-base-image.md
📚 Learning: 2025-12-01T03:45:17.253Z
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Publish DevContainer images to ghcr.io/keito4/config-base with semantic versioning
Applied to files:
docs/using-config-base-image.md
📚 Learning: 2025-12-01T03:45:17.253Z
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/docker-image.yml : Build DevContainer images automatically with semantic versioning and multi-platform support in .github/workflows/docker-image.yml
Applied to files:
docs/using-config-base-image.md.devcontainer/Dockerfile
📚 Learning: 2026-01-04T04:05:56.913Z
Learnt from: CR
Repo: keito4/config PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-04T04:05:56.913Z
Learning: Use specialized Claude Code agents from `.claude/agents/` directory for architecture validation, performance analysis, concurrency safety, and testability analysis
Applied to files:
.devcontainer/Dockerfile
🧬 Code graph analysis (1)
script/setup-claude-build.sh (1)
script/lib/claude_plugins.sh (1)
plugins::apply_hookify_patch(237-272)
🪛 GitHub Actions: CI
script/setup-claude-build.sh
[warning] 24-24: SC2034: PLUGINS_FILE appears unused. Verify use (or export if used externally).
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Generate SBOM
- GitHub Check: Trivy Container Scan
🔇 Additional comments (5)
.devcontainer/Dockerfile (1)
84-84: LGTM!The new COPY instructions properly set ownership and permissions for the build-time setup artifacts. The addition of
script/liband the template file supports the new build-time configuration flow.Also applies to: 87-89
docs/using-config-base-image.md (4)
1-45: LGTM!The overview and minimal configuration sections are clear, accurate, and provide helpful guidance for users starting with the config-base image. The minimal example correctly demonstrates the simplest usage pattern.
46-85: LGTM!The plugin list and recommended configuration section clearly explains the trade-offs between minimal and persistent configurations. The mount setup and postCreateCommand usage are correctly documented.
86-134: LGTM!The project-specific settings section provides clear, actionable guidance for customizing the base image. The explanation of
setup-claude.shbehavior correctly describes the runtime setup responsibilities.
135-178: LGTM!The build instructions correctly document the BuildKit secret usage, and the troubleshooting section addresses the most likely user issues. The reference links provide appropriate additional resources.
| # ビルド時にClaude設定を完全にセットアップ | ||
| USER vscode | ||
| RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました" | ||
| USER root |
There was a problem hiding this comment.
Improve error handling for the build-time setup.
The error suppression with || echo "[WARN]..." will silently hide failures in the setup script, including the permission error from the chown command identified in setup-claude-build.sh. This makes debugging difficult.
If the setup script is expected to fail gracefully during builds without credentials, consider more explicit error handling:
🔧 Suggested improvements
# ビルド時にClaude設定を完全にセットアップ
USER vscode
-RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました"
+RUN bash /tmp/setup-claude-build.sh || ( \
+ echo "[WARN] ビルド時セットアップに失敗しました" && \
+ echo "[INFO] コンテナ起動後に setup-claude.sh を実行してください" \
+)
USER root
+RUN chown -R vscode:vscode /home/vscode/.claudeThis moves the chown operation to run as root after the vscode-user script completes, fixing the permission issue while maintaining graceful degradation.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # ビルド時にClaude設定を完全にセットアップ | |
| USER vscode | |
| RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました" | |
| USER root | |
| # ビルド時にClaude設定を完全にセットアップ | |
| USER vscode | |
| RUN bash /tmp/setup-claude-build.sh || ( \ | |
| echo "[WARN] ビルド時セットアップに失敗しました" && \ | |
| echo "[INFO] コンテナ起動後に setup-claude.sh を実行してください" \ | |
| ) | |
| USER root | |
| RUN chown -R vscode:vscode /home/vscode/.claude |
🤖 Prompt for AI Agents
In @.devcontainer/Dockerfile around lines 101 - 104, The Dockerfile currently
swallows errors from RUN bash /tmp/setup-claude-build.sh via "|| echo ..." which
hides failures (e.g., the chown permission error in setup-claude-build.sh);
update the Dockerfile to run the setup script without silent failure and move
any filesystem ownership operations (the chown referenced in
setup-claude-build.sh) to run as root after USER vscode returns to USER root so
permission changes succeed, or alternatively have the script itself exit
successfully only when allowable errors occur and explicitly log warnings;
specifically, remove the "|| echo" suppression, ensure setup-claude-build.sh
either handles expected missing-credential cases and exits 0 or propagate
failure, and perform chown as root after switching back to USER root to fix
permission errors.
| # 設定ファイルのパーミッション確認 | ||
| chown -R vscode:vscode "$CLAUDE_DIR" | ||
|
|
There was a problem hiding this comment.
Permission error: chown requires root privileges.
This script runs as USER vscode (Dockerfile line 102), but the chown command requires root privileges. This operation will fail silently due to the || echo "[WARN]..." error suppression in the Dockerfile.
🔧 Recommended fix
Option 1 (Recommended): Remove the chown from this script and handle it in the Dockerfile after the script completes:
- # 設定ファイルのパーミッション確認
- chown -R vscode:vscode "$CLAUDE_DIR"
-
log_success "Claude Code ビルド時セットアップが完了しました!"Then in .devcontainer/Dockerfile line 103-104:
USER vscode
-RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました"
+RUN bash /tmp/setup-claude-build.sh
USER root
+RUN chown -R vscode:vscode /home/vscode/.claudeOption 2: Run the entire script as root and handle user switching internally, but this is less clean.
🤖 Prompt for AI Agents
In @script/setup-claude-build.sh around lines 54 - 56, The chown invocation in
setup-claude-build.sh (the chown -R vscode:vscode "$CLAUDE_DIR" line) fails
because the script runs as USER vscode and requires root; remove that chown from
setup-claude-build.sh and instead perform the ownership change in the Dockerfile
after the script completes (i.e., run chown -R vscode:vscode "$CLAUDE_DIR" as
root in the Dockerfile), or if you prefer the alternative, run the script itself
as root and switch to vscode inside the script—prefer the Dockerfile-change
approach.
PR Review: config-baseイメージへのClaude設定の組み込みこのPRは、config-baseイメージに完全なClaude Code環境を組み込むための重要な改善です。全体的に良く設計されていますが、いくつかの改善点と懸念事項があります。 良い点
改善が必要な点1. 重大な問題: setup-claude-build.shのパーミッション操作script/setup-claude-build.sh:54 で 推奨修正: この chown 行を削除する(既にDockerfileで適切な所有権が設定されています) 2. Dockerfileの論理的な問題.devcontainer/Dockerfile:101-104 で、エラーが発生しても警告メッセージだけで続行します。これにより、セットアップが不完全なイメージが作成される可能性があります。 3. テストカバレッジの不足実際のDockerビルドでテストされていない可能性があります。ローカルでのDockerビルドテストとCI結果の確認を推奨します。 4. スクリプトのロバスト性script/setup-claude-build.sh:13-16 で SCRIPT_DIR が計算されますが、Dockerビルド時は常に /tmp/script-lib を使用するため、最初の計算が無駄になっています。 その他の観察事項
推奨アクションマージ前に必須:
推奨(オプション):
総評このPRは、config-baseイメージの利便性を大幅に向上させる優れた機能追加です。しかし、上記の問題(特に chown とUSER切り替え)を修正してからマージすることを強く推奨します。 |
|
🎉 This PR is included in version 1.45.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
新しいリポジトリでconfig-baseイメージを使用する際、ファイルのコピーや手動設定なしでClaude Code環境をすぐに利用できるようにしました。
Changes
Implementation
Dockerビルド時に以下を実行:
Result
新しいリポジトリでは devcontainer.json でイメージを指定するだけで、すべてのClaude設定が利用可能になります。
最小構成例
```json
{
"name": "My Project",
"image": "ghcr.io/keito4/config-base:1.43.0",
"remoteEnv": {
"TMPDIR": "/home/vscode/.claude/tmp"
}
}
```
Test plan
Risks
🤖 Generated with Claude Code
Summary by CodeRabbit
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.