From 71437a764cfbf4246c3a5f8ea1a3f2e9cf9cbcbb Mon Sep 17 00:00:00 2001 From: Hugues Tavernier Date: Sat, 20 Jan 2024 09:42:48 +0100 Subject: [PATCH] add worker-mode playground --- playground/worker-mode/.env | 20 +++ playground/worker-mode/.gitignore | 15 ++ playground/worker-mode/Caddyfile | 26 ++++ playground/worker-mode/assets/app.css | 3 + playground/worker-mode/assets/app.js | 3 + playground/worker-mode/bin/console | 17 +++ playground/worker-mode/composer.json | 83 +++++++++++ playground/worker-mode/config/bundles.php | 12 ++ .../worker-mode/config/packages/cache.yaml | 19 +++ .../worker-mode/config/packages/debug.yaml | 5 + .../config/packages/framework.yaml | 25 ++++ .../worker-mode/config/packages/monolog.yaml | 62 ++++++++ .../worker-mode/config/packages/routing.yaml | 12 ++ .../worker-mode/config/packages/twig.yaml | 6 + .../config/packages/web_profiler.yaml | 17 +++ playground/worker-mode/config/preload.php | 5 + playground/worker-mode/config/routes.yaml | 5 + .../config/routes/dev/pentatrion_vite.yaml | 3 + .../worker-mode/config/routes/framework.yaml | 4 + .../config/routes/web_profiler.yaml | 8 ++ playground/worker-mode/config/services.yaml | 24 ++++ playground/worker-mode/package.json | 8 ++ playground/worker-mode/public/index.php | 9 ++ .../worker-mode/src/Controller/.gitignore | 0 .../src/Controller/DefaultController.php | 34 +++++ playground/worker-mode/src/Kernel.php | 11 ++ playground/worker-mode/symfony.lock | 132 ++++++++++++++++++ .../worker-mode/templates/base.html.twig | 23 +++ .../templates/default/page-1.html.twig | 7 + .../templates/default/page-2.html.twig | 7 + .../templates/default/welcome.html.twig | 7 + playground/worker-mode/vite.config.js | 19 +++ 32 files changed, 631 insertions(+) create mode 100644 playground/worker-mode/.env create mode 100644 playground/worker-mode/.gitignore create mode 100644 playground/worker-mode/Caddyfile create mode 100644 playground/worker-mode/assets/app.css create mode 100644 playground/worker-mode/assets/app.js create mode 100755 playground/worker-mode/bin/console create mode 100644 playground/worker-mode/composer.json create mode 100644 playground/worker-mode/config/bundles.php create mode 100644 playground/worker-mode/config/packages/cache.yaml create mode 100644 playground/worker-mode/config/packages/debug.yaml create mode 100644 playground/worker-mode/config/packages/framework.yaml create mode 100644 playground/worker-mode/config/packages/monolog.yaml create mode 100644 playground/worker-mode/config/packages/routing.yaml create mode 100644 playground/worker-mode/config/packages/twig.yaml create mode 100644 playground/worker-mode/config/packages/web_profiler.yaml create mode 100644 playground/worker-mode/config/preload.php create mode 100644 playground/worker-mode/config/routes.yaml create mode 100644 playground/worker-mode/config/routes/dev/pentatrion_vite.yaml create mode 100644 playground/worker-mode/config/routes/framework.yaml create mode 100644 playground/worker-mode/config/routes/web_profiler.yaml create mode 100644 playground/worker-mode/config/services.yaml create mode 100644 playground/worker-mode/package.json create mode 100644 playground/worker-mode/public/index.php create mode 100644 playground/worker-mode/src/Controller/.gitignore create mode 100644 playground/worker-mode/src/Controller/DefaultController.php create mode 100644 playground/worker-mode/src/Kernel.php create mode 100644 playground/worker-mode/symfony.lock create mode 100644 playground/worker-mode/templates/base.html.twig create mode 100644 playground/worker-mode/templates/default/page-1.html.twig create mode 100644 playground/worker-mode/templates/default/page-2.html.twig create mode 100644 playground/worker-mode/templates/default/welcome.html.twig create mode 100644 playground/worker-mode/vite.config.js diff --git a/playground/worker-mode/.env b/playground/worker-mode/.env new file mode 100644 index 00000000..38919718 --- /dev/null +++ b/playground/worker-mode/.env @@ -0,0 +1,20 @@ +# In all environments, the following files are loaded if they exist, +# the latter taking precedence over the former: +# +# * .env contains default values for the environment variables needed by the app +# * .env.local uncommitted file with local overrides +# * .env.$APP_ENV committed environment-specific defaults +# * .env.$APP_ENV.local uncommitted environment-specific overrides +# +# Real environment variables win over .env files. +# +# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. +# https://symfony.com/doc/current/configuration/secrets.html +# +# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). +# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration + +###> symfony/framework-bundle ### +APP_ENV=dev +APP_SECRET=11118f9df5355dbeb6a82c0184000098 +###< symfony/framework-bundle ### diff --git a/playground/worker-mode/.gitignore b/playground/worker-mode/.gitignore new file mode 100644 index 00000000..d1edfbb1 --- /dev/null +++ b/playground/worker-mode/.gitignore @@ -0,0 +1,15 @@ + +###> symfony/framework-bundle ### +/.env.local +/.env.local.php +/.env.*.local +/config/secrets/prod/prod.decrypt.private.php +/public/bundles/ +/var/ +/vendor/ +###< symfony/framework-bundle ### + +###> pentatrion/vite-bundle ### +/node_modules/ +/public/build/ +###< pentatrion/vite-bundle ### diff --git a/playground/worker-mode/Caddyfile b/playground/worker-mode/Caddyfile new file mode 100644 index 00000000..581070f7 --- /dev/null +++ b/playground/worker-mode/Caddyfile @@ -0,0 +1,26 @@ +{ + order php_server before file_server + order php before file_server + + frankenphp { + worker { + file ./public/index.php + env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime + } + } +} + +worker-mode.symfony-vite-dev.localhost { + log { + format console + } + + root * public/ + + encode zstd gzip + + respond /healthz 200 + + file_server browse + php_server +} diff --git a/playground/worker-mode/assets/app.css b/playground/worker-mode/assets/app.css new file mode 100644 index 00000000..3221ce1d --- /dev/null +++ b/playground/worker-mode/assets/app.css @@ -0,0 +1,3 @@ +body { + background-color: #eeeeee; +} diff --git a/playground/worker-mode/assets/app.js b/playground/worker-mode/assets/app.js new file mode 100644 index 00000000..f12aab03 --- /dev/null +++ b/playground/worker-mode/assets/app.js @@ -0,0 +1,3 @@ +import "./app.css"; + +console.log("Happy coding !!"); \ No newline at end of file diff --git a/playground/worker-mode/bin/console b/playground/worker-mode/bin/console new file mode 100755 index 00000000..c933dc53 --- /dev/null +++ b/playground/worker-mode/bin/console @@ -0,0 +1,17 @@ +#!/usr/bin/env php +=8.1", + "ext-ctype": "*", + "ext-iconv": "*", + "pentatrion/vite-bundle": "dev-main", + "runtime/frankenphp-symfony": "^0.2.0", + "symfony/console": "6.4.*", + "symfony/dotenv": "6.4.*", + "symfony/flex": "^2", + "symfony/framework-bundle": "6.4.*", + "symfony/monolog-bundle": "^3.0", + "symfony/runtime": "6.4.*", + "symfony/twig-bundle": "6.4.*", + "symfony/yaml": "6.4.*", + "twig/extra-bundle": "^2.12|^3.0", + "twig/twig": "^2.12|^3.0" + }, + "config": { + "allow-plugins": { + "php-http/discovery": true, + "symfony/flex": true, + "symfony/runtime": true + }, + "sort-packages": true + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "App\\Tests\\": "tests/" + } + }, + "replace": { + "symfony/polyfill-ctype": "*", + "symfony/polyfill-iconv": "*", + "symfony/polyfill-php72": "*", + "symfony/polyfill-php73": "*", + "symfony/polyfill-php74": "*", + "symfony/polyfill-php80": "*", + "symfony/polyfill-php81": "*" + }, + "scripts": { + "auto-scripts": { + "cache:clear": "symfony-cmd", + "assets:install %PUBLIC_DIR%": "symfony-cmd" + }, + "post-install-cmd": [ + "@auto-scripts" + ], + "post-update-cmd": [ + "@auto-scripts" + ] + }, + "conflict": { + "symfony/symfony": "*" + }, + "extra": { + "symfony": { + "allow-contrib": false, + "require": "6.4.*" + } + }, + "repositories": [ + { + "type": "path", + "url": "../../src/vite-bundle" + } + ], + "require-dev": { + "symfony/debug-bundle": "6.4.*", + "symfony/maker-bundle": "^1.52", + "symfony/stopwatch": "6.4.*", + "symfony/web-profiler-bundle": "6.4.*" + } +} diff --git a/playground/worker-mode/config/bundles.php b/playground/worker-mode/config/bundles.php new file mode 100644 index 00000000..52783eea --- /dev/null +++ b/playground/worker-mode/config/bundles.php @@ -0,0 +1,12 @@ + ['all' => true], + Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], + Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], + Pentatrion\ViteBundle\PentatrionViteBundle::class => ['all' => true], + Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], + Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], + Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true], + Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], +]; diff --git a/playground/worker-mode/config/packages/cache.yaml b/playground/worker-mode/config/packages/cache.yaml new file mode 100644 index 00000000..6899b720 --- /dev/null +++ b/playground/worker-mode/config/packages/cache.yaml @@ -0,0 +1,19 @@ +framework: + cache: + # Unique name of your app: used to compute stable namespaces for cache keys. + #prefix_seed: your_vendor_name/app_name + + # The "app" cache stores to the filesystem by default. + # The data in this cache should persist between deploys. + # Other options include: + + # Redis + #app: cache.adapter.redis + #default_redis_provider: redis://localhost + + # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues) + #app: cache.adapter.apcu + + # Namespaced pools use the above "app" backend by default + #pools: + #my.dedicated.cache: null diff --git a/playground/worker-mode/config/packages/debug.yaml b/playground/worker-mode/config/packages/debug.yaml new file mode 100644 index 00000000..ad874afd --- /dev/null +++ b/playground/worker-mode/config/packages/debug.yaml @@ -0,0 +1,5 @@ +when@dev: + debug: + # Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser. + # See the "server:dump" command to start a new server. + dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%" diff --git a/playground/worker-mode/config/packages/framework.yaml b/playground/worker-mode/config/packages/framework.yaml new file mode 100644 index 00000000..980ee45c --- /dev/null +++ b/playground/worker-mode/config/packages/framework.yaml @@ -0,0 +1,25 @@ +# see https://symfony.com/doc/current/reference/configuration/framework.html +framework: + secret: '%env(APP_SECRET)%' + #csrf_protection: true + annotations: false + http_method_override: false + handle_all_throwables: true + + # Enables session support. Note that the session will ONLY be started if you read or write from it. + # Remove or comment this section to explicitly disable session support. + session: + handler_id: null + cookie_secure: auto + cookie_samesite: lax + + #esi: true + #fragments: true + php_errors: + log: true + +when@test: + framework: + test: true + session: + storage_factory_id: session.storage.factory.mock_file diff --git a/playground/worker-mode/config/packages/monolog.yaml b/playground/worker-mode/config/packages/monolog.yaml new file mode 100644 index 00000000..9db7d8a7 --- /dev/null +++ b/playground/worker-mode/config/packages/monolog.yaml @@ -0,0 +1,62 @@ +monolog: + channels: + - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists + +when@dev: + monolog: + handlers: + main: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: debug + channels: ["!event"] + # uncomment to get logging in your browser + # you may have to allow bigger header sizes in your Web server configuration + #firephp: + # type: firephp + # level: info + #chromephp: + # type: chromephp + # level: info + console: + type: console + process_psr_3_messages: false + channels: ["!event", "!doctrine", "!console"] + +when@test: + monolog: + handlers: + main: + type: fingers_crossed + action_level: error + handler: nested + excluded_http_codes: [404, 405] + channels: ["!event"] + nested: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: debug + +when@prod: + monolog: + handlers: + main: + type: fingers_crossed + action_level: error + handler: nested + excluded_http_codes: [404, 405] + buffer_size: 50 # How many messages should be saved? Prevent memory leaks + nested: + type: stream + path: php://stderr + level: debug + formatter: monolog.formatter.json + console: + type: console + process_psr_3_messages: false + channels: ["!event", "!doctrine"] + deprecation: + type: stream + channels: [deprecation] + path: php://stderr + formatter: monolog.formatter.json diff --git a/playground/worker-mode/config/packages/routing.yaml b/playground/worker-mode/config/packages/routing.yaml new file mode 100644 index 00000000..4b766ce5 --- /dev/null +++ b/playground/worker-mode/config/packages/routing.yaml @@ -0,0 +1,12 @@ +framework: + router: + utf8: true + + # Configure how to generate URLs in non-HTTP contexts, such as CLI commands. + # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands + #default_uri: http://localhost + +when@prod: + framework: + router: + strict_requirements: null diff --git a/playground/worker-mode/config/packages/twig.yaml b/playground/worker-mode/config/packages/twig.yaml new file mode 100644 index 00000000..f9f4cc53 --- /dev/null +++ b/playground/worker-mode/config/packages/twig.yaml @@ -0,0 +1,6 @@ +twig: + default_path: '%kernel.project_dir%/templates' + +when@test: + twig: + strict_variables: true diff --git a/playground/worker-mode/config/packages/web_profiler.yaml b/playground/worker-mode/config/packages/web_profiler.yaml new file mode 100644 index 00000000..b9461110 --- /dev/null +++ b/playground/worker-mode/config/packages/web_profiler.yaml @@ -0,0 +1,17 @@ +when@dev: + web_profiler: + toolbar: true + intercept_redirects: false + + framework: + profiler: + only_exceptions: false + collect_serializer_data: true + +when@test: + web_profiler: + toolbar: false + intercept_redirects: false + + framework: + profiler: { collect: false } diff --git a/playground/worker-mode/config/preload.php b/playground/worker-mode/config/preload.php new file mode 100644 index 00000000..5ebcdb21 --- /dev/null +++ b/playground/worker-mode/config/preload.php @@ -0,0 +1,5 @@ +render('default/welcome.html.twig', [ + 'controller_name' => 'DefaultController', + ]); + } + + #[Route('/', name: 'app_page1')] + public function page1(): Response + { + return $this->render('default/page-1.html.twig', [ + 'controller_name' => 'DefaultController', + ]); + } + + #[Route('/', name: 'app_page2')] + public function page2(): Response + { + return $this->render('default/page-2.html.twig', [ + 'controller_name' => 'DefaultController', + ]); + } +} diff --git a/playground/worker-mode/src/Kernel.php b/playground/worker-mode/src/Kernel.php new file mode 100644 index 00000000..779cd1f2 --- /dev/null +++ b/playground/worker-mode/src/Kernel.php @@ -0,0 +1,11 @@ + + + + + {% block title %}Welcome!{% endblock %} + + {% block stylesheets %} + {{ vite_entry_link_tags('app') }} + {% endblock %} + + {% block javascripts %} + {{ vite_entry_script_tags('app') }} + {% endblock %} + + + + {% block body %}{% endblock %} + + diff --git a/playground/worker-mode/templates/default/page-1.html.twig b/playground/worker-mode/templates/default/page-1.html.twig new file mode 100644 index 00000000..3d02b5f0 --- /dev/null +++ b/playground/worker-mode/templates/default/page-1.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block title %}Page 1{% endblock %} + +{% block body %} +

Page 1

+{% endblock %} diff --git a/playground/worker-mode/templates/default/page-2.html.twig b/playground/worker-mode/templates/default/page-2.html.twig new file mode 100644 index 00000000..af6a44e4 --- /dev/null +++ b/playground/worker-mode/templates/default/page-2.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block title %}Page 2{% endblock %} + +{% block body %} +

Page 2

+{% endblock %} diff --git a/playground/worker-mode/templates/default/welcome.html.twig b/playground/worker-mode/templates/default/welcome.html.twig new file mode 100644 index 00000000..65c57351 --- /dev/null +++ b/playground/worker-mode/templates/default/welcome.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block title %}Welcome !{% endblock %} + +{% block body %} +

Welcome

+{% endblock %} diff --git a/playground/worker-mode/vite.config.js b/playground/worker-mode/vite.config.js new file mode 100644 index 00000000..ab4fb8a5 --- /dev/null +++ b/playground/worker-mode/vite.config.js @@ -0,0 +1,19 @@ +import { defineConfig } from "vite"; +import symfonyPlugin from "vite-plugin-symfony"; + +/* if you're using React */ +// import react from '@vitejs/plugin-react'; + +export default defineConfig({ + plugins: [ + /* react(), // if you're using React */ + symfonyPlugin(), + ], + build: { + rollupOptions: { + input: { + app: "./assets/app.js" + }, + } + }, +});