docs: add glossary, ADRs and implementation planUnverified
eab3ea1 added
.gitignore +4 -0 | new file mode 100644 | ||
| @@ -0,0 +1,4 @@ | ||
| 1 | +/vendor/ | |
| 2 | +/composer.lock | |
| 3 | +/.phpunit.cache/ | |
| 4 | +/.php-cs-fixer.cache | |
| new file mode 100644 | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | +/vendor/ | ||
| 2 | +/composer.lock | ||
| 3 | +/.phpunit.cache/ | ||
| 4 | +/.php-cs-fixer.cache | ||
added
GLOSSARY.md +47 -0 | new file mode 100644 | ||
| @@ -0,0 +1,47 @@ | ||
| 1 | +# Scaleway Runtime | |
| 2 | + | |
| 3 | +Symfony Runtime integration that runs PHP applications on Scaleway Serverless Functions. | |
| 4 | + | |
| 5 | +## Language | |
| 6 | + | |
| 7 | +**Invocation**: | |
| 8 | +A single call of the function by Scaleway, carrying one Event and expecting one Function Response. | |
| 9 | +_Avoid_: Request (reserved for the Symfony HTTP request), call, execution | |
| 10 | + | |
| 11 | +**Event**: | |
| 12 | +The array Scaleway passes to the handler, describing an HTTP call or a CRON trigger. | |
| 13 | +_Avoid_: Payload, input | |
| 14 | + | |
| 15 | +**Function Response**: | |
| 16 | +The array returned to Scaleway (status code, headers, body). | |
| 17 | +_Avoid_: Output, result | |
| 18 | + | |
| 19 | +**Handler**: | |
| 20 | +The global `handle($event, $context)` function Scaleway calls for each Invocation. | |
| 21 | +_Avoid_: Entry point, front controller | |
| 22 | + | |
| 23 | +**Front Controller**: | |
| 24 | +The application's unchanged `public/index.php`, returning the closure that builds the Application. | |
| 25 | +_Avoid_: Handler, bootstrap | |
| 26 | + | |
| 27 | +**Application**: | |
| 28 | +The object built by the Front Controller closure (Kernel, PSR-15 handler, Console application, callable). | |
| 29 | +_Avoid_: App, service | |
| 30 | + | |
| 31 | +**Warm Process**: | |
| 32 | +A PHP process that survives between Invocations and keeps the booted Application in memory. | |
| 33 | +_Avoid_: Worker, long-running process | |
| 34 | + | |
| 35 | +**HTTP Invocation**: | |
| 36 | +An Invocation triggered by an HTTP call to the function's endpoint. | |
| 37 | + | |
| 38 | +**CRON Invocation**: | |
| 39 | +An Invocation triggered by a Scaleway CRON trigger, carrying the trigger's configured arguments as body. | |
| 40 | +_Avoid_: Scheduled job, cron task | |
| 41 | + | |
| 42 | +**Command Invocation**: | |
| 43 | +A CRON Invocation whose body names a console command to run instead of an HTTP route. | |
| 44 | + | |
| 45 | +**Emulator**: | |
| 46 | +The local server that turns real HTTP requests into Events and calls the Handler, to run an application without deploying it. | |
| 47 | +_Avoid_: Local runtime, dev server | |
| new file mode 100644 | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | +# Scaleway Runtime | ||
| 2 | + | ||
| 3 | +Symfony Runtime integration that runs PHP applications on Scaleway Serverless Functions. | ||
| 4 | + | ||
| 5 | +## Language | ||
| 6 | + | ||
| 7 | +**Invocation**: | ||
| 8 | +A single call of the function by Scaleway, carrying one Event and expecting one Function Response. | ||
| 9 | +_Avoid_: Request (reserved for the Symfony HTTP request), call, execution | ||
| 10 | + | ||
| 11 | +**Event**: | ||
| 12 | +The array Scaleway passes to the handler, describing an HTTP call or a CRON trigger. | ||
| 13 | +_Avoid_: Payload, input | ||
| 14 | + | ||
| 15 | +**Function Response**: | ||
| 16 | +The array returned to Scaleway (status code, headers, body). | ||
| 17 | +_Avoid_: Output, result | ||
| 18 | + | ||
| 19 | +**Handler**: | ||
| 20 | +The global `handle($event, $context)` function Scaleway calls for each Invocation. | ||
| 21 | +_Avoid_: Entry point, front controller | ||
| 22 | + | ||
| 23 | +**Front Controller**: | ||
| 24 | +The application's unchanged `public/index.php`, returning the closure that builds the Application. | ||
| 25 | +_Avoid_: Handler, bootstrap | ||
| 26 | + | ||
| 27 | +**Application**: | ||
| 28 | +The object built by the Front Controller closure (Kernel, PSR-15 handler, Console application, callable). | ||
| 29 | +_Avoid_: App, service | ||
| 30 | + | ||
| 31 | +**Warm Process**: | ||
| 32 | +A PHP process that survives between Invocations and keeps the booted Application in memory. | ||
| 33 | +_Avoid_: Worker, long-running process | ||
| 34 | + | ||
| 35 | +**HTTP Invocation**: | ||
| 36 | +An Invocation triggered by an HTTP call to the function's endpoint. | ||
| 37 | + | ||
| 38 | +**CRON Invocation**: | ||
| 39 | +An Invocation triggered by a Scaleway CRON trigger, carrying the trigger's configured arguments as body. | ||
| 40 | +_Avoid_: Scheduled job, cron task | ||
| 41 | + | ||
| 42 | +**Command Invocation**: | ||
| 43 | +A CRON Invocation whose body names a console command to run instead of an HTTP route. | ||
| 44 | + | ||
| 45 | +**Emulator**: | ||
| 46 | +The local server that turns real HTTP requests into Events and calls the Handler, to run an application without deploying it. | ||
| 47 | +_Avoid_: Local runtime, dev server | ||
added
docs/adr/0001-handler-drives-runtime-lifecycle.md +9 -0 | new file mode 100644 | ||
| @@ -0,0 +1,9 @@ | ||
| 1 | +# The Handler drives the Runtime lifecycle instead of autoload_runtime.php | |
| 2 | + | |
| 3 | +Scaleway owns the PHP process and calls a global `handle($event, $context)` for each Invocation, while the generated `vendor/autoload_runtime.php` re-includes `$_SERVER['SCRIPT_FILENAME']` and ends with `exit()`. | |
| 4 | +We therefore ship a Handler that instantiates our `RuntimeInterface` itself, resolves the unchanged Front Controller, and delegates each Invocation to the runner, keeping the `RuntimeInterface`/`RunnerInterface` contract and the `extra.runtime` options. | |
| 5 | + | |
| 6 | +## Considered Options | |
| 7 | + | |
| 8 | +- Custom `autoload_template` without `exit`: rejected, still coupled to `SCRIPT_FILENAME`, which Scaleway controls. | |
| 9 | +- Booting the Kernel by hand without the Runtime component: rejected, loses Front Controller portability and runtime options. | |
| new file mode 100644 | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | +# The Handler drives the Runtime lifecycle instead of autoload_runtime.php | ||
| 2 | + | ||
| 3 | +Scaleway owns the PHP process and calls a global `handle($event, $context)` for each Invocation, while the generated `vendor/autoload_runtime.php` re-includes `$_SERVER['SCRIPT_FILENAME']` and ends with `exit()`. | ||
| 4 | +We therefore ship a Handler that instantiates our `RuntimeInterface` itself, resolves the unchanged Front Controller, and delegates each Invocation to the runner, keeping the `RuntimeInterface`/`RunnerInterface` contract and the `extra.runtime` options. | ||
| 5 | + | ||
| 6 | +## Considered Options | ||
| 7 | + | ||
| 8 | +- Custom `autoload_template` without `exit`: rejected, still coupled to `SCRIPT_FILENAME`, which Scaleway controls. | ||
| 9 | +- Booting the Kernel by hand without the Runtime component: rejected, loses Front Controller portability and runtime options. | ||
added
docs/adr/0002-reuse-application-across-invocations.md +8 -0 | new file mode 100644 | ||
| @@ -0,0 +1,8 @@ | ||
| 1 | +# The Application is booted once per Warm Process and reset between Invocations | |
| 2 | + | |
| 3 | +Rebuilding the Kernel on every Invocation makes every call pay the cold-start cost. | |
| 4 | +We boot the Application once per process and call `terminate()` plus the `services_resetter` between Invocations, like FrankenPHP worker mode or RoadRunner; if Scaleway does not keep processes warm, this degrades to a fresh boot per Invocation. | |
| 5 | + | |
| 6 | +## Consequences | |
| 7 | + | |
| 8 | +Applications must be safe for long-running execution (no request state kept in services that are not resettable). | |
| new file mode 100644 | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | +# The Application is booted once per Warm Process and reset between Invocations | ||
| 2 | + | ||
| 3 | +Rebuilding the Kernel on every Invocation makes every call pay the cold-start cost. | ||
| 4 | +We boot the Application once per process and call `terminate()` plus the `services_resetter` between Invocations, like FrankenPHP worker mode or RoadRunner; if Scaleway does not keep processes warm, this degrades to a fresh boot per Invocation. | ||
| 5 | + | ||
| 6 | +## Consequences | ||
| 7 | + | ||
| 8 | +Applications must be safe for long-running execution (no request state kept in services that are not resettable). | ||
added
docs/adr/0003-ship-vendor-and-warm-cache-in-zip.md +4 -0 | new file mode 100644 | ||
| @@ -0,0 +1,4 @@ | ||
| 1 | +# The deployment zip ships vendor/ and a warmed-up cache | |
| 2 | + | |
| 3 | +Scaleway can install Composer dependencies itself at deploy time, which is its documented path. | |
| 4 | +We instead build the zip with `composer install --no-dev -o` and a prod `cache:warmup`, so builds are reproducible and Invocations never pay container compilation on a possibly read-only filesystem. | |
| new file mode 100644 | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | +# The deployment zip ships vendor/ and a warmed-up cache | ||
| 2 | + | ||
| 3 | +Scaleway can install Composer dependencies itself at deploy time, which is its documented path. | ||
| 4 | +We instead build the zip with `composer install --no-dev -o` and a prod `cache:warmup`, so builds are reproducible and Invocations never pay container compilation on a possibly read-only filesystem. | ||
added
docs/plan.md +31 -0 | new file mode 100644 | ||
| @@ -0,0 +1,31 @@ | ||
| 1 | +# Implementation plan | |
| 2 | + | |
| 3 | +Vocabulary follows [GLOSSARY.md](../GLOSSARY.md); decisions are recorded in [docs/adr](adr). | |
| 4 | + | |
| 5 | +## Settled design | |
| 6 | + | |
| 7 | +- Package `jdecool/scaleway-runtime`, namespace `JDecool\ScalewayRuntime`, MIT, PHP >=8.4, Symfony ^7.4 || ^8.0. | |
| 8 | +- Repository: the package at the root, a demo Symfony app in `example/` consuming it through a Composer `path` repository. | |
| 9 | +- The application commits a 3-line `handler.php` stub (generated by `vendor/bin/scaleway-init`); the Scaleway handler setting is `handler.handle`. | |
| 10 | +- The Handler drives `ScalewayRuntime extends SymfonyRuntime` itself, without `vendor/autoload_runtime.php` (ADR 0001). | |
| 11 | +- The Front Controller is the unchanged `public/index.php`; its path is the `front_controller` runtime option (`extra.runtime` or `APP_RUNTIME_OPTIONS`). | |
| 12 | +- The Application is booted once per Warm Process; between Invocations the runtime calls `terminate()` and the `services_resetter`; a failed boot is retried on the next Invocation (ADR 0002). | |
| 13 | +- HTTP mapping: base64 bodies decoded on input; output marked `isBase64Encoded` when the body is not valid UTF-8; multi-value headers sent as arrays; streamed and binary file responses buffered; query string rebuilt from `queryStringParameters`; `X-Forwarded-*` trusted; platform limits documented. | |
| 14 | +- Errors escaping the Application are logged to stderr and returned as a 500 Function Response (generic body, details when `APP_DEBUG=1`). | |
| 15 | +- Cache is warmed at build time; cache and log dirs fall back to `/tmp` when the project dir is not writable; logs go to stderr. | |
| 16 | +- `vendor/bin/scaleway-package` builds a zip with `vendor/` (`--no-dev -o`) and a warmed prod cache, excluding `var/`, `tests/`, `.env.local` (ADR 0003). | |
| 17 | +- CRON Invocations become `POST /` HTTP requests by default; a JSON body `{"command": "...", "args": {...}}` makes it a Command Invocation run through the Console Application of the same Kernel; a non-zero exit code yields a 500 with the command output. | |
| 18 | +- Tests: PHPUnit on conversions, GitHub Actions CI (PHPUnit, PHPStan max, PHP-CS-Fixer; PHP 8.4/8.5 x Symfony 7.4/8.x), local Emulator `vendor/bin/scaleway-serve`, manual real E2E deployed with Terraform. | |
| 19 | + | |
| 20 | +## Phases | |
| 21 | + | |
| 22 | +Each phase ends with green CI checks locally, a commit series, and an independent code review whose findings are addressed before the next phase. | |
| 23 | + | |
| 24 | +1. **Bootstrap**: `composer.json`, directory layout, PHPUnit, PHPStan (max), PHP-CS-Fixer, GitHub Actions matrix, `.gitignore`, `LICENSE`, minimal `README.md`. | |
| 25 | +2. **HttpKernel Application**: `ScalewayRuntime`, Handler bootstrap, Event to `Request` and `Response` to Function Response conversions, runner, reset between Invocations, boot retry, error handling, `front_controller` option, writable dir fallback. | |
| 26 | +3. **Tooling and example**: `scaleway-init`, `scaleway-package`, `scaleway-serve` Emulator, `example/` Symfony app, Terraform for the manual E2E, a probe function measuring the open platform facts (CRON Event shape, multi-value response headers, Warm Process reuse, read-only filesystem, handler path with shipped `vendor/`). | |
| 27 | +4. **Response Application**: a Front Controller returning a Symfony `Response`. | |
| 28 | +5. **PSR-15 Application**: `RequestHandlerInterface` via `symfony/psr-http-message-bridge` and `nyholm/psr7` (suggested dependencies). | |
| 29 | +6. **Console Application and CRON routing**: Command Invocations, Console `Application` / `Command` Front Controllers. | |
| 30 | +7. **Raw callable Application**: `fn(array $event, array $context): array`. | |
| 31 | +8. **Documentation**: full README (install, configure, deploy, limitations), probe results folded into the docs. | |
| new file mode 100644 | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | +# Implementation plan | ||
| 2 | + | ||
| 3 | +Vocabulary follows [GLOSSARY.md](../GLOSSARY.md); decisions are recorded in [docs/adr](adr). | ||
| 4 | + | ||
| 5 | +## Settled design | ||
| 6 | + | ||
| 7 | +- Package `jdecool/scaleway-runtime`, namespace `JDecool\ScalewayRuntime`, MIT, PHP >=8.4, Symfony ^7.4 || ^8.0. | ||
| 8 | +- Repository: the package at the root, a demo Symfony app in `example/` consuming it through a Composer `path` repository. | ||
| 9 | +- The application commits a 3-line `handler.php` stub (generated by `vendor/bin/scaleway-init`); the Scaleway handler setting is `handler.handle`. | ||
| 10 | +- The Handler drives `ScalewayRuntime extends SymfonyRuntime` itself, without `vendor/autoload_runtime.php` (ADR 0001). | ||
| 11 | +- The Front Controller is the unchanged `public/index.php`; its path is the `front_controller` runtime option (`extra.runtime` or `APP_RUNTIME_OPTIONS`). | ||
| 12 | +- The Application is booted once per Warm Process; between Invocations the runtime calls `terminate()` and the `services_resetter`; a failed boot is retried on the next Invocation (ADR 0002). | ||
| 13 | +- HTTP mapping: base64 bodies decoded on input; output marked `isBase64Encoded` when the body is not valid UTF-8; multi-value headers sent as arrays; streamed and binary file responses buffered; query string rebuilt from `queryStringParameters`; `X-Forwarded-*` trusted; platform limits documented. | ||
| 14 | +- Errors escaping the Application are logged to stderr and returned as a 500 Function Response (generic body, details when `APP_DEBUG=1`). | ||
| 15 | +- Cache is warmed at build time; cache and log dirs fall back to `/tmp` when the project dir is not writable; logs go to stderr. | ||
| 16 | +- `vendor/bin/scaleway-package` builds a zip with `vendor/` (`--no-dev -o`) and a warmed prod cache, excluding `var/`, `tests/`, `.env.local` (ADR 0003). | ||
| 17 | +- CRON Invocations become `POST /` HTTP requests by default; a JSON body `{"command": "...", "args": {...}}` makes it a Command Invocation run through the Console Application of the same Kernel; a non-zero exit code yields a 500 with the command output. | ||
| 18 | +- Tests: PHPUnit on conversions, GitHub Actions CI (PHPUnit, PHPStan max, PHP-CS-Fixer; PHP 8.4/8.5 x Symfony 7.4/8.x), local Emulator `vendor/bin/scaleway-serve`, manual real E2E deployed with Terraform. | ||
| 19 | + | ||
| 20 | +## Phases | ||
| 21 | + | ||
| 22 | +Each phase ends with green CI checks locally, a commit series, and an independent code review whose findings are addressed before the next phase. | ||
| 23 | + | ||
| 24 | +1. **Bootstrap**: `composer.json`, directory layout, PHPUnit, PHPStan (max), PHP-CS-Fixer, GitHub Actions matrix, `.gitignore`, `LICENSE`, minimal `README.md`. | ||
| 25 | +2. **HttpKernel Application**: `ScalewayRuntime`, Handler bootstrap, Event to `Request` and `Response` to Function Response conversions, runner, reset between Invocations, boot retry, error handling, `front_controller` option, writable dir fallback. | ||
| 26 | +3. **Tooling and example**: `scaleway-init`, `scaleway-package`, `scaleway-serve` Emulator, `example/` Symfony app, Terraform for the manual E2E, a probe function measuring the open platform facts (CRON Event shape, multi-value response headers, Warm Process reuse, read-only filesystem, handler path with shipped `vendor/`). | ||
| 27 | +4. **Response Application**: a Front Controller returning a Symfony `Response`. | ||
| 28 | +5. **PSR-15 Application**: `RequestHandlerInterface` via `symfony/psr-http-message-bridge` and `nyholm/psr7` (suggested dependencies). | ||
| 29 | +6. **Console Application and CRON routing**: Command Invocations, Console `Application` / `Command` Front Controllers. | ||
| 30 | +7. **Raw callable Application**: `fn(array $event, array $context): array`. | ||
| 31 | +8. **Documentation**: full README (install, configure, deploy, limitations), probe results folded into the docs. | ||