Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
557f412
feat(PLAN58): devbase 経由の Compose の有効なプロファイルを devbase が決める (#189)
takemi-ohama Sep 16, 2026
4775a23
feat(PLAN58): フックへ有効なプロファイルを DEVBASE_ACTIVE_PROFILES で伝える (#189)
takemi-ohama Sep 16, 2026
51ed882
feat(PLAN58): プロファイルの起動・停止・一覧を cmd_profile_up / down / list に置く (#189)
takemi-ohama Sep 16, 2026
f13f100
feat(PLAN58): project / container に profile サブコマンドを足す (#189)
takemi-ohama Sep 16, 2026
ebf1caf
feat(PLAN58): devbase list の操作メニューからプロファイルを起動・停止する (#189)
takemi-ohama Sep 16, 2026
0480af1
test(PLAN58): 生成物が profiles と depends_on.required を保つことを固定する (#189)
takemi-ohama Sep 16, 2026
4768f27
docs(PLAN58): profiles でテスト用サーバを後から起動・停止する書き方とコマンドを案内する (#189)
takemi-ohama Sep 16, 2026
928990d
Test: characterize profile status errors and hook environment
takemi-ohama Sep 16, 2026
3de1d4b
Test: characterization — tests/commands/test_container_profile.py
takemi-ohama Sep 16, 2026
baec17f
fix: プロファイル一覧の稼働状況を全プロファイルの ps から数える (#189)
takemi-ohama Sep 16, 2026
f5fd93a
fix: 起動対象の解決を停止前に移し、TUI のプロファイル解決を対象プロジェクトの環境で行う (#189)
takemi-ohama Sep 16, 2026
fe0b1e5
fix: TUI の復元境界で機密の注入履歴も値と同時に戻す (#189)
takemi-ohama Sep 16, 2026
8775d17
docs(PLAN58): 実装中に範囲へ入れた注入履歴の復元を計画へ記録する (#189)
takemi-ohama Sep 16, 2026
bf2cf52
fix(PLAN58): プロファイル解決が空のとき空の選択メニューを出さずサブメニューへ戻る (#189)
takemi-ohama Sep 16, 2026
d08af76
docs(PLAN58): CHANGELOG の Unreleased に profiles の追加を記録する (#189)
takemi-ohama Sep 16, 2026
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
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@

## [Unreleased]

### Added

- **Compose の `profiles` を付けた付随サービス群を、dev コンテナに触れずに後から起動・停止できるように
しました(PLAN58 / #189, #191)。** `devbase up` の既定では dev だけが起動します。
- `devbase project profile up|down [name] <profile>` / `devbase project profile list [name]` を追加しました
(`container` / `ct` にもあります。`[name]` は受け付けません)。起動は `--no-deps` で対象サービスだけを、
停止は `stop` → `rm -f` で行い、名前付きボリュームは残します
- `devbase list` の起動中の行の操作メニューに「テスト用サーバ起動 / 停止」を足しました(プロファイルを
持つプロジェクトだけ)
- `profile up` の後に `deploy` フックを呼び直します。フックは `DEVBASE_ACTIVE_PROFILES` で起動した
プロファイル名を受け取ります(`devbase up` からは空)
- 利用には Docker Compose 2.20.0 以上が要ります(`depends_on.required` のため)。書き方は
`docs/plugin-dev/compose-profiles.md`

### Changed

- `devbase down` と `devbase up` の冒頭の停止は、プロファイルのサービスも止めるようになりました
(`--profile '*'`)。`devbase up` の起動は `profiles` を持たないサービスを名前で明示して起動します
- devbase 経由の `docker compose` には、端末の環境変数やプロジェクトの `.env` の `COMPOSE_PROFILES` が
効かなくなりました(devbase が `__devbase_none__` で上書きします)。素の `docker compose` には影響しません

### Fixed

- `devbase list` から別のプロジェクトを続けて操作すると、最初のプロジェクトにだけある機密が次の
プロジェクトの `docker compose` へ渡ることがあった問題を直しました(#191)

## [3.4.0] - 2026-09-15

機密の保存先に OpenBao を選べるようになりました。起動中の dev コンテナの中からも `bao` で
Expand Down
4 changes: 3 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ graph LR
| [plugin.yml リファレンス](plugin-dev/plugin-yml-reference.md) | プラグイン定義ファイルの全フィールド |
| [compose.yml ガイドライン](plugin-dev/compose-yml-guidelines.md) | Docker Compose 設定のベストプラクティス |
| [repo 連携プロジェクトと pre-up populate](plugin-dev/repo-backed-projects.md) | 外部リポジトリを共有 work ボリュームへ populate する `pre-up` パターンと冪等スキップ |
| [テスト用サーバを後から起動・停止する](plugin-dev/compose-profiles.md) | Compose の `profiles` で付随サービス群を `devbase up` から外し、`devbase project profile` で起動・停止する |

### devbase 開発者(devbase 本体を改善したい方)

Expand Down Expand Up @@ -114,7 +115,8 @@ docs/
│ ├── quickstart.md ← クイックスタート
│ ├── plugin-yml-reference.md ← plugin.yml リファレンス
│ ├── compose-yml-guidelines.md ← compose.yml ガイドライン
│ └── repo-backed-projects.md ← repo 連携 / pre-up populate パターン
│ ├── repo-backed-projects.md ← repo 連携 / pre-up populate パターン
│ └── compose-profiles.md ← profiles でテスト用サーバを後から起動・停止
└── developer/ ← devbase 開発者向け
├── architecture.md ← アーキテクチャ
├── contributing.md ← コントリビューション
Expand Down
111 changes: 111 additions & 0 deletions docs/plugin-dev/compose-profiles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# テスト用サーバを後から起動・停止する(Compose の profiles)

dev のほかに app / db などのサービスを持つプロジェクトで、`devbase up` の既定では dev だけを起動し、テスト用のサーバ群は必要なときだけ後から起動・停止するための書き方です。起動・停止のどちらでも、dev コンテナは再作成も再起動もされません。

## 使える環境

| 項目 | 条件 |
| --- | --- |
| Docker Compose | **2.20.0 以上**。`depends_on` の `required` を使うため。動作を確かめたのは v5.1.4 |
| devbase | `devbase project profile` があるバージョン |

## 1. `compose.yml` の書き方

テスト用のサービスへ `profiles:` を書きます。プロファイル名はプロジェクトが自由に決めてかまいません(devbase は既定の名前を持ちません)。

```yaml
services:
dev:
image: ...
# dev から app への依存を残すなら required: false を付ける
depends_on:
app:
condition: service_started
required: false

app:
image: ...
profiles: [test]
depends_on:
mysql:
condition: service_healthy

mysql:
image: mysql:8
profiles: [test]
```

| 書き方 | 理由 |
| --- | --- |
| `profiles: [test]` | `devbase up` の既定の起動対象から外れる |
| 既定のサービスからプロファイルのサービスへの `depends_on` には `required: false` | 付けないと、既定の `up` が `service "dev" depends on undefined service "app": invalid compose project` で止まる |
| プロファイルのサービスから dev への `depends_on` | どちらの形(`[dev]` / `required: false` 付き)でも書けます。devbase は `--no-deps` で起動するため dev は対象に入りません |

プロファイル名に `__devbase_none__` は使わないでください。devbase が「どのプロファイルも有効にしない」ために予約している名前です。

## 2. コマンド

```bash
devbase project profile list # プロファイルと稼働状況を見る
devbase project profile up test # test のサービスを起動する
devbase project profile down test # test のサービスを停止して削除する(ボリュームは残る)

devbase project profile up carmo test # 任意のディレクトリから carmo の test を起動する
```

`devbase list` で起動中のプロジェクトを選ぶと、操作のメニューに「テスト用サーバ起動 (profile up)」「テスト用サーバ停止 (profile down)」が出ます(プロファイルを持つプロジェクトだけ)。

`profile list` の表は次のとおりです。

```text
PROFILE SERVICES RUNNING
test app,mysql 2/2 running
```

| RUNNING | 意味 |
| --- | --- |
| `2/2 running` | すべて稼働中 |
| `1/2 partial` | 一部だけ稼働中 |
| `0/2 stopped` | 停止中 |
| `不明` | Docker のデーモンへ接続できず、稼働状況を得られなかった |

どのコマンドも、先に `devbase up` を済ませて `.docker-compose.scale.yml` がある状態で使います。

## 3. `devbase up` / `devbase down` との関係

| 操作 | プロファイルのサービス |
| --- | --- |
| `devbase up` | 起動しない。起動していた場合も、冒頭の停止で止まる。**テストを続けるなら `up` の後にもう一度 `profile up` する** |
| `devbase down` | dev と一緒に削除する |
| `devbase scale` | 複製しない(dev だけが増える) |

端末の環境変数やプロジェクトの `.env` に `COMPOSE_PROFILES` を書いても、devbase 経由の操作には効きません。有効なプロファイルは devbase のコマンドで決めます。素の `docker compose` を叩いたときは従来どおり効きます。

## 4. `deploy` フックでの分岐

`devbase project profile up <名前>` は、サービスの起動が終わった後に `deploy` フックを稼働中の全インスタンスについて呼び直します。`pre-up` は呼びません。

フックは `DEVBASE_ACTIVE_PROFILES` で、どの経路から呼ばれたかを見分けられます。

| 呼ばれ方 | `DEVBASE_ACTIVE_PROFILES` |
| --- | --- |
| `devbase up` の `pre-up` / `deploy` | 空 |
| `devbase project profile up test` の `deploy` | `test` |

```bash
#!/bin/bash
# projects/<name>/deploy
if [ "$DEVBASE_ACTIVE_PROFILES" = "test" ]; then
echo "テスト用サーバの初期データを投入する"
exit 0
fi
# 以下は devbase up のときの処理
```

`deploy` が失敗すると `profile up` も 0 以外で終わります。値は常にプロファイル名 1 つです(カンマ区切りは将来の拡張のための予約です)。

## 関連

- [compose.yml ガイドライン](compose-yml-guidelines.md)
- [フックへ渡る環境変数](quickstart.md#フックへ渡る環境変数)
- [`devbase project profile`](../user/cli-reference/02-project.md#devbase-project-profile)
1 change: 1 addition & 0 deletions docs/plugin-dev/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ MY_SECRET_API_KEY=sk-xxxxxxxxxxxx
| `DEVBASE_WORK_DIR` | コンテナ内の既定の作業ディレクトリ(`work_dir`。未指定なら `/work/$DEVBASE_PRIMARY_DIR`) | ✓ | ✓ |
| `DEVBASE_REPO_DIRS` | 全リポジトリのディレクトリ名を `project.yml` の宣言順に空白区切りで並べたもの | ✓ | ✓ |
| `DEVBASE_INSTANCE_INDEX` | 実行対象のインスタンス番号(1 始まり)。`pre-up` はインスタンスごとに実行されないため渡りません | -- | ✓ |
| `DEVBASE_ACTIVE_PROFILES` | 有効な Compose のプロファイル名。`devbase up` からは空、`devbase project profile up <名前>` の後の `deploy` にはその名前([テスト用サーバを後から起動・停止する](compose-profiles.md)) | ✓ | ✓ |

primary は `repos` の先頭(または `primary: true` を付けた 1 件)で、常にちょうど 1 件です。primary 以外も含めて全リポジトリを回したい場合は `DEVBASE_REPO_DIRS` を使います。

Expand Down
24 changes: 23 additions & 1 deletion docs/user/cli-reference/02-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ cd $DEVBASE_ROOT/projects/adminer && devbase project up

## `--context NAME`(共通オプション)

`up` / `down` / `ps` / `logs` / `login` / `scale` / `build` / `rebuild`(`project` /
`up` / `down` / `ps` / `logs` / `login` / `scale` / `build` / `rebuild` / `profile`(`project` /
`container` 配下と、トップレベルのショートカット)は `--context NAME` を受け付けます。
そのコマンドの `docker` / `docker compose` を、指定した docker context の daemon へ向けます。

Expand Down Expand Up @@ -183,6 +183,28 @@ devbase project scale adminer 3

新しい値は `project.yml` の `scale` に書き戻されるため、次回の `devbase up` にも引き継がれます。

## `devbase project profile`

`compose.yml` で `profiles:` を付けたサービス群を、dev コンテナに触れずに後から起動・停止します。
書き方は [テスト用サーバを後から起動・停止する](../../plugin-dev/compose-profiles.md) を参照してください。

```
devbase project profile up [name] <profile> [--context NAME]
devbase project profile down [name] <profile> [--context NAME]
devbase project profile list [name] [--context NAME]
```

| パラメータ | 必須 | 説明 |
|-----------|------|------|
| `name` | いいえ | 対象プロジェクト名(省略時はカレント)。`container profile` / `ct profile` では受け付けません |
| `<profile>` | はい(`up` / `down`) | `compose.yml` に書いたプロファイル名 |

- `up`: そのプロファイルのサービスをすべて `--no-deps` 付きで起動し、`deploy` フックを `DEVBASE_ACTIVE_PROFILES=<profile>` で稼働中の全インスタンスについて呼び直す
- `down`: そのプロファイルのサービスを `stop` → `rm -f` で停止・削除する(ボリュームは残る。フックは呼ばない)
- `list`: `PROFILE` / `SERVICES` / `RUNNING` の表を出す。Docker のデーモンへ接続できないときは `RUNNING` を `不明` にする
- どれも `devbase up` の後(`.docker-compose.scale.yml` がある状態)で使う。無ければ終了コード 1
- `devbase up` の冒頭の停止と `devbase down` は、プロファイルのサービスも止める

## `devbase project migrate-config`

旧 `env` 形式(`GIT_USER` / `GIT_REPO` / `GIT_HOST` / `WORK_DIR` / `CONTAINER_SCALE` /
Expand Down
8 changes: 8 additions & 0 deletions etc/_devbase
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ _devbase() {
'build:Build container images'
'rebuild:Rebuild images without cache (docker compose build --no-cache)'
'list:List projects (NAME / PLUGIN / STATUS)'
'profile:Start / stop compose profile services'
)

container_subcommands=(
Expand All @@ -92,6 +93,7 @@ _devbase() {
'scale:Scale containers online'
'build:Build container images'
'rebuild:Rebuild images without cache (docker compose build --no-cache)'
'profile:Start / stop compose profile services'
)

env_subcommands=(
Expand Down Expand Up @@ -203,6 +205,9 @@ _devbase() {
'--interactive[(compat) interactive selection, default]' \
'-i[(compat) interactive selection, default]'
;;
profile)
_values 'operation' up down list
;;
*)
_describe -t project-commands 'project command' project_subcommands
;;
Expand All @@ -228,6 +233,9 @@ _devbase() {
build)
_arguments '1:image:'
;;
profile)
_values 'operation' up down list
;;
*)
_describe -t container-commands 'container command' container_subcommands
;;
Expand Down
10 changes: 8 additions & 2 deletions etc/devbase-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ _devbase_completions() {

local commands="init status shell-rc project container ct env plugin pl snapshot ss up down login build rebuild ps scale list help"
# project / container は同じサブコマンド群 (container は非推奨だが補完は維持)。
local project_subcommands="up down ps login logs scale build rebuild list"
local container_subcommands="up down ps login logs scale build rebuild"
local project_subcommands="up down ps login logs scale build rebuild list profile"
local container_subcommands="up down ps login logs scale build rebuild profile"
local env_subcommands="init sync list set get delete edit project export import keygen exec encrypt decrypt rekey doctor"
local plugin_subcommands="list install uninstall update info sync repo"
local repo_subcommands="add remove list refresh"
Expand Down Expand Up @@ -126,6 +126,9 @@ _devbase_completions() {
list)
COMPREPLY=($(compgen -W "--no-interactive --plain -P --interactive -i" -- "$cur"))
;;
profile)
COMPREPLY=($(compgen -W "up down list" -- "$cur"))
;;
esac
fi
# container subcommand arguments (非推奨: project へ移行してください)
Expand All @@ -137,6 +140,9 @@ _devbase_completions() {
scale)
COMPREPLY=($(compgen -W "1 2 3 4 5" -- "$cur"))
;;
profile)
COMPREPLY=($(compgen -W "up down list" -- "$cur"))
;;
ps)
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "--all -a" -- "$cur"))
Expand Down
Loading
Loading