fix(build): devbase build <image> の単体ビルドを動くようにする - #144
Merged
Merged
Conversation
`devbase build <image>` は位置引数が剥がされないまま shell の cmd_build へ 流れ、`docker buildx build ... <context> <image>` と PATH が 2 つになって 必ず失敗していた (#139)。 - bin/devbase の build dispatch で位置引数を検出し、`--expires` と同じく Python の project build へ振り分ける。既定 / --no-cache / --project-no-cache は従来どおり shell の cmd_build のまま - 単体ビルドを container._build_single_image() として抽出し、タグを devbase-<image>:latest に、コマンドを docker buildx build --load に揃える。 接頭辞なしのタグは他 Dockerfile の FROM devbase-base:latest から解決できず、 ビルドしても使われなかった - 振り分けを Python 側へ寄せたのは、逆向きにすると wrapper 冒頭の name 解決を 通ってしまい、containers/ と projects/ に同名がある場合 (bi-tools) に devbase project build が別のものをビルドするため - bin/devbase の引数解釈に回帰テストを追加 (実プロセス起動 + スタブ) - ルーティングの注記とドキュメントを実態へ追従 範囲外として起票: #141 (CI が pytest を実行していない)、 #142 (<image> と実在プロジェクト名の衝突) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9tinzTAbF1LVEYvfUgzKx
takemi-ohama
commented
Sep 2, 2026
takemi-ohama
left a comment
Contributor
Author
There was a problem hiding this comment.
🤖 cross-review | round 1 | codex | APPROVE
修正を要する指摘はありません。
takemi-ohama
commented
Sep 2, 2026
takemi-ohama
left a comment
Contributor
Author
There was a problem hiding this comment.
🤖 cross-review | round 1 | gemini | REQUEST_CHANGES
PR の設計と実装を確認しました。単体ビルドが正常に動作するようになり、引数振り分けの無限再帰も _run_build がフラグのみを渡すため発生しないことを確認しました(PR 補足 2)。また、Docker イメージ名は - から始まらないため、-* をフラグとする分類も安全です(PR 補足 1)。
1 点、PR 補足 3 で質問されていたタグの二重付与回避(removeprefix)について、ディレクトリ名とタグの対応が 1:1 にならず衝突する構造的なリスクがあるためインラインで指摘しました。修正をご検討ください。
`removeprefix('devbase-')` を外し、タグを `containers/` 配下のディレクトリ名から
一意に導くようにした。接頭辞を剥がすと `containers/xxx` と `containers/devbase-xxx`
が同じ `devbase-xxx:latest` を取り合い、別ディレクトリなのに互いのイメージを
上書きする衝突リスクがあったため。
`devbase build devbase-base` のように接頭辞込みで渡した場合は、既存の存在確認で
`containers/devbase-base` を探して見つからず、探したパスを示して終了コード 1 で
終わる。黙って別のイメージを作るより明確な挙動になる。
テストは接頭辞の二重付与を禁じるものから、ディレクトリ名とタグの 1:1 対応
(`xxx` と `devbase-xxx` でタグが衝突しない)を固定するものへ書き換えた。
ドキュメントも同じ趣旨へ追従させた。
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V9tinzTAbF1LVEYvfUgzKx
takemi-ohama
commented
Sep 2, 2026
takemi-ohama
left a comment
Contributor
Author
There was a problem hiding this comment.
🤖 cross-review | round 2 | codex | COMMENT
実装仕様と同一 PR 内の実装計画を一致させてください。
takemi-ohama
commented
Sep 2, 2026
takemi-ohama
left a comment
Contributor
Author
There was a problem hiding this comment.
🤖 cross-review | round 2 | gemini | APPROVE
PR の目的(単体ビルドの修正と Python / shell 間の適切な振り分け)が的確に実装されており、追加されたテストも AC をよく網羅しています。全体として非常にクリーンな変更です。
一点だけ、パス操作の堅牢性に関するマイナーな提案をインラインに残しました。
PR #144 のレビュー指摘 2 件に対応する。 - `_build_single_image` の先頭で `image` が `containers/` 配下の 1 ディレクトリ名として妥当か検証する。`/` `\` `..` 空文字などを弾き、 `DEVBASE_ROOT` の外を指すパスや Docker タグとして不正な名前を 渡させない。弾いた場合は理由を logger.error に出して 1 を返し、 docker は起動しない。 - `issues/PLAN49_build-image-argument.md` の Task 1 と決定 3 を、 round 2 で確定した「タグはディレクトリ名から一意に導き `devbase-` 接頭辞は剥がさない」仕様へ更新し、「受け入れ条件の変更」節へ 旧記述の取り消し線付きで理由と日付を追記する。 - 不正な image 名の拒否と実在ディレクトリ名の受理をテストで固定する。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9tinzTAbF1LVEYvfUgzKx
レビューで方針が変わった際に、改訂前の説明 (接頭辞なしでは解決できない) と 改訂後の説明 (接頭辞を剥がさない) が並んで残っていた。1 つにまとめる。 振る舞いは変えない。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9tinzTAbF1LVEYvfUgzKx
- docs/developer/architecture.md: build の振り分けを現在の実装へ更新した。 「build だけが Bash 側に残っている」という記述は、<image> と --expires が Python 経路になった今は誤り。引数ごとの層と実体、単体ビルドのタグ規約、 期限判定の経路が再帰しない理由を表と本文で示す - CHANGELOG.md: Unreleased の Fixed へ #139 を追加 - issues/PLAN49_build-image-argument.md を issues/old/ へ移動 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9tinzTAbF1LVEYvfUgzKx
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
devbase build <image>が必ず失敗する不具合 (#139) を修正します。位置引数が剥がされないまま shell のcmd_buildへ流れ、docker buildx build ... <context> <image>と PATH が 2 つになっていました。設計は #143 でレビュー済みです。詳細は
issues/PLAN49_build-image-argument.mdを参照してください。関連 Issue
<image>と実在プロジェクト名の衝突)変更点
1. wrapper が位置引数を Python へ振り分ける(
bin/devbase)build)dispatch のループで-始まりでない引数を<image>として拾い、--expiresと同じくrun_python project buildへ渡します。既定 /--no-cache/--project-no-cacheは従来どおり shell のcmd_build(devbase-baseの 2 段ビルド)のままです。Python 側へ寄せた理由: 逆向き(Python が
bash bin/devbase build <image>を呼ぶ)にすると、bin/devbase冒頭の name 解決を通ってしまい、projects/bi-toolsとcontainers/bi-toolsが両方実在するためdevbase project build bi-toolsが別のものをビルドします。現在project buildの位置引数が name 解決の対象外であることで守られている挙動を壊さないためです。2. 単体ビルドを抽出しタグとビルダを直す(
lib/devbase/commands/container.py)cmd_buildの単体ビルド部分を_build_single_image()へ抽出し、次を直しました。base:latestdevbase-base:latestdocker builddocker buildx build --load接頭辞なしのタグは他の Dockerfile の
FROM devbase-base:latestから解決できず、ビルドしても使われませんでした。containers/配下 10 件すべてがdevbase-<name>規約で参照されていることを確認済みです。devbase-baseと接頭辞込みで渡されても二重に付けません。これにより
devbase build <image>/devbase project build <image>/devbase container build <image>が同じ実装へ届き、単体ビルドのdocker呼び出しは 1 箇所だけになります。3. 回帰テスト(
tests/cli/test_build_image_argument.py、新規 16 件)bin/devbaseは ShellCheck しか CI が見ておらず、引数解釈の回帰を防ぐテストがありませんでした。tests/cli/test_project_name_resolution.pyと同じスタブ方式でbin/devbaseを実プロセス起動し、振り分け先を固定しています。4. 注記とドキュメントの追従
cli.py/container.pyの「build は shell へ委譲する」という注記を実態(<image>と--expiresは Python、それ以外は shell)へ更新し、docs/user/cli-reference/02-project.mdに単体ビルドが作るタグと、プロジェクト名との衝突時の逃げ道を追記しました。互換性
devbase project build <image>/devbase container build <image>が作るタグが<image>:latestからdevbase-<image>:latestへ変わります。旧タグはリポジトリ内のどこからも参照されておらず(grepで確認済み)FROM devbase-*を解決できないため、移行措置は設けていません。動作確認
uv run pytest tests/cli/test_build_image_argument.py -quv run pytest tests/ -qshellcheck --severity=error bin/devbaseruff check --select=E9,F63,F7,F82 libpython -m compileall -q lib bin/bash -n bin/devbasebuildの 4 経路すべての振り分け先をテストで固定)docs/) を更新した./bin/devbase --helpが正常に動作する未検証: 実 docker でのビルド。テストは
subprocess.runをスタブ化しているため、実際にdevbase-base:latestが作られ他 Dockerfile のFROMから解決できることは確認していません。リリース後テストで実施します。スクリーンショット・ログ(任意)
補足
レビューでは特に次を見ていただきたいです。
build)dispatch の振り分け条件。-*をフラグ、それ以外を<image>とする分類で漏れがないか_run_build(Python → shell)と新しい振り分け(shell → Python)で再帰しないこと。_run_buildは位置引数を渡さないため shell 側へ入る、という前提が正しいかremoveprefix('devbase-')で避けている点。containers/devbase-xxxのような名前が将来できたときの扱い