EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.09k stars 1.02k forks source link

Route definitions in read-only file systems #6303

Open dschoschu opened 5 months ago

dschoschu commented 5 months ago

Describe the bug On our system we use Debian packages to deploy our software. So we try to use the Debian file system structure as much as possible. As a result we have changed the cache, build and log directory of our Symfony application. In a standard Symfony application the build and cache directory are mostly the same. Our cache directory lives in /var/cache/... and our build directory lives together with the source code in /usr/share/... which is considered read-only (written only from the content of Debian packages). Our application does not have any write permissions in /usr/share/....

We use EasyAdmin in version 4.10.1 and encountered a problem with the route definitions which live in var/cache/easyadmin. This file is generated by the CacheWarmer during the build process in the pipeline but does use the cache directory instead of the build directory by default. Even though routing definition should not change after deployment.

Our workaround is a decorated CacheWarmer which uses the build directory if defined. Additionally, the AdminContextFactory service definition is overridden by a compiler pass to change the cache directory in the first argument to the build directory.

I am not sure whether the change to use the build directory instead of the cache directory is considered a breaking change. If the build directory is not explicitly configured, Symfony uses the cache directory by default. If it is, then this could be an issue for the next major release.

To Reproduce Configure a separate build directory with no write permissions for the web application itself.

Additional context

128) "{\"message\":\"Uncaught PHP Exception RuntimeException: \\"The name of the route associated to \\"Application\\Controller\\DashboardController::index\\" cannot be determined. Clear the application cache to run the EasyAdmin cache warmer, which generates the needed data to find this route.\\" at AdminContextFactory.php line 89\",\"context\":{\"exception\":{\"class\":\"RuntimeException\",\"message\":\"The name of the route associated to \\"Application\\Controller\\DashboardController::index\\" cannot be determined. Clear the application cache to run the EasyAdmin cache warmer, which generates the needed data to find this route.\",\"code\":0,\"file\":\"/usr/share/application/app/vendor/easycorp/easyadmin-bundle/src/Factory/AdminContextFactory.php:89\"}},\"level\":500,\"level_name\":\"CRITICAL\",\"channel\":\"request\",\"datetime\":\"2024-05-22T15:50:50.258683+02:00\",\"extra\":{\"uid\":\"4729330\"}}\n"

javiereguiluz commented 4 months ago

@dschoschu do you think we should change EasyAdmin code to use the build directory? I haven't looked much into this. Do you think it would be easy to use the build dir first and fall back to the cache dir? Would it break anything for folks not using readonly filesystems? Thanks!

dschoschu commented 4 months ago

In my opinion? Yes.

I think it should be relatively easy to use the build directory here. It should not break anything for the folks not using a readonly filesystem. Currently the default value in the kernel for the build dir is the value of the cache for so no change should occur on the setups not using a read only filesystem. Only the setups that have reconfigured the build dir to an separate directory will see a change as the route definitions are then found in the new directory.

Here the symfony docs for the build dir option https://symfony.com/doc/current/reference/configuration/kernel.html

Also relevant could be https://symfony.com/blog/new-in-symfony-6-4-build-dir-improvements as it outlines Symfonys plans to use this directory more.