Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ COPY --chown=vscode:vscode .claude/commands /home/vscode/.claude/commands
COPY --chown=vscode:vscode .claude/agents /home/vscode/.claude/agents
COPY --chown=vscode:vscode .claude/hooks /home/vscode/.claude/hooks
COPY --chown=vscode:vscode .claude/plugins/plugins.txt /home/vscode/.claude/plugins/plugins.txt
COPY --chown=vscode:vscode .claude/plugins/known_marketplaces.json.template /home/vscode/.claude/plugins/known_marketplaces.json.template
COPY --chown=vscode:vscode script/install-claude-plugins.sh /tmp/install-claude-plugins.sh
COPY --chown=root:root script/setup-claude.sh /usr/local/bin/setup-claude.sh
RUN chmod +x /usr/local/bin/setup-claude.sh
COPY --chown=vscode:vscode script/setup-claude-build.sh /tmp/setup-claude-build.sh
COPY --chown=vscode:vscode script/lib /tmp/script-lib
RUN chmod +x /usr/local/bin/setup-claude.sh /tmp/setup-claude-build.sh

# Install Claude plugins using BuildKit secret
# Build with: DOCKER_BUILDKIT=1 docker build --secret id=claude_credentials,src=$HOME/.claude/.credentials.json .
Expand All @@ -95,6 +98,11 @@ RUN --mount=type=secret,id=claude_credentials,uid=0,gid=0 \
) \
&& chown -R vscode:vscode /home/vscode/.claude

# ビルド時にClaude設定を完全にセットアップ
USER vscode
RUN bash /tmp/setup-claude-build.sh || echo "[WARN] ビルド時セットアップに失敗しました"
USER root
Comment on lines +101 to +104

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 | 🟠 Major

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/.claude

This 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.

Suggested change
# ビルド時に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.


RUN chsh -s /bin/bash vscode

RUN echo 'source ~/.bashrc' >> /home/vscode/.bash_profile \
Expand Down
178 changes: 178 additions & 0 deletions docs/using-config-base-image.md
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/)
59 changes: 59 additions & 0 deletions script/setup-claude-build.sh
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

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

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/.claude

Option 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.

log_success "Claude Code ビルド時セットアップが完了しました!"
}

main "$@"