You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to build Docker Image with Symfony app inside, and this image must meet the following requirements:
Immutable infrastructure, so update of composer, building container, warming up of cache.system cache and other tasks performed during build of Docker image. After building this image filesystem must be for reads only and may run in any environment (dev, staging, prod) with same stuff inside.
Due to immutability, configuration is completely passed by environment variables in runtime so no configuration may be set during build process and no configuration may be stored inside docker image after.
Composer has post-install-cmd which runs after anyinstallation of packages, clears cache and dumps container, if it was not present before call, or removes container if if was before call of cache:clear.
In my case this call will create a fresh container, because i build new image in pipeline where sources was copied without previous container dump.
By default this command also performes warmup of cache, one of cache warmers is doctrine which cached its annotations to cache.system cache and reuery results to cache.app.
Everything was fine, but once upon a time i decided to implement app cache with memcached provider. As we rememeber one of warmers is doctrine which warmups its system configs, due to next config in config/packages/prod/doctrine.yaml:
Now i have a situation during Docker build when installing of composer dependencies starts clearing cache, clearing cache starts warming cache, one of warmers is doctrine which depends on cache.app cache, this cache is now memcached so it requires env variable with DSN which i dont have because i'm inside context of building Docker image.
Moving cache:clear from composer's post-install-cmd to Docker's entrypoint is not a solution because clearing and warming up cache during container start may produce different results and also requires more time to start container (warming oftet takes too long time).
Disable warmers on clearing cache in post-install-cmd by adding cache:clear --no-warmup is not working because when we have first call of cache:clear when container yet not dumped, it dumped by Kernel and this kernel perform warmup unconditionally in \Symfony\Component\HttpKernel\Kernel::initializeContainer:
And aslo this is not a solution because this warmers will be executed in any case in runtime but i want immutable image.
Good solution will be in any required warmers do not depend on any ENV and any features except simple system cache warm. But this warmer \Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer::warmUp try to instantiate to much dependencies in $this->registry->getManagers().
How to reproduce
Configure memcached or any other external cache that requires DSN in env vars as app cache, do not define DSN for memcached to emulate case when it will be passed in runtime outside Docker container
Try to cache:clear when container not dumped (as first installation of framework)
Get error that required memcached env var with DSN empty
Possible Solution
Use class generator without entity manager to prevent instantiation of unnecessary dependencies and use this generator in \Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer::warmUp if this possible?
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Symfony version(s) affected
5.4
Description
I'm trying to build Docker Image with Symfony app inside, and this image must meet the following requirements:
cache.system
cache and other tasks performed during build of Docker image. After building this image filesystem must be for reads only and may run in any environment (dev, staging, prod) with same stuff inside.So, in my Dockerfile i do something like this:
Composer has
post-install-cmd
which runs after anyinstallation of packages, clears cache and dumps container, if it was not present before call, or removes container if if was before call ofcache:clear
.In my case this call will create a fresh container, because i build new image in pipeline where sources was copied without previous container dump.
By default this command also performes warmup of cache, one of cache warmers is doctrine which cached its annotations to
cache.system
cache and reuery results tocache.app
.Everything was fine, but once upon a time i decided to implement
app
cache withmemcached
provider. As we rememeber one of warmers is doctrine which warmups its system configs, due to next config inconfig/packages/prod/doctrine.yaml
:Now i have a situation during Docker build when installing of composer dependencies starts clearing cache, clearing cache starts warming cache, one of warmers is doctrine which depends on
cache.app
cache, this cache is now memcached so it requires env variable with DSN which i dont have because i'm inside context of building Docker image.Moving
cache:clear
from composer'spost-install-cmd
to Docker's entrypoint is not a solution because clearing and warming up cache during container start may produce different results and also requires more time to start container (warming oftet takes too long time).Disable warmers on clearing cache in
post-install-cmd
by addingcache:clear --no-warmup
is not working because when we have first call ofcache:clear
when container yet not dumped, it dumped by Kernel and this kernel perform warmup unconditionally in\Symfony\Component\HttpKernel\Kernel::initializeContainer
:And aslo this is not a solution because this warmers will be executed in any case in runtime but i want immutable image.
Good solution will be in any required warmers do not depend on any ENV and any features except simple system cache warm. But this warmer
\Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer::warmUp
try to instantiate to much dependencies in$this->registry->getManagers()
.How to reproduce
app
cache, do not define DSN for memcached to emulate case when it will be passed in runtime outside Docker containercache:clear
when container not dumped (as first installation of framework)Possible Solution
Use class generator without entity manager to prevent instantiation of unnecessary dependencies and use this generator in \Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer::warmUp if this possible?
Additional Context
No response
The text was updated successfully, but these errors were encountered: