Description
Symfony version(s) affected: 5.2.x
My scenario is that I deploy the an application on a read-only filesystem. Think Bref or Docker. I want to build the application on the CI and then ship it to production as an "image". The production system do have a cache directory /tmp/cache
(absolute, not related to project_dir). This directory is frequently emptied (ie re-deploy the docker images on a new host (Think autoscaling)).
So, on the CI I want to warm up the cache as much as possible to avoid cold starts on the host. I use the build_dir
(#36515) to build the container etc. But some things will not be dumped in the build directory. Like doctrine proxy classes, cache pools, translations, validations, annotations and twig cache. Im not sure if some of these should be in the build dir or not. I guess that some needs to be writable. It does not matter too much if I get a "half cold" application.
My main issue is when I warmup the application on the CI there is a reference between the build_dir
and the cache_dir
. Ie, with ['build_dir' => '%kernel.project_dir%/var/build', 'cache_dir' => '%kernel.project_dir%/var/cache']
, I get a a build directory with references like:
'cache_dir' => (\dirname(__DIR__, 2).'/cache/prod/translations'
This does not really work if I use a different cache dir in production compared to my CI. (Production is using /tmp/cache
). And if I configure to use /tmp/cache
as cache dir on the CI, I will get an error in production because it cache file does not exists.
Ie, it would be fine if both the build_dir
and the cache_dir
was empty, but just to have an empty cache_dir
will case errors like:
> vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:187
Compile Error: require(): Failed opening required '/tmp/cache/prod/doctrine/orm/Proxies/__CG__AppEntitySurveyTemplate.php'
Is the solution to make the files in the build directory to always use %kernel.cache_dir%
to access files in the cache dir?
Could we also make the build directory not assume the cache is available?
Or.. how can I deploy on a true read-only filesystem? Do I need to be more careful on each cache to make sure none is ever written to?