Skip to content

feat(wb): pass the project's declared env vars into Docker containers#1115

Merged
exKAZUu merged 1 commit into
mainfrom
feat-docker-fnox-env
Jul 26, 2026
Merged

feat(wb): pass the project's declared env vars into Docker containers#1115
exKAZUu merged 1 commit into
mainfrom
feat-docker-fnox-env

Conversation

@exKAZUu

@exKAZUu exKAZUu commented Jul 26, 2026

Copy link
Copy Markdown
Member

背景

fnox 移行後、Docker イメージにはアプリの環境変数が焼き込まれません(fnox の秘密情報を復号する age 鍵をコンテナへ持ち込むことは禁止されているため)。その結果、wb が起動する docker runwb start --mode docker など)は環境変数を一切持たないコンテナを立ち上げ、最初に必要になった値で失敗します。WillBooster/survey-system の fnox 移行(WillBooster/survey-system#538)で判明しました。

変更

  • docker run に、プロジェクトが宣言している環境変数それぞれの --env <KEY> を渡します。名前のみを渡すため、値は wb 自身の環境から docker が引き継ぎ、コマンドライン(ps 出力や CI ログ)には現れません。
  • NODE_ENVPORT はイメージ側が所有するため除外します(公開ポートのマッピングはイメージのポートを指しており、fnox 以前も焼き込まれた .env より Dockerfile の ENV が優先されていました)。
  • Project#declaredEnvKeys を追加。env はプロセス環境をマージしてしまうため、プロジェクト自身が宣言した変数を区別できません。
  • selectFnoxSourcedKeysrailwayEnv.ts から utils/envSources.ts へ移動(project.ts からコマンドモジュールを import しないため)。

docker build には何も渡していません: ビルド引数はイメージ履歴に残るため、秘密情報を焼き込まないためです。

テスト

  • selectContainerEnvKeys のユニットテストを追加。
  • survey-system(fnox 移行済み、.env を焼き込まない Dockerfile)で、ローカルビルドした wb が生成する docker run --env <NAME> ... を実行し、コンテナが prisma のマイグレーション・シードを完了して HTTP 200 を返すことを確認しました。wb start --mode docker が生成するコマンド文字列も期待どおり(PORTNODE_ENV は除外)です。

Since fnox replaced .env files, an image no longer bakes the app configuration —
the age key that decrypts fnox secrets must never enter a container — so a
`docker run` started by wb (e.g. `wb start --mode docker`, `wb test --e2e
docker`) came up with no environment variables at all and crashed on the first
value it needed.

`docker run` now receives `--env <KEY>` for every variable the project declares,
passing names only so the values are forwarded from wb's own environment instead
of appearing in argv (`ps` output, CI logs). NODE_ENV and PORT are excluded
because the image owns them: the published port mapping targets the image's port,
and before fnox the baked .env files lost to the Dockerfile's `ENV` values too.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request extracts selectFnoxSourcedKeys into a shared utility file packages/wb/src/utils/envSources.ts and introduces a declaredEnvKeys getter on the Project class to retrieve environment variables declared by the project. Additionally, it updates the Docker run script generation to forward these declared environment variables into the container, excluding image-owned variables (NODE_ENV, PORT) and undefined values, and adds corresponding unit tests. There are no review comments, so I have no feedback to provide.

@exKAZUu
exKAZUu merged commit 4e6611e into main Jul 26, 2026
7 checks passed
@exKAZUu
exKAZUu deleted the feat-docker-fnox-env branch July 26, 2026 09:44
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.

1 participant