Docker環境でのテンプレート開発を改善する - #6712
Conversation
docker-compose.override.yml is automatically loaded by Docker Compose and is intended for local developer customizations. Ignoring it in git prevents accidental commits of local-only settings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 Walkthroughウォークスルーこのプルリクエストは、環境変数 変更内容
推定コードレビュー工数🎯 2 (Simple) | ⏱️ ~15 分 詩
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Provides a sample override file for developers who want to mount plugin/template directories individually for local development. Copy to docker-compose.override.yml and customize as needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Provides a pre-configured override file that automatically mounts plugin and template directories into the Docker container, so local changes are reflected immediately without restarting the container. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.3 #6712 +/- ##
============================================
+ Coverage 78.65% 78.80% +0.14%
- Complexity 6824 6825 +1
============================================
Files 476 476
Lines 27078 27711 +633
============================================
+ Hits 21299 21838 +539
- Misses 5779 5873 +94
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
When ECCUBE_TEMPLATE_CODE is set as a process environment variable (e.g., via Docker), writing to .env has no effect because process env vars take precedence over .env in Symfony. Display a warning message after saving to inform the user that the change will not be applied. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Allows developers to control the active template via the ECCUBE_TEMPLATE_CODE environment variable. Defaults to "default". Change the value and run docker compose restart to switch templates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Clearer name that conveys the purpose: syncing locally developed plugins and templates into the Docker container in real time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ove plugin volumes Plugin development does not require the same workaround because plugin state is stored in the database (named volume), not in .env. The file is now focused solely on template development. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The previous check (getenv('ECCUBE_TEMPLATE_CODE')) was incorrect.
The real cause is that index.php skips loading .env when APP_ENV is
already set as an environment variable (e.g., via Docker), making
admin panel template changes ineffective.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Explain why .env is not loaded in Docker (APP_ENV is set) - Document how to set ECCUBE_TEMPLATE_CODE via project root .env - Clarify that 'up -d' is required (not restart) when changing templates Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When APP_ENV is set as an environment variable (e.g., in Docker), index.php previously skipped loading .env entirely, making it impossible to switch templates via the admin panel. With this change, .env is loaded using createImmutable()->safeLoad() when APP_ENV is already set, so variables not defined in the Docker environment (such as ECCUBE_TEMPLATE_CODE) are read from .env. Existing Docker environment variables are not overridden. This enables template switching via the admin panel in Docker without requiring a container restart. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Now that index.php loads .env even when APP_ENV is set, template switching via the admin panel works without requiring a dedicated compose file or container restart. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Since index.php now loads .env even when APP_ENV is set, the warning should only appear when ECCUBE_TEMPLATE_CODE is explicitly set as a process environment variable (e.g., via Docker), which prevents .env changes from taking effect. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@index.php`:
- Around line 36-40: The code currently uses
Dotenv::createImmutable(__DIR__)->safeLoad(), but createImmutable does not
include PutenvAdapter so values won't be visible via getenv() (used by
TemplateController to read ECCUBE_TEMPLATE_CODE); change the call to use
Dotenv::createUnsafeImmutable(__DIR__)->safeLoad() so the loaded .env values are
exposed to getenv() while still not overwriting existing env vars.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d97261df-ff03-4721-836a-866c1bae2d35
📒 Files selected for processing (4)
index.phpsrc/Eccube/Controller/Admin/Store/TemplateController.phpsrc/Eccube/Resource/locale/messages.en.yamlsrc/Eccube/Resource/locale/messages.ja.yaml
✅ Files skipped from review due to trivial changes (2)
- src/Eccube/Resource/locale/messages.en.yaml
- src/Eccube/Resource/locale/messages.ja.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Eccube/Controller/Admin/Store/TemplateController.php
ECCUBE_TEMPLATE_CODE がプロセス環境変数として設定されている場合(Docker 環境など)に 警告メッセージが表示されることを確認するテストを追加する。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@kurozumi |
PR EC-CUBE#6712 の `Dotenv::createImmutable($dir)->safeLoad()` 追加後, CI の dockerbuild (admin01) が一貫して 500 になっていた. 原因は `createImmutable` の既定の immutability check が `ApacheAdapter / EnvConstAdapter / ServerConstAdapter` のみで, `PutenvAdapter` を含まないこと. CI の Apache 環境では: - Apache の `PassEnv` は `APP_ENV APP_DEBUG TRUSTED_PROXIES TRUSTED_HOSTS` のみで `DATABASE_URL` を渡していない → `$_SERVER['DATABASE_URL']` 未設定 - PHP の `variables_order` が既定値 (`GPCS`) で `E` を含まない → `$_ENV['DATABASE_URL']` 未設定 - `getenv('DATABASE_URL')` だけが Docker から渡された postgres URL を保持 この状態で `createImmutable` の immutability check は「既存値なし」と判定し, `.env` の `DATABASE_URL=sqlite:///var/eccube.db` を `$_SERVER` / `$_ENV` に 書き込んでしまう. Symfony の `EnvVarProcessor` は `$_SERVER` を最優先で読むため, 本来の postgres ではなく SQLite に接続してしまい, `no such table: dtb_base_info` で 500 を引き起こしていた. `RepositoryBuilder::createWithDefaultAdapters()->addAdapter(PutenvAdapter::class)` で putenv 由来の値も既存値として尊重するように修正する. - vlucas/phpdotenv v5.6.3 の挙動で確認 - 最小再現で OLD/NEW の差分検証済み (OLD は $_SERVER を sqlite で上書き, NEW は上書きしない) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
PR EC-CUBE#6712 の `Dotenv::createImmutable($dir)->safeLoad()` 追加後, CI の dockerbuild (admin01) が全 PHP バージョンで一貫して 500 になっていた. 原因は vlucas/phpdotenv の `createImmutable` のデフォルト adapter が `ApacheAdapter / EnvConstAdapter / ServerConstAdapter` のみで `PutenvAdapter` を含まないこと. 失敗経路 (CI Apache 環境): - Apache の `PassEnv` は `APP_ENV APP_DEBUG TRUSTED_PROXIES TRUSTED_HOSTS` のみで `DATABASE_URL` を渡していない → `$_SERVER['DATABASE_URL']` 未設定 - PHP の `variables_order` 既定値 (`GPCS`) は `E` を含まない → `$_ENV['DATABASE_URL']` 未設定 - `getenv('DATABASE_URL')` だけが Docker 由来の postgres URL を保持 この状態で `createImmutable` の immutability check は「既存値なし」と判定し `.env` の `DATABASE_URL=sqlite:///var/eccube.db` を `$_SERVER` / `$_ENV` に 書き込んでしまう. Symfony の `EnvVarProcessor` は `$_SERVER` を最優先で読むため 本来の postgres ではなく SQLite に接続し, `no such table: dtb_base_info` で 500 を引き起こしていた. `RepositoryBuilder::createWithDefaultAdapters()->addAdapter(PutenvAdapter::class)` で putenv 由来の値も既存値として尊重するように修正する. - vlucas/phpdotenv v5.6.3 の挙動で確認 - 最小再現スクリプトで OLD/NEW の差分検証済み Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
背景
Docker 環境でテンプレートをアップロードして適用しようとしても反映されないという問題があります。
原因
管理画面のテンプレート切り替えは
.envにECCUBE_TEMPLATE_CODEを書き込む仕組みになっています。しかしindex.phpはAPP_ENVが環境変数として設定されている場合、.envを一切読み込みません。Docker 環境では
docker-compose.ymlでAPP_ENV: "dev"を設定しているため、.envが読み込まれず、管理画面からテンプレートを切り替えても反映されません。変更内容
1.
index.phpの修正APP_ENVが設定されている場合でも.envを読み込むように変更しました。createImmutable()->safeLoad()を使用するため、Docker で設定済みの環境変数は上書きしません。これにより管理画面からテンプレートを切り替えると
.envにECCUBE_TEMPLATE_CODEが書き込まれ、次のリクエストから反映されます。Docker の再起動は不要です。2.
TemplateControllerに警告を追加ECCUBE_TEMPLATE_CODEがプロセス環境変数として明示的に設定されている場合(createImmutableでは上書きできないため.envの変更が反映されない)、管理画面に警告を表示します。影響範囲
APP_ENVが設定されていない既存の環境には影響ありませんAPP_ENVが設定されている環境では.envが追加で読み込まれますが、既存の環境変数は上書きされません🤖 Generated with Claude Code
Summary by CodeRabbit
リリースノート
新機能
ECCUBE_TEMPLATE_CODEが設定されている場合に警告メッセージを表示するようになりました。環境変数が設定されている場合は、.envファイルの変更は適用されず、環境変数の更新が必要です。改善
.envファイルの読み込みロジックを改善しました。外部で設定された環境変数を保持しながら、.envファイルの値を活用できるようになりました。