8000 Doctrine's ProxyCacheWarmer requires configured app cache · Issue #46481 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Doctrine's ProxyCacheWarmer requires configured app cache #46481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sokil opened this issue May 27, 2022 · 1 comment
Closed

Doctrine's ProxyCacheWarmer requires configured app cache #46481

sokil opened this issue May 27, 2022 · 1 comment

Comments

@sokil
Copy link
sokil commented May 27, 2022

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:

  • 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.

So, in my Dockerfile i do something like this:

composer install --no-dev --prefer-dist --no-progress --no-interaction && \
composer dump-autoload --no-dev --classmap-authoritative && \
composer dump-env prod

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:

            doctrine.result_cache_pool:
                adapter: cache.app
            doctrine.system_cache_pool:
                adapter: cache.system

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:

protected function initializeContainer()
{
    $container = $this->buildContainer();
    $container->compile();
    //…
    $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
    //…
    if ($this->container->has('cache_warmer')) {
            $preload = array_merge($preload, (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')));
        }

}

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

  1. 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
  2. Try to cache:clear when container not dumped (as first installation of framework)
  3. 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

@sokil sokil added the Bug label May 27, 2022
@sokil sokil changed the title Doctrine Cache Warmer requires configured app cache Doctrine's ProxyCacheWarmer requires configured app cache May 27, 2022
@sokil
Copy link
Author
sokil commented May 27, 2022

Sorry. I have found closed but not resolved issue #24865 so i think there is no clear sulutions, just workarounds, so i also close this :(

@sokil sokil closed this as completed May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0