Skip to content

perf: Docker ビルドを高速化(Rust/similarity-ts/不要パッケージ削除) - #637

Merged
keito4 merged 2 commits into
mainfrom
perf/docker-build-optimization
Mar 23, 2026
Merged

perf: Docker ビルドを高速化(Rust/similarity-ts/不要パッケージ削除)#637
keito4 merged 2 commits into
mainfrom
perf/docker-build-optimization

Conversation

@keito4

@keito4 keito4 commented Mar 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Rust ツールチェイン、similarity-ts、不要パッケージを削除しビルド時間を約20分短縮
  • similarity-analysis コマンドにオンデマンドインストールのフォールバックを追加
  • ADR 0003 を作成

Why

arm64 QEMU下での cargo install similarity-ts が20分、Rust toolchain インストールが1-2分かかっていた。similarity-ts は1コマンドでしか使われず、|| true で失敗許容だった。

What

Dockerfile

  • alsa-utils, sox, libasound2-dev, pkg-config, libssl-dev を apt-get から削除
  • rustup, cargo, rustfmt, clippy のインストールを削除
  • RUSTUP_HOME, CARGO_HOME ENV を削除
  • cargo install similarity-ts || true を削除

similarity-analysis.md

  • 実行時に similarity-ts 未インストールなら cargo binstall / cargo install でフォールバック

ADR

  • docs/adr/0003-remove-rust-from-base-image.md を追加

Expected Build Time

Before After Savings
~40min ~20min ~20min

Test plan

  • ビルドが20分以内に完了すること
  • container-security.yml のビルドも成功すること

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Dev container no longer includes Rust/toolchain by default; tool installation is deferred and performed on-demand when running similarity analysis.
    • Similarity analysis now checks for the required tool, installs it if missing, and ensures user-local bin paths are searched for executables.
  • Documentation

    • Added an ADR describing the move to on-demand tooling and the dev environment changes.

arm64 QEMU下での cargo install similarity-ts が20分かかっていた問題を解消。

- similarity-ts をビルドから削除(オンデマンドインストールに変更)
- Rust ツールチェイン(rustup, cargo, rustfmt, clippy)を削除
- 不要パッケージ(alsa-utils, sox, libasound2-dev, pkg-config, libssl-dev)を削除
- similarity-analysis コマンドに未インストール時のフォールバック手順を追加

期待されるビルド時間短縮: 約20分(40分 → 20分)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 09bb3839-88d1-4a0b-a84b-674717166847

📥 Commits

Reviewing files that changed from the base of the PR and between 974ac58 and 88d5b78.

📒 Files selected for processing (2)
  • .devcontainer/Dockerfile
  • script/install-claude-plugins.sh

📝 Walkthrough

Walkthrough

This pull request removes the Rust toolchain from the DevContainer base image, updates PATH handling, moves build-time similarity-ts installation to an on-demand runtime install during the similarity-analysis command (preferring cargo-binstall, falling back to cargo install, with a failing hint if neither are present), and adjusts plugin installer PATH fallbacks.

Changes

Cohort / File(s) Summary
Command Enhancement
.claude/commands/similarity-analysis.md
Split into two steps: pre-check for similarity-ts on PATH with on-demand install logic (prefer cargo-binstall -y, fallback to cargo install, error with Rust hint if neither), then run similarity-ts ${path:-.} --threshold ....
DevContainer Configuration
.devcontainer/Dockerfile
Removed Rust toolchain install and Rust env vars/CARGO_HOME/RUSTUP_HOME, removed audio/build deps (alsa-utils, sox, pkg-config, libssl-dev, libasound2-dev), removed build-time cargo install similarity-ts, adjusted ENV PATH to include $HOME/.local/bin and .claude/local/bin; preserved PNPM and Cursor installer setup.
Installer Script
script/install-claude-plugins.sh
Expanded PATH fallback candidates to include /home/vscode/.local/bin and ${HOME}/.local/bin when prepending candidate bin dirs to PATH.
Architecture Decision
docs/adr/0003-remove-rust-from-base-image.md
New ADR documenting removal of Rust from base image and rationale for runtime/on-demand installation of similarity-ts instead of build-time.
Auxiliary changes
(ENV/.bashrc updates) ...
Updated shell PATH exports to prepend $HOME/.local/bin:$HOME/.claude/local/bin and removed Rust-related PATH/export lines.

Sequence Diagram(s)

sequenceDiagram
  rect rgba(200,200,255,0.5)
    participant User as Developer Shell
    participant Cmd as similarity-analysis cmd
    participant Env as PATH / Shell
    participant Installer as cargo-binstall / cargo
  end

  User->>Cmd: run similarity-analysis
  Cmd->>Env: check for `similarity-ts` on PATH
  alt found
    Env-->>Cmd: `similarity-ts` available
    Cmd->>User: run `similarity-ts ${path:-.} --threshold ...`
  else not found
    Cmd->>Installer: attempt `cargo-binstall -y similarity-ts`
    alt cargo-binstall success
      Installer-->>Cmd: installed binary
      Cmd->>User: run `similarity-ts ${path:-.} --threshold ...`
    else cargo-binstall fail
      Cmd->>Installer: attempt `cargo install similarity-ts`
      alt cargo install success
        Installer-->>Cmd: installed binary
        Cmd->>User: run `similarity-ts ${path:-.} --threshold ...`
      else both missing
        Cmd->>User: error -> hint to install Rust toolchain
      end
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

released

Poem

🐰
I hopped through PATHs both near and far,
hid Rust in the image, kept the runtime star.
When similarity calls, I fetch it anew —
quick paws, small footprint, a one-off brew. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main optimization: Docker build performance improvement by removing Rust, similarity-ts, and unnecessary packages, matching the changeset focus.
Description check ✅ Passed The description follows the template structure with Summary, Why, What, and checklist sections, providing clear rationale and detailed change documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/docker-build-optimization

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.

@keito4 keito4 self-assigned this Mar 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 974ac587a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +33 to +35
cargo binstall similarity-ts -y
elif command -v cargo &>/dev/null; then
cargo install similarity-ts

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Permit cargo commands for on-demand similarity-ts install

This new fallback branch invokes cargo binstall / cargo install, but this command’s frontmatter still only allows Bash(similarity-ts:*) (plus git/gh). In a fresh image where similarity-ts is no longer preinstalled, /similarity-analysis now depends on this path and will fail under the tool allowlist before installation can happen. Please add the necessary Bash allowlist entries (at least cargo and the check command) so the fallback can actually execute.

Useful? React with 👍 / 👎.

@claude

claude Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

コードレビュー

全体的に、ビルド時間を大幅に短縮するための合理的なアプローチです。

良い点

  • ADR の作成: docs/adr/0003-remove-rust-from-base-image.md で意思決定の背景・理由・影響を明確に記録している
  • ビルド時間の改善: arm64 QEMU 下でのボトルネック(cargo install 約20分)を正確に特定し排除
  • 段階的フォールバック: cargo-binstallcargo install → エラーの順で適切に対応している
  • PR 説明の充実: Before/After の比較表・変更内容・テスト計画が明確

懸念点・改善提案

1. pkg-config / libssl-dev の削除(リスク: 中)

pkg-configlibssl-dev は Rust ビルド依存として削除されていますが、他の npm native addon でも必要になる可能性があります。

ADR では「build-essential は npm native addon のビルドに使用される可能性があるため残置」とありますが、libssl-dev についても同様の考慮が必要です。現在のグローバル npm パッケージの中に OpenSSL バインディングを必要とするものがないか確認を推奨します。

2. similarity-analysis.md のフォールバック(リスク: 低)

Rust が未インストールの場合のエラーメッセージにインストールコマンドが案内されていますが、ユーザーが次のアクションを取りやすいよう選択肢を提示するか、ドキュメントへのリンクを追加するとより UX が向上します。現状の「案内のみ」でも十分ではあります。

