-
Notifications
You must be signed in to change notification settings - Fork 0
feat(devcontainer): ビルド時に完全なClaude設定をイメージに組み込み #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| # config-base イメージの使用方法 | ||
|
|
||
| ## 概要 | ||
|
|
||
| `ghcr.io/keito4/config-base` イメージは、Claude Code の完全なセットアップを含む DevContainer イメージです。新しいリポジトリでこのイメージを使用することで、以下がすぐに利用可能になります: | ||
|
|
||
| - Claude Code CLI と設定 | ||
| - 事前インストールされたプラグイン | ||
| - カスタムコマンド(`/config-base-sync-check`, `/security-credential-scan` など) | ||
| - カスタムエージェント(DDD, パフォーマンス分析など) | ||
| - Git hooks(Quality Gates) | ||
| - 開発ツール(Node.js, pnpm, Rust, terraform, aws-cli など) | ||
|
|
||
| ## 最小構成(マウントなし) | ||
|
|
||
| 新しいリポジトリで最小限の設定で使用する場合: | ||
|
|
||
| ```json | ||
| // .devcontainer/devcontainer.json | ||
| { | ||
| "name": "My Project", | ||
| "image": "ghcr.io/keito4/config-base:1.43.0", | ||
| "remoteEnv": { | ||
| "TMPDIR": "/home/vscode/.claude/tmp" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| この構成では、イメージに含まれているすべての設定がそのまま利用できます。 | ||
|
|
||
| ### 利用可能なコマンド | ||
|
|
||
| ```bash | ||
| # Claude Code コマンド | ||
| claude --help | ||
|
|
||
| # カスタムコマンド | ||
| /config-base-sync-check # イメージバージョン確認 | ||
| /security-credential-scan # 認証情報スキャン | ||
| /code-complexity-check # コード複雑度チェック | ||
| /dependency-health-check # 依存関係ヘルスチェック | ||
| /pre-pr-checklist # PR前チェックリスト | ||
| # その他多数... | ||
| ``` | ||
|
|
||
| ### プラグイン | ||
|
|
||
| 以下のプラグインが事前インストールされています: | ||
|
|
||
| - `commit-commands@claude-plugins-official` | ||
| - `hookify@claude-plugins-official` | ||
| - `plugin-dev@claude-plugins-official` | ||
| - `frontend-design@claude-plugins-official` | ||
| - `typescript-lsp@claude-plugins-official` | ||
| - `code-refactoring@claude-code-workflows` | ||
| - `code-review@claude-plugins-official` | ||
| - `code-review-ai@claude-code-workflows` | ||
| - `kubernetes-operations@claude-code-workflows` | ||
| - `javascript-typescript@claude-code-workflows` | ||
| - `playwright-skill@playwright-skill` | ||
|
|
||
| ## 推奨構成(ホスト設定の永続化) | ||
|
|
||
| プラグインの追加インストールや設定のカスタマイズを永続化したい場合: | ||
|
|
||
| ```json | ||
| // .devcontainer/devcontainer.json | ||
| { | ||
| "name": "My Project", | ||
| "image": "ghcr.io/keito4/config-base:1.43.0", | ||
| "remoteEnv": { | ||
| "TMPDIR": "/home/vscode/.claude/tmp" | ||
| }, | ||
| "initializeCommand": "mkdir -p ~/.claude", | ||
| "mounts": ["source=${localEnv:HOME}/.claude,target=/home/vscode/.claude,type=bind,consistency=cached"], | ||
| "postCreateCommand": "/usr/local/bin/setup-claude.sh" | ||
| } | ||
| ``` | ||
|
|
||
| この構成では: | ||
|
|
||
| - ホストの `~/.claude` をマウントして設定を永続化 | ||
| - `setup-claude.sh` でイメージの設定をホスト側にコピー | ||
| - 追加のプラグインインストールや設定変更が保持される | ||
|
|
||
| ## プロジェクト固有の設定を追加 | ||
|
|
||
| プロジェクト固有のコマンドやプラグインを追加する場合: | ||
|
|
||
| ### 1. リポジトリに `.claude/` ディレクトリを作成 | ||
|
|
||
| ```bash | ||
| mkdir -p .claude/commands | ||
| mkdir -p .claude/plugins | ||
| ``` | ||
|
|
||
| ### 2. プロジェクト固有のコマンドを追加 | ||
|
|
||
| ```markdown | ||
| <!-- .claude/commands/my-custom-command.md --> | ||
|
|
||
| # My Custom Command | ||
|
|
||
| プロジェクト固有のコマンド説明... | ||
| ``` | ||
|
|
||
| ### 3. プロジェクト固有のプラグインを追加 | ||
|
|
||
| ```txt | ||
| # .claude/plugins/plugins.txt | ||
| # プロジェクト固有のプラグイン | ||
| my-plugin@marketplace | ||
| ``` | ||
|
|
||
| ### 4. `devcontainer.json` を更新 | ||
|
|
||
| ```json | ||
| { | ||
| "name": "My Project", | ||
| "image": "ghcr.io/keito4/config-base:1.43.0", | ||
| "remoteEnv": { | ||
| "TMPDIR": "/home/vscode/.claude/tmp" | ||
| }, | ||
| "initializeCommand": "mkdir -p ~/.claude", | ||
| "mounts": ["source=${localEnv:HOME}/.claude,target=/home/vscode/.claude,type=bind,consistency=cached"], | ||
| "postCreateCommand": "/usr/local/bin/setup-claude.sh" | ||
| } | ||
| ``` | ||
|
|
||
| `setup-claude.sh` は以下を自動的に行います: | ||
|
|
||
| - リポジトリの `.claude/commands/` を `~/.claude/commands/` にコピー | ||
| - リポジトリの `.claude/plugins/plugins.txt` からプラグインをインストール | ||
|
|
||
| ## イメージのビルドとリリース | ||
|
|
||
| このリポジトリでイメージをビルドする場合: | ||
|
|
||
| ```bash | ||
| # ローカルビルド(認証情報を使用) | ||
| DOCKER_BUILDKIT=1 docker build \ | ||
| --secret id=claude_credentials,src=$HOME/.claude/.credentials.json \ | ||
| -t ghcr.io/keito4/config-base:local \ | ||
| -f .devcontainer/Dockerfile \ | ||
| . | ||
|
|
||
| # GitHub Actions でのビルド(自動) | ||
| # main ブランチへのプッシュで自動的にビルド・リリース | ||
| git push origin main | ||
| ``` | ||
|
|
||
| ## トラブルシューティング | ||
|
|
||
| ### プラグインがインストールされていない | ||
|
|
||
| イメージビルド時に認証情報がない場合、プラグインのインストールがスキップされます。コンテナ起動後に手動でインストールしてください: | ||
|
|
||
| ```bash | ||
| claude plugin install <plugin>@<marketplace> | ||
| ``` | ||
|
|
||
| ### hooks が動作しない | ||
|
|
||
| `setup-claude.sh` を実行してhookifyパッチを適用してください: | ||
|
|
||
| ```bash | ||
| /usr/local/bin/setup-claude.sh | ||
| ``` | ||
|
|
||
| ### 設定が反映されない | ||
|
|
||
| マウント設定により、ホストの `~/.claude` がイメージの内容を上書きしている可能性があります。`postCreateCommand` で `setup-claude.sh` を実行することで、イメージの設定をホスト側にコピーできます。 | ||
|
|
||
| ## 参考情報 | ||
|
|
||
| - [Claude Code ドキュメント](https://github.com/anthropics/claude-code) | ||
| - [DevContainers 仕様](https://containers.dev/) | ||
| - [Docker BuildKit](https://docs.docker.com/build/buildkit/) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env bash | ||
| # ============================================================================ | ||
| # Claude Code Setup Script for Docker Build | ||
| # Dockerビルド時に完全なセットアップを実行 | ||
| # ============================================================================ | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Determine script directory and source libraries | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| LIB_DIR="${SCRIPT_DIR}/../script-lib" | ||
|
|
||
| # Dockerビルド時は /tmp/script-lib を使用 | ||
| if [[ -d "/tmp/script-lib" ]]; then | ||
| LIB_DIR="/tmp/script-lib" | ||
| fi | ||
|
|
||
| # shellcheck source=script/lib/output.sh | ||
| source "$LIB_DIR/output.sh" | ||
| # shellcheck source=script/lib/claude_plugins.sh | ||
| source "$LIB_DIR/claude_plugins.sh" | ||
|
|
||
| CLAUDE_DIR="/home/vscode/.claude" | ||
|
|
||
| main() { | ||
| log_info "Claude Code ビルド時セットアップを開始します..." | ||
|
|
||
| # Claude CLI の存在確認 | ||
| if ! command -v claude &> /dev/null; then | ||
| log_warn "Claude CLI が見つかりません。セットアップをスキップします。" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # プラグインがインストールされているか確認 | ||
| if [[ ! -d "${CLAUDE_DIR}/plugins/marketplaces" ]]; then | ||
| log_warn "プラグインがインストールされていません。" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # hookifyパッチの適用 | ||
| log_info "hookifyプラグインのパッチを適用中..." | ||
| plugins::apply_hookify_patch "$CLAUDE_DIR" | ||
|
|
||
| # known_marketplaces.json の生成 | ||
| if [[ -f "${CLAUDE_DIR}/plugins/known_marketplaces.json.template" ]]; then | ||
| log_info "known_marketplaces.json を生成中..." | ||
| sed "s|{{HOME}}|/home/vscode|g" \ | ||
| "${CLAUDE_DIR}/plugins/known_marketplaces.json.template" \ | ||
| > "${CLAUDE_DIR}/plugins/known_marketplaces.json" | ||
| log_success "known_marketplaces.json を生成しました" | ||
| fi | ||
|
|
||
| # 設定ファイルのパーミッション確認 | ||
| chown -R vscode:vscode "$CLAUDE_DIR" | ||
|
|
||
|
Comment on lines
+54
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Permission error: This script runs as USER vscode (Dockerfile line 102), but the 🔧 Recommended fixOption 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 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 |
||
| log_success "Claude Code ビルド時セットアップが完了しました!" | ||
| } | ||
|
|
||
| main "$@" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 thechowncommand identified insetup-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
This moves the
chownoperation to run as root after the vscode-user script completes, fixing the permission issue while maintaining graceful degradation.📝 Committable suggestion
🤖 Prompt for AI Agents