Implementation plan
Vocabulary follows GLOSSARY.md; decisions are recorded in docs/adr.
Settled design
- Package
jdecool/scaleway-runtime, namespaceJDecool\ScalewayRuntime, MIT, PHP >=8.4, Symfony ^7.4 || ^8.0. - Repository: the package at the root, a demo Symfony app in
example/requiring it from Packagist,composer link-runtimeadding apathrepository on the fly for local work and CI. - The application commits a 3-line
handler.phpstub (generated byvendor/bin/scaleway-init); the Scaleway handler setting ishandler.handle. - The Handler drives
ScalewayRuntime extends SymfonyRuntimeitself, withoutvendor/autoload_runtime.php(ADR 0001). - The Front Controller is the unchanged
public/index.php; its path is thefront_controllerruntime option (extra.runtimeorAPP_RUNTIME_OPTIONS). - The Application is booted once per Warm Process; between Invocations the runtime calls
terminate()and theservices_resetter; a failed boot is retried on the next Invocation (ADR 0002). - A Front Controller returning a Response is called for every Invocation, a
Requestargument receiving the Invocation's Request (ADR 0004). - A Front Controller returning a PSR-15
RequestHandlerInterfaceis built once like a Kernel and served throughsymfony/psr-http-message-bridge(suggested, withnyholm/psr7); the PSR-7 request carries the client the runtime resolved in its server params (REMOTE_ADDR,HTTPS,HTTP_HOST,SERVER_PORT) and URI; a handler implementingResetInterfaceis reset before every Invocation but the first. - HTTP mapping: base64 bodies decoded on input; output marked
isBase64Encodedwhen the body is not valid UTF-8; multi-value headers sent as arrays; streamed and binary file responses buffered; query string rebuilt fromqueryStringParameters; no proxy trusted, the client taken fromX-Real-Ip, the scheme fromX-Forwarded-Protoand the host from thehostruntime option (SCALEWAY_HOST,localhostby default), as clients can forge the other forwarding headers and noHostreaches the function (ADR 0007); platform limits documented. - Errors escaping the Application are logged to stderr and returned as a 500 Function Response (generic body, details when
APP_DEBUG=1). - The Handler runs
prodwhen the process environment sets noAPP_ENV, whatever the shipped.envsays, and the Emulatordev(ADR 0006);APP_RUNTIME_MODEdefaults toweb=1&worker=1, so error pages use the web renderer. - Scaleway installs the dependencies at deploy time from the shipped
composer.lock, scripts included; the cache is built at the first Invocation of each Warm Process, or by an optionalpost-install-cmd; cache and log dirs fall back to/tmpwhen the project dir is not writable; the runtime logs its own errors to stderr, the application's logs are its own configuration (ADR 0008). vendor/bin/scaleway-packagezips the sources withcomposer.jsonandcomposer.lock, withoutvendor/,var/,tests/,.env.local, and refuses a missing or stale lock andpathrepositories (ADR 0008).- CRON Invocations become
POST /HTTP requests by default; a JSON body{"command": "...", "args": {...}, "secret": "..."}whose secret matchesSCALEWAY_CRON_SECRET, in an Event without theX-Real-IpandX-Envoy-External-Addressof HTTP calls, makes it a Command Invocation run through the Console Application of the same Kernel, non-interactive,argsmapped to anArrayInput; the exit code 0 yields a 200 and any other a 500, both with the command output (ADR 0005). - A Front Controller returning a Console
Applicationor aCommandserves Command Invocations only and answers a 403 to the others; services are reset before and after each command, as no HTTP request follows to trigger the Kernel's own reset. - A Front Controller closure returning a
Closuremakes it a raw callablefn (array $event, mixed $context): array, built once like a Kernel (GenericRuntime would run it as a zero-argument script, meaningless per Invocation; invokable objects keep their type-based dispatch, a$object(...)turns one into a raw callable); it gets every Event and context untouched, CRON Invocations included without Command Invocation routing (raw means raw), and its return value must be the documented Function Response shape (intstatusCode, optionalheadersof strings or lists of strings, stringbody, optional boolisBase64Encoded), undocumented keys dropped, anything else being a 500. - Tests: PHPUnit on conversions, runners and packaging (offline), GitHub Actions CI (PHPUnit, PHPStan max, PHP-CS-Fixer; PHP 8.4/8.5 x Symfony 7.4/8.x; the example's scenarios through the Emulator, in dev and on its zip installed like Scaleway does), local Emulator
vendor/bin/scaleway-servebuilding Events like the platform and CRON Events onPOST /_scaleway/cron, manual real E2E deployed with Terraform.
Phases
Each phase ends with green CI checks locally, a commit series, and an independent code review whose findings are addressed before the next phase.
Phases 1 to 9 are done; what remains is listed under Remaining work.
- Bootstrap:
composer.json, directory layout, PHPUnit, PHPStan (max), PHP-CS-Fixer, GitHub Actions matrix,.gitignore,LICENSE, minimalREADME.md. - HttpKernel Application:
ScalewayRuntime, Handler bootstrap, Event toRequestandResponseto Function Response conversions, runner, reset between Invocations, boot retry, error handling,front_controlleroption, writable dir fallback. - Tooling and example:
scaleway-init,scaleway-package,scaleway-serveEmulator,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 shippedvendor/). - Response Application: a Front Controller returning a Symfony
Response. - PSR-15 Application:
RequestHandlerInterfaceviasymfony/psr-http-message-bridgeandnyholm/psr7(suggested dependencies). - Console Application and CRON routing: Command Invocations, Console
Application/CommandFront Controllers. - Raw callable Application:
fn(array $event, mixed $context): array. - Documentation: full README (install, configure, deploy, limitations), packaging tests; folding the probe results in is left for after the probe is deployed.
- Fold in the probe results (docs/probe-results.md): Scaleway installs the dependencies (ADR 0008, superseding ADR 0003), so
scaleway-packagezips the sources and lock only; only the headers the platform overwrites are trusted and the host is a runtime option (ADR 0007); Command Invocations also require a CRON-shaped Event (ADR 0005); converter tests on real Events; Emulator Events and context like the platform's, CRON simulated on a reserved path; the example requires the runtime from Packagist; Terraform recreates CRON triggers when the function is replaced.
Deviations from the original plan
Recorded per phase; the settled design above already reflects them.
- Phase 2: runners implement an own
InvocationRunner::invoke($event, $context): array, as Symfony'sRunnerInterface::run(): inthas no room for an Event nor a Function Response;extra.runtime.classandAPP_RUNTIMEare ignored (ADR 0001). - Phase 3: the Emulator is PHP's built-in server with a router forwarding each Event to a separate Warm Process over a Unix socket in a private temp dir, as the built-in server wipes all PHP state after each request; a crashed Warm Process is replaced.
- Phase 3:
scaleway-packagerequires a committedcomposer.lockand installs with--classmap-authoritativeinstead of-o; relativepathrepositories are made absolute in the lock for the install only, the zip shipping it as committed; the build runs in a private temp dir, as it holds the.envfiles (ADR 0003). - Phase 4: a Front Controller returning a Response is called for every Invocation rather than once per process, a
Requestargument receiving the Invocation's Request (ADR 0004). - Phase 6: the Command Invocation body carries the CRON Secret, matched against
SCALEWAY_CRON_SECRET, as nothing known tells a CRON Invocation from an HTTP one (ADR 0005); Front Controllers returning a ConsoleApplicationor aCommandserve Command Invocations only, and answer a 403 to the others. - Phase 7: the raw callable is a
Closurereturned by the Front Controller closure, not any callable, and must return the documented Function Response shape, undocumented keys being dropped. - Phase 8: documenting the environment variables showed that a function deployed without
APP_ENVran the shipped.env'sdev, and that error pages dumped the exception even inprod, through FrameworkBundle's CLI error renderer: the Handler now defaults toprod(ADR 0006) and to the web runtime mode, andsymfony/dotenvis a dev dependency so the tests boot like a Flex application. - Phase 9: the example's committed
composer.lockstays the onecomposer link-runtimewrites until the package is on Packagist, as no lock resolving it from Packagist can be generated before; CI proves the zip by installing it like Scaleway with this checkout standing in for Packagist, through a Composer repository configured outsidecomposer.json(e2e/deploy-locally.sh); a read-only project only keepsvar/cacheas build dir when a container was warmed there, as the zip no longer ships one.
Remaining work
Done on 2026-11-14: the repository is on GitHub with CI green, the package is on Packagist, example/composer.lock is locked from Packagist, and example/e2e/run.sh passed against the example deployed on Scaleway (php85), before v0.1.0 was tagged.
- Verify a Command Invocation end to end on Scaleway: the e2e scenarios trigger CRON Invocations only through the Emulator, and the deployed one could only be observed in the logs.
- Run the example deployment with
hostset, to check absolute URLs. - Measure what the probe left open: where logs go (Cockpit), and what a deployment with a failing Composer script serves.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|