3. alsa-utils / sox / libasound2-dev の削除

これらは音声関連のパッケージです。ADR または PR 説明に「これらのパッケージは何のために追加されていたか・なぜ今回削除して問題ないか」の説明があると将来の参照に役立ちます。ADR の Context セクションに「alsa/sox パッケージは過去に追加されたが現在使用されていない」旨を追記することを提案します。

マイナーな指摘

cargo install similarity-ts || true の削除に伴い、その RUN ステートメントは curl https://cursor.com/install -fsS | bash のみになっています。cursor install が失敗した場合のハンドリングが明示されていない点は元からの問題ですが、このPRで意図的に変更するなら言及があると良いです。

総評

設計判断は適切で、ADR による記録も CLAUDE.md の「非自明なアーキテクチャ変更には ADR を作成する」方針に沿っています。

マージ前に確認推奨:

  1. libssl-dev 削除による影響(グローバル npm パッケージへの影響)
  2. Docker ビルドが実際に成功し、/similarity-analysis コマンドが初回実行時に正常にインストール・動作することの確認

CI の Trivy Container Scan / Generate SBOM が pending のため、それらが pass してからマージを推奨します。

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.claude/commands/similarity-analysis.md:
- Around line 25-41: The fallback install script for similarity-ts conflicts
with the command allowlist and the devcontainer image: update the allowlist
entries (where Bash(git:*), Bash(gh:*), Bash(similarity-ts:*) are defined) to
permit cargo and cargo-binstall commands, AND add Rust/Cargo to the base image
in the .devcontainer/Dockerfile (or alternatively remove the automatic fallback
and document Rust/Cargo and cargo-binstall as manual prerequisites in
similarity-analysis.md); locate the installation check block (the similarity-ts
install conditional) and either enable the installer commands in the allowlist
and add the toolchain to the Dockerfile, or replace the on-demand install with a
clear manual preflight note in the docs.

In @.devcontainer/Dockerfile:
- Around line 120-121: Replace the Dockerfile base image from
mcr.microsoft.com/devcontainers/base:2.0-ubuntu-24.04 to
ghcr.io/keito4/config-base:latest, and harden the Cursor installer RUN step by
enabling shell pipefail for the pipeline (e.g., use set -o pipefail before or
within the RUN that executes the curl | bash) so download failures propagate and
the build fails instead of being masked; update the RUN that invokes the Cursor
installer and the PATH export line accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 044d71a3-05a3-4640-8cf3-2f0124686254

📥 Commits

Reviewing files that changed from the base of the PR and between 5d84b99 and 974ac58.

📒 Files selected for processing (3)
  • .claude/commands/similarity-analysis.md
  • .devcontainer/Dockerfile
  • docs/adr/0003-remove-rust-from-base-image.md

Comment on lines +25 to +41
1. **similarity-ts のインストール確認**

similarity-ts が未インストールの場合、オンデマンドでインストールします:

```bash
if ! command -v similarity-ts &>/dev/null; then
echo "similarity-ts が未インストールです。インストールを開始します..."
if command -v cargo-binstall &>/dev/null; then
cargo binstall similarity-ts -y
elif command -v cargo &>/dev/null; then
cargo install similarity-ts
else
echo "Rust ツールチェインが必要です: curl -sSf https://sh.rustup.rs | sh"
exit 1
fi
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 | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's check if the file exists and read the full context
git ls-files | grep -E "similarity-analysis|Dockerfile|README" | head -20

Repository: keito4/config

Length of output: 562


🏁 Script executed:

# Read the similarity-analysis.md file to check front matter and code
cat -n .claude/commands/similarity-analysis.md | head -50

Repository: keito4/config

Length of output: 1751


🏁 Script executed:

# Check the Dockerfile for Rust/Cargo presence
cat -n .devcontainer/Dockerfile

Repository: keito4/config

Length of output: 10922


The new fallback cannot execute in the default devcontainer.

Line 3 restricts Claude Code to Bash(git:*), Bash(gh:*), and Bash(similarity-ts:*), but this fallback invokes cargo-binstall and cargo, which violate the allowlist. Additionally, the base image in .devcontainer/Dockerfile does not include Rust or Cargo, so the fallback lands in the error branch rather than installing on-demand. Either widen the allowlist to permit the installer commands and add Rust/Cargo to the base image, or document this as a manual prerequisite instead of an automatic fallback.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/similarity-analysis.md around lines 25 - 41, The fallback
install script for similarity-ts conflicts with the command allowlist and the
devcontainer image: update the allowlist entries (where Bash(git:*), Bash(gh:*),
Bash(similarity-ts:*) are defined) to permit cargo and cargo-binstall commands,
AND add Rust/Cargo to the base image in the .devcontainer/Dockerfile (or
alternatively remove the automatic fallback and document Rust/Cargo and
cargo-binstall as manual prerequisites in similarity-analysis.md); locate the
installation check block (the similarity-ts install conditional) and either
enable the installer commands in the allowlist and add the toolchain to the
Dockerfile, or replace the on-demand install with a clear manual preflight note
in the docs.

Comment thread .devcontainer/Dockerfile
Comment on lines +120 to 121
RUN curl https://cursor.com/install -fsS | bash \
&& echo 'export PATH="$HOME/.local/bin:$PATH"' >> /home/vscode/.bashrc

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

🧩 Analysis chain

🏁 Script executed:

grep -n "^FROM\|^SHELL" .devcontainer/Dockerfile | head -20

Repository: keito4/config

Length of output: 117


🏁 Script executed:

sed -n '75,90p' .devcontainer/Dockerfile | cat -n

Repository: keito4/config

Length of output: 689


🏁 Script executed:

sed -n '115,125p' .devcontainer/Dockerfile | cat -n

Repository: keito4/config

Length of output: 519


🏁 Script executed:

grep -n "^SHELL\|^ENV SHELL" .devcontainer/Dockerfile

Repository: keito4/config

Length of output: 79


Fix base image and add pipefail to the Cursor installer pipeline.

Lines 120-121 run the Cursor installer via pipeline without pipefail, so transient download failures can be masked. Additionally, the Dockerfile violates the .devcontainer/** guideline, which requires base image ghcr.io/keito4/config-base:latest instead of mcr.microsoft.com/devcontainers/base:2.0-ubuntu-24.04.

🔧 Proposed fixes

Update the base image:

-FROM mcr.microsoft.com/devcontainers/base:2.0-ubuntu-24.04
+FROM ghcr.io/keito4/config-base:latest

Add pipefail to the Cursor installer:

-RUN curl https://cursor.com/install -fsS | bash \
+RUN bash -o pipefail -c 'curl -fsS https://cursor.com/install | bash' \
     && echo 'export PATH="$HOME/.local/bin:$PATH"' >> /home/vscode/.bashrc
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.devcontainer/Dockerfile around lines 120 - 121, Replace the Dockerfile base
image from mcr.microsoft.com/devcontainers/base:2.0-ubuntu-24.04 to
ghcr.io/keito4/config-base:latest, and harden the Cursor installer RUN step by
enabling shell pipefail for the pipeline (e.g., use set -o pipefail before or
within the RUN that executes the curl | bash) so download failures propagate and
the build fails instead of being masked; update the RUN that invokes the Cursor
installer and the PATH export line accordingly.

native installer は ~/.claude/local/bin ではなく ~/.local/bin に
バイナリを配置するため、プラグインインストール時に claude が
見つからなかった。両方のパスを PATH に追加。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@keito4
keito4 merged commit 15e29b4 into main Mar 23, 2026
19 checks passed
@keito4
keito4 deleted the perf/docker-build-optimization branch March 23, 2026 09:56
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.106.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released リリース済み label Mar 23, 2026
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