Skip to content

fix: Dockerビルド時のプラグインインストールを改善 - #173

Merged
keito4 merged 1 commit into
mainfrom
fix/docker-plugin-installation-verbose
Dec 24, 2025
Merged

fix: Dockerビルド時のプラグインインストールを改善#173
keito4 merged 1 commit into
mainfrom
fix/docker-plugin-installation-verbose

Conversation

@keito4

@keito4 keito4 commented Dec 24, 2025

Copy link
Copy Markdown
Owner

問題

v1.6.0のDockerイメージでプラグインが正しくインストールされていませんでした。

根本原因

  1. マーケットプレイスが存在しない

    • Dockerfileで known_marketplaces.json をコピーしているが、実際のマーケットプレイスリポジトリ(.claude/plugins/marketplaces/)は存在しない
    • プラグインインストール時にマーケットプレイスが見つからず失敗
  2. エラーログが隠されている

    • claude plugin install "$plugin" 2>/dev/null でエラー出力を破棄
    • 失敗の詳細がビルドログに表示されない
  3. デバッグ情報不足

    • 失敗の原因を特定するための情報が不足

解決策

1. マーケットプレイスの自動追加

プラグインインストール前に、必要なマーケットプレイスを追加:

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

効果: マーケットプレイスが存在しない場合でも自動的にcloneされる

2. エラーログの可視化

Before:

if claude plugin install "$plugin" 2>/dev/null; then
    echo "[SUCCESS]   完了: ${plugin}"
else
    echo "[WARN]   スキップまたは失敗: ${plugin}"  # 詳細不明
fi

After:

if output=$(claude plugin install "$plugin" 2>&1); then
    echo "[SUCCESS]   完了: ${plugin}"
else
    echo "[ERROR]   失敗: ${plugin}"
    echo "[ERROR]   エラー詳細: ${output}"  # 詳細を表示
fi

効果: 失敗時のエラーメッセージがビルドログに表示される

3. デバッグ情報の追加

echo "[DEBUG] Claude version: $(claude --version 2>&1 || echo 'not found')"
echo "[DEBUG] Marketplaces directory: ${CLAUDE_DIR}/plugins/marketplaces"
ls -la "${CLAUDE_DIR}/plugins/marketplaces" 2>/dev/null || echo "[WARN] Marketplaces directory not found"

効果: 環境情報とマーケットプレイスの状態が確認可能

期待効果

Dockerビルド時

項目 Before After
プラグインインストール ❌ 失敗(エラー不明) ✅ 成功
エラーログ 🚫 非表示 ✅ 詳細表示
デバッグ ❌ 困難 ✅ 容易
ビルド時間 28分 29-30分 (+1-2分)

ビルド時間増加の理由

マーケットプレイスの初回clone:

  • claude-code-plugins: ~30秒
  • claude-code-templates: ~30秒
  • claude-code-workflows: ~30秒
  • 合計: 約1-2分増加

トレードオフ: ビルド時間が少し増えるが、プラグインが正しくインストールされる

テスト計画

フェーズ1: ローカルでの動作確認

  1. install-claude-plugins.sh を単体で実行
  2. ✅ エラーログが正しく表示されるか確認
  3. ✅ マーケットプレイスが追加されるか確認

フェーズ2: Dockerビルドでの検証

  1. ⏳ CI/CDでビルド実行
  2. ⏳ ビルドログでプラグインインストール状況を確認
  3. ⏳ ビルド成功後、コンテナ内でプラグイン動作確認

フェーズ3: DevContainer起動確認

  1. ⏳ v1.7.0イメージでDevContainer起動
  2. /plugin コマンドでエラーが出ないか確認
  3. ⏳ 全プラグインが利用可能か確認

影響範囲

ローカル環境

  • ✅ 影響なし(既にマーケットプレイス存在)
  • ✅ スクリプト実行時のログがより詳細に

Docker環境

  • ✅ プラグインが正しくインストールされる
  • ⚠️ ビルド時間が1-2分増加

CI/CD

  • ✅ エラーの早期発見が可能
  • ✅ デバッグが容易に

ロールバック手順

問題が発生した場合:

# このPRをrevert
git revert <commit-hash>

# または、スクリプトを以前のバージョンに戻す
git checkout v1.6.0 -- script/install-claude-plugins.sh

関連PR

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added marketplace initialization with configuration loading and registration capabilities.
  • Bug Fixes

    • Enhanced error reporting for failed plugin installations to display diagnostic output.
  • Chores

    • Added debug diagnostic information to improve troubleshooting capabilities.

✏️ Tip: You can customize this high-level summary in your review settings.

## 問題

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>
@coderabbitai

coderabbitai Bot commented Dec 24, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Marketplace Initialization & Plugin Installation Enhancement
script/install-claude-plugins.sh
Adds marketplace initialization block after authentication that loads known_marketplaces.json and registers marketplaces with failure warnings; enhances plugin installation loop to capture and log command output on failures; adds debug echoes for Claude version and marketplaces directory; retains credentials file cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through marketplaces wide,
Loading configs with diagnostic pride,
When plugins stumble, errors now shine bright—
Better logs guide the install through the night! 🌙

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is in Japanese and specifically describes fixing Docker plugin installation, which matches the main objective of improving plugin installation during Docker builds.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/docker-plugin-installation-verbose

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
     fi

This is optional and depends on the actual error messages from the claude CLI.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96d8549 and 0116b74.

📒 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 || echo for non-critical commands is appropriate.

Comment on lines +47 to +58
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
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.

@keito4
keito4 merged commit 5cd77d1 into main Dec 24, 2025
6 checks passed
@claude

claude Bot commented Dec 24, 2025

Copy link
Copy Markdown
Contributor

PRレビュー: Dockerビルド時のプラグインインストール改善

🎯 総合評価

LGTM with minor suggestions - 問題の根本原因を正しく特定し、適切な解決策を実装しています。


✅ 良い点

1. 根本原因の正確な特定

  • マーケットプレイスがDockerイメージに存在しない問題を正しく特定
  • 2>/dev/null によるエラー隠蔽を特定
  • デバッグ情報の不足を認識

2. 段階的な改善アプローチ

エラー出力をキャプチャして表示するようになり、トラブルシューティングが劇的に改善されます。

3. 詳細なPR説明

  • 問題、解決策、期待効果が明確
  • トレードオフ(ビルド時間+1-2分)を事前に提示
  • テスト計画とロールバック手順を記載

⚠️ 改善提案

1. セキュリティ: 認証情報の確実な削除 (High Priority)

問題点:

  • スクリプトがL79-86で失敗すると、認証情報が残る可能性
  • set -euo pipefail により途中で終了する可能性

推奨:
スクリプト冒頭にtrapを追加して、スクリプトがどのように終了しても認証情報が削除されるようにすることを推奨します。

2. マーケットプレイス追加のエラーハンドリング (Medium Priority)

現在の実装では「already exists」と「failed to add」を区別できません。失敗した場合でもスクリプトが続行され、プラグインインストールで必ず失敗します。

マーケットプレイス追加時のエラー出力を確認し、already existsは許容、それ以外はexit 1することを推奨します。

3. テストカバレッジの追加 (Low Priority)

リポジトリのCLAUDE.mdによると、TDDと70%+カバレッジが必須です。Batsフレームワークでのテスト追加を検討してください。


📊 CLAUDE.md 準拠状況

要件 状態 コメント
Conventional Commits fix: タイプを正しく使用
テストカバレッジ 70%+ Bashスクリプトのテストが未実装
ドキュメント更新 PR本文に詳細な説明あり

アクションアイテム:

  1. Batsフレームワークでのテスト追加を検討
  2. ShellCheckによるスクリプト品質チェックをCIに追加

🎬 最終推奨事項

マージ前に対応すべき項目:

  1. Must: trapによる認証情報のクリーンアップ(セキュリティ)
  2. Should: マーケットプレイス追加のエラーハンドリング改善

マージ後に対応可能な項目:

  1. Nice to have: Batsフレームワークでのテスト追加
  2. Nice to have: ShellCheckの導入

📝 コード品質スコア: 4/5

カテゴリ スコア コメント
問題分析 5/5 根本原因を正確に特定
実装品質 4/5 trapによるクリーンアップで5/5
エラー処理 4/5 マーケットプレイス追加の改善で5/5
ドキュメント 5/5 非常に詳細なPR説明
テスト 2/5 テストコードが未実装

この変更は明確な価値を提供し、将来のデバッグを大幅に改善します。上記の提案を検討いただければ、さらに堅牢になります! 🚀

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.6.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant