Skip to content

fix(devcontainer): DevContainerビルド時のClaudeプラグインインストールを改善 - #179

Merged
keito4 merged 2 commits into
mainfrom
feat/credential-filtering
Dec 25, 2025
Merged

fix(devcontainer): DevContainerビルド時のClaudeプラグインインストールを改善#179
keito4 merged 2 commits into
mainfrom
feat/credential-filtering

Conversation

@keito4

@keito4 keito4 commented Dec 25, 2025

Copy link
Copy Markdown
Owner

概要

DevContainerビルド時のClaudeプラグインインストールを改善し、エラーハンドリングと自動リカバリーを強化しました。

変更内容

1. Dockerfile

  • プラグインインストール失敗時の明確な警告メッセージを追加
  • ビルドログで問題を把握しやすくなりました

2. devcontainer.json

  • postCreateCommand から --sync-only オプションを削除
  • コンテナ起動時にプラグインも自動インストールされるように修正

3. script/post-create-plugins.sh (新規)

  • 不足しているプラグインを自動検出してインストールするスクリプトを追加
  • コンテナ起動後のフォールバック用

背景

ビルド時に BuildKit secret が提供されない場合、プラグインのインストールが失敗していましたが、|| true により エラーが無視されていたため問題が表面化していませんでした。

この修正により:

  1. ✅ ビルド時のエラーが明確になる
  2. ✅ コンテナ起動時に自動的に再インストールを試みる
  3. ✅ 手動インストールの方法も明示される

テスト

  • pre-commit hooks 通過
  • 全35個のテストが成功
  • 手動でプラグインインストールを確認

関連Issue

プラグインインストールエラーの解決

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Automated plugin installation during setup with detection of missing plugins and clear per-plugin status reporting.
  • Improvements

    • Explicit failure handling: shows two Japanese messages (warning and guidance) on install errors and continues setup.
    • Setup invocation updated to run the full install (no sync-only restriction).

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

## 変更内容

### Dockerfile
- プラグインインストール失敗時の明確な警告メッセージを追加
- ビルドログで問題を把握しやすくなりました

### devcontainer.json
- postCreateCommand から --sync-only オプションを削除
- コンテナ起動時にプラグインも自動インストールされるように修正

### script/post-create-plugins.sh (新規)
- 不足しているプラグインを自動検出してインストールするスクリプトを追加
- コンテナ起動後のフォールバック用

## 背景

ビルド時に BuildKit secret が提供されない場合、プラグインのインストールが
失敗していましたが、エラーが無視されていたため問題が表面化していませんでした。

この修正により:
1. ビルド時のエラーが明確になる
2. コンテナ起動時に自動的に再インストールを試みる
3. 手動インストールの方法も明示される

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 25, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Replaces silent Dockerfile fallback with explicit Japanese warning/guidance on Claude plugin install failure, removes --sync-only from devcontainer postCreateCommand, and adds script/post-create-plugins.sh to read plugins.txt and install missing Claude plugins with status reporting.

Changes

Cohort / File(s) Summary
Devcontainer Dockerfile
.devcontainer/Dockerfile
Replaced silent failure fallback after Claude plugin install with an explicit fallback that emits two Japanese messages (warning and guidance) and continues.
Devcontainer config
.devcontainer/devcontainer.json
Removed the --sync-only flag from the postCreateCommand invocation: changed `./script/setup-claude.sh --sync-only
Plugin installation script
script/post-create-plugins.sh
Added new script that reads plugins.txt, skips comments/blank lines, checks installed plugins via claude plugin list, installs missing plugins with claude plugin install, reports per-plugin status and final counts, and exits 0.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

released

Poem

🐰
I hopped through Docker, nose aglow,
Found plugins listed row by row,
I warned in Japanese when installs failed,
Then ran my script till none were paled —
A merry hop, and logs that show! 🎋

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 clearly describes the main change: improving Claude plugin installation during DevContainer builds, which matches the core objectives of enhancing error handling and auto-recovery for plugin installation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee89ec7 and bd9652c.

📒 Files selected for processing (2)
  • .devcontainer/Dockerfile
  • .devcontainer/devcontainer.json

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 (2)
script/post-create-plugins.sh (2)

22-28: Consider using parameter expansion for trimming whitespace.

The use of xargs to trim whitespace works but is unconventional. A more idiomatic bash approach would be:

plugin="${line#"${line%%[![:space:]]*}"}"  # Remove leading whitespace
plugin="${plugin%"${plugin##*[![:space:]]}"}"  # Remove trailing whitespace

Or even simpler with extended pattern matching:

shopt -s extglob
plugin="${line##*([[:space:]])}"
plugin="${plugin%%*([[:space:]])}"

19-40: Consider tracking already-installed plugins for complete visibility.

Currently, the script only counts installed and missing plugins. Plugins that are already installed are silently skipped without any counter update, making it difficult to understand the complete picture of what happened during execution.

🔎 Proposed enhancement to track skipped plugins
 installed=0
+skipped=0
 missing=0

 while IFS= read -r line || [[ -n "$line" ]]; do
     # 空行とコメント行をスキップ
     [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue

     # 前後の空白を除去
     plugin=$(echo "$line" | xargs)
     [[ -z "$plugin" ]] && continue

     # プラグインがインストール済みかチェック
     if ! claude plugin list 2>/dev/null | grep -q "$plugin"; then
         echo "[INFO] インストール中: ${plugin}"
         if claude plugin install "$plugin" 2>/dev/null; then
             echo "[SUCCESS] 完了: ${plugin}"
             installed=$((installed + 1))
         else
             echo "[WARN] スキップまたは失敗: ${plugin}"
             missing=$((missing + 1))
         fi
+    else
+        echo "[INFO] 既にインストール済み: ${plugin}"
+        skipped=$((skipped + 1))
     fi
 done < "$PLUGINS_FILE"

 if [[ $installed -gt 0 ]]; then
     echo "[SUCCESS] ${installed} 個のプラグインをインストールしました"
 fi

+if [[ $skipped -gt 0 ]]; then
+    echo "[INFO] ${skipped} 個のプラグインは既にインストール済みです"
+fi
+
 if [[ $missing -gt 0 ]]; then
     echo "[WARN] ${missing} 個のプラグインのインストールに失敗しました"
     echo "[INFO] 手動でインストールするには: claude plugin install <plugin>@<marketplace>"
 fi
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20c1326 and ee89ec7.

📒 Files selected for processing (3)
  • .devcontainer/Dockerfile
  • .devcontainer/devcontainer.json
  • script/post-create-plugins.sh
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
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
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
🔇 Additional comments (4)
script/post-create-plugins.sh (2)

1-17: LGTM!

The script header and file existence check are well-structured. The use of set -euo pipefail provides good error handling, and the graceful exit when the plugins file is missing is appropriate.


43-52: LGTM!

The summary output and unconditional exit 0 are appropriate for a post-create hook. This ensures the DevContainer setup continues even if some plugins fail to install, while still providing useful diagnostic information to the user.

.devcontainer/Dockerfile (1)

84-88: LGTM! Improved error visibility during plugin installation.

The updated fallback messaging clearly communicates when plugin installation fails and provides actionable guidance for users. The use of a subshell for the warning messages ensures the Docker build continues successfully while making the failure visible, which aligns perfectly with the PR objectives of improving error handling and auto-recovery.

The Japanese messages are appropriate for the target audience and consistent with the messaging in post-create-plugins.sh.

.devcontainer/devcontainer.json (1)

49-49: The setup-claude.sh change is safe and correct.

Verified:

  • The script supports running without --sync-only (defaults to SYNC_ONLY=false), enabling both config sync and plugin installation
  • Plugins are installed via install_plugins() when SYNC_ONLY is false, aligning with the PR objective for auto-installation at container startup
  • post-create-plugins.sh provides a compatible fallback mechanism that checks for missing plugins and installs only those not yet present, ensuring graceful recovery if the initial installation fails

[[ -z "$plugin" ]] && continue

# プラグインがインストール済みかチェック
if ! claude plugin list 2>/dev/null | grep -q "$plugin"; then

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

Fix plugin existence check to use exact matching.

The current grep -q "$plugin" performs substring matching, which can produce false positives. For example, if the plugins list contains both "git" and "github", checking for "git" would incorrectly match "github".

🔎 Proposed fix using exact matching
-    if ! claude plugin list 2>/dev/null | grep -q "$plugin"; then
+    if ! claude plugin list 2>/dev/null | grep -qE "^${plugin}(\s|$)"; then

Alternatively, use word boundary matching:

-    if ! claude plugin list 2>/dev/null | grep -q "$plugin"; then
+    if ! claude plugin list 2>/dev/null | grep -qw "$plugin"; then

Note: The best approach depends on the exact output format of claude plugin list. You may need to verify the output format to ensure the pattern matches correctly.

📝 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
if ! claude plugin list 2>/dev/null | grep -q "$plugin"; then
if ! claude plugin list 2>/dev/null | grep -qw "$plugin"; then
🤖 Prompt for AI Agents
In script/post-create-plugins.sh around line 31, the existence check uses grep
-q "$plugin" which does substring matching and can yield false positives (e.g.,
"git" matching "github"); change the check to an exact whole-line match such as
using grep -xF -q "$plugin" (or grep -wF -q "$plugin" if word boundaries are
needed) so the plugin name must match exactly, ensure the variable is quoted and
escaped appropriately, and if claude plugin list prints additional columns
adjust the pattern (or trim/parse the output) to match only the plugin name
field.

マージコンフリクトを解決:
- BuildKit secret の権限指定(uid=0,gid=0)を維持
- エラーメッセージの改善を追加
- chown による所有権設定を維持
@keito4
keito4 merged commit 9c0f832 into main Dec 25, 2025
3 of 4 checks passed
@keito4
keito4 deleted the feat/credential-filtering branch December 25, 2025 01:29
@claude

claude Bot commented Dec 25, 2025

Copy link
Copy Markdown
Contributor

PR レビュー結果

このPRはDevContainerビルド時のClaudeプラグインインストールの改善に関するもので、全体的に良い改善です。詳細なフィードバックを以下に提供します。


✅ 良い点

1. エラーハンドリングの改善

  • Dockerfile:85-88 の変更で、ビルド時のエラーが明確になり、トラブルシューティングが容易になりました
  • ユーザーフレンドリーな日本語メッセージで対処方法を案内している点が優れています

2. フォールバック戦略

  • post-create-plugins.sh スクリプトの追加により、ビルド時に失敗してもコンテナ起動後に再試行できる仕組みを提供
  • 自動リカバリーの仕組みは堅牢性を高めます

3. --sync-only 削除の妥当性

  • devcontainer.json:46 の変更により、プラグインも含めた完全なセットアップが自動化されました

⚠️ 改善提案

1. 重大な問題: post-create-plugins.sh が実行されない

問題: 新しく追加された script/post-create-plugins.sh が postCreateCommand から呼び出されていません。

影響: フォールバック用スクリプトが実行されず、ビルド時にプラグインインストールが失敗した場合の自動リカバリーが機能しません。

推奨修正: postCreateCommand に ./script/post-create-plugins.sh の呼び出しを追加するか、setup-claude.sh の中から呼び出す

2. エラーメッセージの詳細度

場所: script/post-create-plugins.sh:36-37

問題: エラーの詳細が不明確で、デバッグが困難です。

推奨: エラー出力をキャプチャして表示することで、トラブルシューティングを容易にする

3. コード重複の削減

問題: install-claude-plugins.sh と post-create-plugins.sh でプラグインインストールロジックが重複しています。

推奨: 共通のヘルパー関数を作成し、両スクリプトから呼び出すことで保守性を向上させます。

4. テストカバレッジ

欠落: 新しいスクリプトに対するテストが含まれていません。

推奨: CLAUDE.mdの要件(70%+ 行カバレッジ)を満たすため、Bashスクリプトのテストも追加することを検討してください。

5. ドキュメント不足

問題: post-create-plugins.sh の使用方法が文書化されていない

推奨: スクリプトの目的と使用方法をREADMEに追加


🔒 セキュリティ

問題なし

  • 認証情報の削除処理が適切に実装されています
  • BuildKit secretの使用により、認証情報がイメージレイヤーに残らない設計は優れています

📊 パフォーマンス

懸念なし

  • プラグインインストールは非同期的に実行され、ビルド時間への影響は最小限です

🧪 テスト

ステータス

  • ✅ 全35個のテストが成功
  • ✅ pre-commit hooks 通過

追加推奨

  • 新しいスクリプトの単体テスト
  • プラグインインストール失敗時の統合テスト

総合評価

評価: ⭐⭐⭐⭐ (4/5)

判定: 条件付き承認 - 上記の「改善提案 #1(重大)」を修正後にマージ推奨


次のアクション

  1. ✅ postCreateCommand に ./script/post-create-plugins.sh の呼び出しを追加
  2. 🔄 エラーメッセージの詳細度を改善(任意)
  3. 🔄 ドキュメントの更新(任意)
  4. 🔄 テストの追加(将来的な改善)

お疲れさまでした!全体的に良い改善で、特にエラーハンドリングとフォールバック戦略は素晴らしいアイデアです。


🤖 Generated by Claude Code Review

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.6.6 🎉

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