Skip to content

Commit 23e4e9e

Browse files
takemi-ohamaclaude
andcommitted
fix(container): Codex review 指摘の HIGH/MED 対応
Codex 第二意見レビューで指摘された 4 件に対応: [1.1 HIGH] 公開イメージの定期 re-pull を廃止 docker image inspect の Created はイメージのビルド日時で ローカル pull 日時ではないため、age 比較で再 pull すると 毎回 pull がループする欠陥があった。image-only サービス (build: なし) は不在時のみ pull し、定期再 pull は行わない 方針に変更。「image: のみで定期 pull が必要」というユース ケースが出てきたら別 PR で digest 比較等を実装する。 [1.2 HIGH] DEV_SERVICE_NAME 連動の build に修正 Python 側 _ensure_images() は get_dev_service_name() で対象 サービスを解決していたが、Bash 側 cmd_build は 'docker compose build dev' を固定実行していた。 DEV_SERVICE_NAME != dev なプロジェクトで自動再ビルド経路に 入ると存在しないサービスをビルドしようとして失敗する回帰。 Bash 側を 'docker compose build "${DEV_SERVICE_NAME:-dev}"' に変更してチェックと実行のサービス名解決を整合化。 [1.4 MED] エラーメッセージを build/pull 双方を案内する文面に _ensure_images() 失敗時に常に "devbase container build" を 案内していたが、image-only サービスでは build は不適切。 build と docker pull の両方を案内する文面に変更。 [2.1 MED] cli-reference.md に自動 build/pull 動作を明記 devbase up が条件次第で build/pull を自動実行する旨と、 DEVBASE_IMAGE_MAX_AGE_DAYS 環境変数の存在を追記。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9010cbd commit 23e4e9e

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

bin/devbase

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ cmd_build() {
9292

9393
echo ""
9494
echo "[2/2] Building project image..."
95-
if docker compose build dev "$@"; then
95+
if docker compose build "${DEV_SERVICE_NAME:-dev}" "$@"; then
9696
echo ""
9797
echo "✓ All images built successfully"
9898
else
@@ -126,7 +126,7 @@ cmd_build() {
126126

127127
echo ""
128128
echo "[2/2] Building project image..."
129-
if docker compose build dev "$@"; then
129+
if docker compose build "${DEV_SERVICE_NAME:-dev}" "$@"; then
130130
echo ""
131131
echo "✓ All images built successfully"
132132
else

docs/user/cli-reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ devbase up
101101

102102
- 起動時にスナップショットを自動作成(新世代 or 差分追加)
103103
- `CONTAINER_SCALE` の値に基づいてコンテナ数を決定
104+
- イメージの自動準備:
105+
- `build:` 定義あり、イメージ未存在 → `devbase build` を自動実行
106+
- `build:` 定義あり、イメージが7日以上古い → `devbase build --no-cache` で再ビルド
107+
- `image:` のみ(公開イメージ)、未存在 → `docker pull` を自動実行
108+
- 閾値は `DEVBASE_IMAGE_MAX_AGE_DAYS` 環境変数で上書き可能(既定 7、不正値は警告して既定値)
104109

105110
### `devbase container down`
106111

lib/devbase/commands/container.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ def cmd_up(project_name: str = None, scale: int = None) -> int:
105105

106106
# Pre-check 2: Ensure container images exist
107107
if not _ensure_images():
108-
logger.error("Failed to build container images. Please run 'devbase container build' manually.")
108+
logger.error(
109+
"Failed to ensure container images. "
110+
"Run 'devbase container build' for build-based services, "
111+
"or 'docker pull <image>' for image-only services."
112+
)
109113
return 1
110114

111115
# Pre-step: Auto snapshot(差分世代数ベース世代管理)
@@ -440,9 +444,13 @@ def _ensure_images() -> bool:
440444
- Image missing + image-only (no build:) → run `docker pull`
441445
- Image present and >= threshold days old + has build:
442446
→ rebuild with `--no-cache`
443-
- Image present and >= threshold days old + image-only
444-
→ re-pull
447+
- Image present + image-only → nothing to do
448+
(Created reflects upstream build time, not local pull time, so we
449+
cannot derive a meaningful freshness signal here. Users who want
450+
public images refreshed should run `docker pull` explicitly.)
445451
- Otherwise: nothing to do
452+
453+
Returns True on success or no-op, False on failure.
446454
"""
447455
compose_file = Path('compose.yml')
448456
if not compose_file.exists():
@@ -489,6 +497,11 @@ def _ensure_images() -> bool:
489497
logger.info("Container image '%s' not found, pulling...", image_name)
490498
return _run_pull(image_name)
491499

500+
# Image-only services: 'Created' reflects upstream build time, not
501+
# local pull time, so age-based re-pull is not meaningful. Skip.
502+
if not has_build:
503+
return True
504+
492505
max_age = _image_max_age_days()
493506
age_days = _get_image_age_days(inspect.stdout)
494507
if age_days is None or age_days < max_age:
@@ -498,11 +511,8 @@ def _ensure_images() -> bool:
498511
"Container image '%s' is %d days old (>= %d days threshold)",
499512
image_name, age_days, max_age
500513
)
501-
if has_build:
502-
logger.info("Rebuilding with --no-cache...")
503-
return _run_build(no_cache=True)
504-
logger.info("Re-pulling latest image...")
505-
return _run_pull(image_name)
514+
logger.info("Rebuilding with --no-cache...")
515+
return _run_build(no_cache=True)
506516

507517
except Exception as e:
508518
logger.warning("Error checking image: %s", e)

0 commit comments

Comments
 (0)