出现问题是因为当各种 Symfony 命令在 composer 安装过程和/或您自己的命令(例如assetic:dump)结束时运行时,缓存被填充在ondeck环境中。
解决方案是在部署的最后一个命令清除缓存,并指定--no-warmup来停止 Symfony 自动重新填充它,这样当环境从ondeck移动到current时,缓存是空的。在我的.ebextensions/symfony.config我有:
container_commands:
01_migrate:
command: php app/console doctrine:migrations:migrate --env=prod --no-debug --no-interaction
leader_only: true
02_dumpassets:
command: php app/console assetic:dump --env=prod --no-debug
99_clearcache:
command: php app/console cache:clear --env=prod --no-debug --no-warmup
它没有很好的文档记录,但您也可以在环境移动到current后使用部署后挂钩来预热缓存。同样在.ebextensions/symfony.config:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/01-cachewarm.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
. /opt/elasticbeanstalk/support/envvars
cd $EB_CONFIG_APP_CURRENT
php app/console cache:warmup --env=prod --no-debug