Skip to content

issue109: 必須の環境変数が全 docker compose コマンドで必要な点を明記し .env による指定を案内する - #110

Draft
tichi73 wants to merge 5 commits into
developfrom
feature/issue109-compose-env-docs
Draft

issue109: 必須の環境変数が全 docker compose コマンドで必要な点を明記し .env による指定を案内する#110
tichi73 wants to merge 5 commits into
developfrom
feature/issue109-compose-env-docs

Conversation

@tichi73

@tichi73 tichi73 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #109

背景

外部DBシングル構成 (single/extdb) で docker compose pull が以下のエラーで停止する、という問い合わせがあった。

error while interpolating x-required-db-env.DATABASE_URL: required variable DATABASE_URL is missing a value: ...

2026/07/10 リリースで導入した :? による必須化 (#98) が原因。docker compose は変数展開を compose ファイル読み込み時に一括で実施するため、up だけでなく pull / config / down / ps / logs などすべてのサブコマンドで発火する (pull が接続先に接続しているわけではなく、ファイルのパース段階で停止している)。ドキュメントはいずれも up の文脈でしか説明しておらず、README 自身の手順どおりに進めても必ずエラーになっていた。

変更内容

1. .env による指定を主手順にした (c5a614c / 2b288ff)

コマンドごとの前置き指定は実運用で現実的でないため、セットアップ手順の先頭で .env を用意する流れに改めた。以降の pull / up -d / down は素のコマンドのままでよい。

.env の書式説明は Docker Compose v2.29.2 での実挙動を確認して記述している。シェルではなく compose が解釈するため、コマンド前置きでの指定とは扱いが異なる。

.env の記述 展開結果
DATABASE_URL=pgsql://u:pa$ss@h:5432/db pgsql://u:pa@h:5432/db ($ss が変数参照として展開される)
DATABASE_URL=pgsql://u:pa$$ss@h:5432/db $ はエスケープされて維持
DATABASE_URL='pgsql://u:pa$ss@h:5432/db' クオートは除去され $ は維持
DATABASE_URL=pgsql://u:p@h:5432/db # comment 空白 + # 以降はコメントとして無視

2. cluster/swarmDATABASE_URL 必須化を取り止めた (e9ae9f3)

本構成では setup_stack.sh が要否判定 (未指定なら DATABASE_HOST から既定値を組み立て、いずれも無ければエラー停止) を行なった上で docker-swarm.yml を生成する。compose ファイル側の :? はこれと重複しており、README の環境変数表の記述 (「未指定時は DATABASE_HOST からデフォルト値を構築します」) とも矛盾していた。また docker stack deploy には用いない docker compose pull まで停止させていた。

x-required-db-env と 3 サービスの <<: マージを削除し、#98 以前の状態に戻した。

extdb / jobmngrd で必須を維持したのは、未指定時のフォールバック先が内部コンテナ (postgres / rabbitmq) で、これらの構成には存在しないため。黙って起動すると名前解決エラーで kengine が再起動ループに入り、原因の分かりにくい失敗になる。

3. :? のエラーメッセージを改善した (26ac0f3)

README を読まずにコマンドを実行した場合、このメッセージが唯一の導線になるため、値の例だけでなく (1) up 以外でも必要であること (2) .env に書けば以後不要になること (3) Environment.md への誘導を含めた。

$ docker compose pull
error while interpolating x-required-db-env.DATABASE_URL: required variable DATABASE_URL is missing a value:
DATABASE_URL must be set. It is required by every docker compose command (pull, config, up, down, ...),
not only up. Recommended - write it in the .env file in this directory
(e.g. DATABASE_URL=pgsql://user:password@host:5432/dbname). See Environment.md for details

動作確認

環境変数・.env なしの状態で docker compose config -q / docker compose pull を実行:

構成 結果
ke2/single/extdb 改善後のメッセージでエラー停止
ke2/extra/jobmngrd 同上 (AMQP_URL)
ke2/cluster/swarm 通過 (緩和後。従来はエラー停止)
ke2/single/basic 通過

あわせて確認した項目:

  • .env 作成後、extdb / jobmngrd で追加指定なしに config -q が通ること
  • SHARED_DIR=... ./setup_stack.shdocker-swarm.yml を生成でき、既定で DATABASE_URL=pgsql://kompira:kompira@host.docker.internal:9999/kompiraDATABASE_HOST=10.20.0.100 指定時に ...@10.20.0.100:9999/kompira になること (README の記述どおり)
  • .envgit check-ignore で除外されること

補足

Copilot AI 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.

Pull request overview

This PR addresses issue #109 by clarifying that required environment variables in certain Docker Compose configurations are evaluated at compose-file load time, so they are needed for all docker compose subcommands (e.g., pull, config, down), and by recommending .env files as the primary way to provide them.

Changes:

  • Add a new “環境変数の指定方法” section to Environment.md, documenting required variables and .env behavior/pitfalls.
  • Update single/extdb and extra/jobmngrd READMEs to introduce .env setup before docker compose pull, and move per-command env examples into a “参考” section.
  • Relax cluster/swarm by removing compose-level DATABASE_URL required checks and relying on setup_stack.sh validation; also ignore .env files via .gitignore.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ke2/single/extdb/README.md Reorders setup to create .env first; explains “all subcommands need env” and adds a non-.env reference section.
ke2/single/extdb/docker-compose.override.yml Improves required-var message for DATABASE_URL and documents why it affects all compose commands.
ke2/extra/jobmngrd/README.md Reorders setup to create .env first; adds guidance and a non-.env reference section for AMQP_URL.
ke2/extra/jobmngrd/docker-compose.override.yml Improves required-var message for AMQP_URL and documents load-time interpolation behavior.
ke2/cluster/swarm/docker-compose.override.yml Removes compose-level DATABASE_URL requirement and adds rationale comments.
Environment.md Adds consolidated documentation for required env vars and recommended .env usage, including parsing/escaping caveats.
ChangeLog Records the documentation change and the swarm requirement relaxation for #109.
.gitignore Ignores .env and .env.bak.* repository-wide to prevent accidental secret commits.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ke2/cluster/swarm/docker-compose.override.yml Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

ke2/single/extdb/README.md:128

  • カスタマイズ例のコマンドが DATABASE_URL の指定を含まないため、このセクションだけを参照して実行すると必須変数未指定でエラーになります(.env に設定済みである前提が明示されていません)。
この構成では、外部データベースへの接続情報として `DATABASE_URL` の指定が **必須** です(未指定の場合は `pull` を含むすべての docker compose コマンドがエラー停止します)。その他の環境変数は各構成で共通のため、[Environment.md](../../../Environment.md) を参照してください。カスタマイズした環境変数も `.env` に記述しておくことができます。

カスタマイズ例:

    $ AMQP_PASSWORD='strong-pw' KOMPIRA_LOG_DIR=/var/log/kompira docker compose up -d

tichi73 added 4 commits July 29, 2026 11:34
本構成では setup_stack.sh が DATABASE_URL の要否判定 (未指定なら DATABASE_HOST
から既定値を組み立て、いずれも無ければエラー停止) を行なった上で docker-swarm.yml
を生成するため、compose ファイル側の必須化は重複しており、README の環境変数表の
記述 (未指定時は DATABASE_HOST から構築) とも矛盾していた。また docker stack
deploy には用いない docker compose pull まで停止させていた。
README を読まずにコマンドを実行した場合、このメッセージが唯一の導線になる
ため、値の例だけでなく (1) up 以外のコマンドでも必要であること (2) .env に
書けば以後の指定が不要になること (3) Environment.md への誘導を含める。
- 必須の環境変数 (DATABASE_URL / AMQP_URL) が pull を含む全 docker compose
  コマンドで必要である点の明記、.env による指定方法の案内、エラーメッセージ
  の改善について追記
- cluster/swarm の DATABASE_URL 必須化を取り止めた件について追記
@tichi73
tichi73 force-pushed the feature/issue109-compose-env-docs branch from bc719f6 to 820ca41 Compare July 29, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants