fix: Dockerビルド時のプラグインインストールを改善 - #173
Conversation
## 問題 v1.6.0のDockerイメージでプラグインインストールが失敗していた原因: 1. マーケットプレイスがDockerイメージに存在しない 2. エラーログが `/dev/null` で隠されていた 3. デバッグ情報が不足していた ## 解決策 ### 1. マーケットプレイスの自動追加 ```bash claude plugin add-marketplace anthropic/claude-code --name claude-code-plugins claude plugin add-marketplace https://github.com/davila7/claude-code-templates.git --name claude-code-templates claude plugin add-marketplace wshobson/agents --name claude-code-workflows ``` ### 2. エラーログの可視化 - `2>/dev/null` を削除 - エラー出力をキャプチャして表示 - `[WARN]` → `[ERROR]` に変更して重大度を明確化 ### 3. デバッグ情報の追加 - Claude CLIバージョン表示 - マーケットプレイスディレクトリの存在確認 - ディレクトリ内容の表示(`ls -la`) ## 期待効果 - ✅ Dockerビルド時にプラグインが正しくインストールされる - ✅ 失敗時のエラーメッセージが明確になる - ✅ デバッグが容易になる ## 影響範囲 - **ローカル環境**: 影響なし(既にマーケットプレイス存在) - **Docker環境**: プラグインインストールが成功するようになる - **ビルド時間**: マーケットプレイスcloneで +1-2分増加の可能性 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe install script is enhanced to initialize marketplaces from a JSON configuration file after authentication, register multiple marketplaces with per-call error handling, and improve plugin installation error logging by capturing command output on failure while adding debug diagnostics. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
script/install-claude-plugins.sh (1)
78-86: Great improvement for error visibility!Capturing and displaying the command output on failure addresses the original issue where errors were silently discarded with
2>/dev/null. This will make debugging plugin installation failures much easier.💡 Optional: Consider distinguishing between error types
For even better diagnostics, you could distinguish between "already installed" vs. actual failures by parsing the output:
# エラー出力をキャプチャ if output=$(claude plugin install "$plugin" 2>&1); then echo "[SUCCESS] 完了: ${plugin}" installed=$((installed + 1)) + elif echo "$output" | grep -qi "already installed"; then + echo "[INFO] スキップ: ${plugin} (already installed)" + installed=$((installed + 1)) else echo "[ERROR] 失敗: ${plugin}" echo "[ERROR] エラー詳細: ${output}" failed=$((failed + 1)) fiThis is optional and depends on the actual error messages from the
claudeCLI.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
script/install-claude-plugins.sh
⏰ 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). (1)
- GitHub Check: claude-review
🔇 Additional comments (1)
script/install-claude-plugins.sh (1)
61-63: Excellent debug additions!The diagnostic output for Claude version, marketplaces directory path, and directory listing will significantly help troubleshoot installation failures. The error handling using
|| echofor non-critical commands is appropriate.
| echo "[INFO] マーケットプレイスを初期化中..." | ||
| # known_marketplaces.jsonから必要なマーケットプレイスを追加 | ||
| if [[ -f "${CLAUDE_DIR}/plugins/known_marketplaces.json" ]]; then | ||
| echo "[INFO] known_marketplaces.jsonが見つかりました" | ||
|
|
||
| # 必須マーケットプレイスを追加 | ||
| claude plugin add-marketplace anthropic/claude-code --name claude-code-plugins 2>&1 || echo "[WARN] claude-code-plugins already exists or failed to add" | ||
| claude plugin add-marketplace https://github.com/davila7/claude-code-templates.git --name claude-code-templates 2>&1 || echo "[WARN] claude-code-templates already exists or failed to add" | ||
| claude plugin add-marketplace wshobson/agents --name claude-code-workflows 2>&1 || echo "[WARN] claude-code-workflows already exists or failed to add" | ||
| else | ||
| echo "[WARN] known_marketplaces.jsonが見つかりません" | ||
| fi |
There was a problem hiding this comment.
Critical logic flaw: Marketplace initialization is conditional when it should be unconditional.
According to the PR objectives, the root cause is that the marketplaces directory didn't exist when known_marketplaces.json was copied. The solution should be to always add the required marketplaces to ensure the directory structure exists, regardless of whether known_marketplaces.json is present.
The current implementation only adds marketplaces when the JSON file exists (Line 49), which may not solve the original problem if the file is absent during Docker build.
🔎 Proposed fix: Add marketplaces unconditionally
echo "[INFO] マーケットプレイスを初期化中..."
-# known_marketplaces.jsonから必要なマーケットプレイスを追加
-if [[ -f "${CLAUDE_DIR}/plugins/known_marketplaces.json" ]]; then
- echo "[INFO] known_marketplaces.jsonが見つかりました"
-
- # 必須マーケットプレイスを追加
- claude plugin add-marketplace anthropic/claude-code --name claude-code-plugins 2>&1 || echo "[WARN] claude-code-plugins already exists or failed to add"
- claude plugin add-marketplace https://github.com/davila7/claude-code-templates.git --name claude-code-templates 2>&1 || echo "[WARN] claude-code-templates already exists or failed to add"
- claude plugin add-marketplace wshobson/agents --name claude-code-workflows 2>&1 || echo "[WARN] claude-code-workflows already exists or failed to add"
-else
- echo "[WARN] known_marketplaces.jsonが見つかりません"
-fi
+# 必須マーケットプレイスを追加(ディレクトリ構造を確保)
+claude plugin add-marketplace anthropic/claude-code --name claude-code-plugins 2>&1 || echo "[WARN] claude-code-plugins already exists or failed to add"
+claude plugin add-marketplace https://github.com/davila7/claude-code-templates.git --name claude-code-templates 2>&1 || echo "[WARN] claude-code-templates already exists or failed to add"
+claude plugin add-marketplace wshobson/agents --name claude-code-workflows 2>&1 || echo "[WARN] claude-code-workflows already exists or failed to add"
+
+if [[ -f "${CLAUDE_DIR}/plugins/known_marketplaces.json" ]]; then
+ echo "[INFO] known_marketplaces.jsonが確認されました"
+else
+ echo "[INFO] known_marketplaces.jsonは作成されます"
+fi📝 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.
| echo "[INFO] マーケットプレイスを初期化中..." | |
| # known_marketplaces.jsonから必要なマーケットプレイスを追加 | |
| if [[ -f "${CLAUDE_DIR}/plugins/known_marketplaces.json" ]]; then | |
| echo "[INFO] known_marketplaces.jsonが見つかりました" | |
| # 必須マーケットプレイスを追加 | |
| claude plugin add-marketplace anthropic/claude-code --name claude-code-plugins 2>&1 || echo "[WARN] claude-code-plugins already exists or failed to add" | |
| claude plugin add-marketplace https://github.com/davila7/claude-code-templates.git --name claude-code-templates 2>&1 || echo "[WARN] claude-code-templates already exists or failed to add" | |
| claude plugin add-marketplace wshobson/agents --name claude-code-workflows 2>&1 || echo "[WARN] claude-code-workflows already exists or failed to add" | |
| else | |
| echo "[WARN] known_marketplaces.jsonが見つかりません" | |
| fi | |
| echo "[INFO] マーケットプレイスを初期化中..." | |
| # 必須マーケットプレイスを追加(ディレクトリ構造を確保) | |
| claude plugin add-marketplace anthropic/claude-code --name claude-code-plugins 2>&1 || echo "[WARN] claude-code-plugins already exists or failed to add" | |
| claude plugin add-marketplace https://github.com/davila7/claude-code-templates.git --name claude-code-templates 2>&1 || echo "[WARN] claude-code-templates already exists or failed to add" | |
| claude plugin add-marketplace wshobson/agents --name claude-code-workflows 2>&1 || echo "[WARN] claude-code-workflows already exists or failed to add" | |
| if [[ -f "${CLAUDE_DIR}/plugins/known_marketplaces.json" ]]; then | |
| echo "[INFO] known_marketplaces.jsonが確認されました" | |
| else | |
| echo "[INFO] known_marketplaces.jsonは作成されます" | |
| fi |
🤖 Prompt for AI Agents
In script/install-claude-plugins.sh around lines 47 to 58, the marketplace add
commands are only executed if known_marketplaces.json exists, but they must run
unconditionally so the plugins directory and required marketplaces are created
even when the JSON file is absent; remove the if/else guard and always run the
three claude plugin add-marketplace lines (keeping their existing 2>&1 || echo
warnings), and optionally ensure the target plugins directory exists beforehand
by creating ${CLAUDE_DIR}/plugins if missing.
PRレビュー: Dockerビルド時のプラグインインストール改善🎯 総合評価LGTM with minor suggestions - 問題の根本原因を正しく特定し、適切な解決策を実装しています。 ✅ 良い点1. 根本原因の正確な特定
2. 段階的な改善アプローチエラー出力をキャプチャして表示するようになり、トラブルシューティングが劇的に改善されます。 3. 詳細なPR説明
|
| 要件 | 状態 | コメント |
|---|---|---|
| Conventional Commits | ✅ | fix: タイプを正しく使用 |
| テストカバレッジ 70%+ | ❌ | Bashスクリプトのテストが未実装 |
| ドキュメント更新 | ✅ | PR本文に詳細な説明あり |
アクションアイテム:
- Batsフレームワークでのテスト追加を検討
- ShellCheckによるスクリプト品質チェックをCIに追加
🎬 最終推奨事項
マージ前に対応すべき項目:
- Must: trapによる認証情報のクリーンアップ(セキュリティ)
- Should: マーケットプレイス追加のエラーハンドリング改善
マージ後に対応可能な項目:
- Nice to have: Batsフレームワークでのテスト追加
- Nice to have: ShellCheckの導入
📝 コード品質スコア: 4/5
| カテゴリ | スコア | コメント |
|---|---|---|
| 問題分析 | 5/5 | 根本原因を正確に特定 |
| 実装品質 | 4/5 | trapによるクリーンアップで5/5 |
| エラー処理 | 4/5 | マーケットプレイス追加の改善で5/5 |
| ドキュメント | 5/5 | 非常に詳細なPR説明 |
| テスト | 2/5 | テストコードが未実装 |
この変更は明確な価値を提供し、将来のデバッグを大幅に改善します。上記の提案を検討いただければ、さらに堅牢になります! 🚀
|
🎉 This PR is included in version 1.6.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
問題
v1.6.0のDockerイメージでプラグインが正しくインストールされていませんでした。
根本原因
マーケットプレイスが存在しない
known_marketplaces.jsonをコピーしているが、実際のマーケットプレイスリポジトリ(.claude/plugins/marketplaces/)は存在しないエラーログが隠されている
claude plugin install "$plugin" 2>/dev/nullでエラー出力を破棄デバッグ情報不足
解決策
1. マーケットプレイスの自動追加
プラグインインストール前に、必要なマーケットプレイスを追加:
効果: マーケットプレイスが存在しない場合でも自動的にcloneされる
2. エラーログの可視化
Before:
After:
効果: 失敗時のエラーメッセージがビルドログに表示される
3. デバッグ情報の追加
効果: 環境情報とマーケットプレイスの状態が確認可能
期待効果
Dockerビルド時
ビルド時間増加の理由
マーケットプレイスの初回clone:
トレードオフ: ビルド時間が少し増えるが、プラグインが正しくインストールされる
テスト計画
フェーズ1: ローカルでの動作確認
install-claude-plugins.shを単体で実行フェーズ2: Dockerビルドでの検証
フェーズ3: DevContainer起動確認
/pluginコマンドでエラーが出ないか確認影響範囲
ローカル環境
Docker環境
CI/CD
ロールバック手順
問題が発生した場合:
関連PR
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.