Skip to content
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

Flex structure #7115

Draft
wants to merge 82 commits into
base: master
Choose a base branch
from
Draft

Flex structure #7115

wants to merge 82 commits into from

Conversation

yguedidi
Copy link
Contributor

@yguedidi yguedidi commented Dec 12, 2023

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Documentation no
Translation no
CHANGELOG.md no
License MIT

This PR is initiated from the work on #6850 as it needed the some files to be updated from their updated version from Flex recipes, namely the framework-bundle, console and phpunit-bridge recipes.

So I decided to extract that update in a separate PR, but instead of updating just the files the other PR needed, partially taking the content from the recipe, I decided that it could be the opportunity to embrasse the new Flex structure, and update completely the files from above listed recipes, and all this without yet using Flex itself!

As I want this to be accepted in a minor version of wallabag, so that we can advance on upgrading to Symfony 5, I did my best to make the changes in a backward compatible way!
What I mean by "BC way"?
I covered by this (draft) BC policy the case of users using wallabag "as is", not customizing its code or something else, just configure the parameters requested during the setup and that's it.
And I want them to be able to upgrade their wallabag instance to the new minor, is it setup by the Docker, a git clone, or via ZIP file.

So I identified those critical pieces that must stay so that an upgrade setup continues to work:

  • parameters.yml file, contains the configuration
  • parameters.yml.dist file, model used to generate the configuration
  • web/ folder, used as document root by server configuration
  • app.php file, used as index file by server configuration
  • app_dev.php files, maybe used by server configuration, shouldn't be used in prod!
  • var/logs/ folder configured to be writable
  • var/cache/ folder configured to be writable
  • var/sessions/ folder configured to be writable
  • AppCache.php file as maybe app.php was altered to use it
  • AppKernel.php file as used by app.php and app_dev.php

Leaving those elements should keep a setup working, even if wallabag internals change!

It may look like a very big PR, 62 commits, 188 files changed, +989 lines −786 lines... but I don't think it is!
I did my best to tell a story, showing the path I went through to achieve the goal, with baby steps.
This means that even if they are lot of commits, each should be a very easy to review!
So you guessed it, the recommended way to review this is commit by commit, open each in a new tab.
One important thing: I did my best to keep tests green at each commit!
Hope those efforts will really help reviewing this PR :)

I'm opening this PR as draft but it's not, it's just that there are some fixup commits that don't make sense on their own that I'd like to squash before merge, but are there to highlight some minor changes that are needed by the commit they fix to make it work.
Those changes would have been hard to catch if done directly along other changes of the commit they fix.

I will go through the commits and add some commit related comments to add more details.

Next steps:

  • move to use env vars with a BC layer using the env(MY_VAR): '%my_var%' fallback syntax
  • move to no bundle pattern for app code
  • install Flex and update configs based on recipes
  • check what new configuration we can take from recipes

@@ -25,3 +24,4 @@ imports:
- { resource: ../../config/packages/twig.yaml }
- { resource: ../../config/packages/validator.yaml }
- { resource: ../../config/packages/wallabag.yaml }
- { resource: ../../config/services.yaml }
Copy link
Contributor Author

@yguedidi yguedidi Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load services after packages: this move is done because it's the way the new Kernel will load them

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Wallabag\Kernel;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to use Wallabag as root namespace instead of the default App one.

_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
WebProfilerBundle:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the bundle name here as done in the recipe, I applied this pattern for other routes move, as there is no chances that the bundle name is used as a route name, so no conflicts

@@ -27,7 +27,7 @@
<name>{{ user }}</name>
</author>
<icon>{{ asset('favicon.ico') }}</icon>
<logo>{{ asset('bundles/wallabagcore/themes/_global/img/logo-square.png') }}</logo>
<logo>{{ asset('img/logo-square.png') }}</logo>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really sure about this one to be honest, but it looks it was broken before as there is no themes/_global/img/logo-square.png in CoreBundle

@@ -4,6 +4,7 @@ imports:
- { resource: parameters_addons.yaml }

parameters:
env(APP_SECRET): '%secret%'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the trick to preserve BC! if the APP_SECRET env var is not set, it will use the value from the %secret% parameter!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a pure copy of the one from dev config, as the test config was extending from dev one, but there one this monolog config and a single setting that needed to be added, so no more extending from dev

@@ -1,5 +1,6 @@
framework:
profiler:
only_exceptions: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comes from the dev config

@@ -1,3 +1,6 @@
imports:
- { resource: parameters_test.yaml }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed so tests get parameters test values to override defaults ones from normal parameters.yml, as we're not using env vars (yet)

@@ -0,0 +1,6 @@
###> symfony/framework-bundle ###
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even not installed with Flex, used this syntax so Flex is ready to identify those places when we will install it and update recipes

@@ -0,0 +1,6 @@
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=CHANGE_ME_TO_SOMETHING_SECRET_AND_RANDOM
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

being here it means dev setup will use the env var, so this needs to be updated.
maybe I should remove it? kept it because it impacts only dev setup, not prod ones

session:
# handler_id set to null will use default session handler from php.ini
handler_id: session.handler.native_file
save_path: "%kernel.project_dir%/var/sessions/%kernel.environment%"
cookie_secure: auto
fragments: ~
http_method_override: true
cookie_samesite: lax
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one I decide to keep it as it's security related

@@ -0,0 +1,3 @@
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should remove some deprecation :)

Comment on lines +48 to +54
# App\:
# resource: '../src/'
# exclude:
# - '../src/DependencyInjection/'
# - '../src/Entity/'
# - '../src/Kernel.php'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kept this as a model for later

#php_errors:
# log: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented as was not in our config

web/app.php Outdated
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
require __DIR__ . '/../public/index.php';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the trick that keeps BC, keeping the app.php file but internally using the new index one.
small BC break here is for users who have altered their app.php file to use the AppCache, now they'll need to alter the index.php to use CacheKernel.
see https://symfony.com/doc/4.4/http_cache.html#symfony-reverse-proxy

I think it's acceptable as I don't think users do that, maybe I'm wrong

@yguedidi yguedidi force-pushed the flex-structure branch 3 times, most recently from 0e9ff13 to 9aead7c Compare December 12, 2023 20:45
@yguedidi yguedidi requested review from j0k3r, nicosomb, Kdecherf and a team December 12, 2023 20:47
@Kdecherf Kdecherf added Ready for review topic: technical Issues and pull requests without user impact labels Dec 13, 2023
@yguedidi yguedidi added this to the 2.8.0 milestone Dec 25, 2023
@yguedidi yguedidi force-pushed the flex-structure branch 2 times, most recently from 23082dc to 70c02e8 Compare January 14, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: technical Issues and pull requests without user impact Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants