jdecool/scaleway-runtimepublic Fork
⑂ v0.2.0
Commits
⬇ Clone ▾
git clone https://git.rickub.com/jdecool/scaleway-runtime.git
git clone ssh://git@rickub.com/jdecool/scaleway-runtime.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
docs: record what a deployment with a failing Composer script serves fdc6e0cUnverified · on v0.2.0 · Jérémy DECOOL · 10d ago
plan.md · 64 lines · 11.1 KBmarkdown
Blame HistoryOpen raw

Implementation plan

Vocabulary follows GLOSSARY.md; decisions are recorded in docs/adr.

Settled design

  • Package jdecool/scaleway-runtime, namespace JDecool\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-runtime adding a path repository on the fly for local work and CI.
  • The application commits a 3-line handler.php stub (generated by vendor/bin/scaleway-init); the Scaleway handler setting is handler.handle.
  • The Handler drives ScalewayRuntime extends SymfonyRuntime itself, without vendor/autoload_runtime.php (ADR 0001).
  • The Front Controller is the unchanged public/index.php; its path is the front_controller runtime option (extra.runtime or APP_RUNTIME_OPTIONS).
  • 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).
  • A Front Controller returning a Response is called for every Invocation, a Request argument receiving the Invocation's Request (ADR 0004).
  • A Front Controller returning a PSR-15 RequestHandlerInterface is built once like a Kernel and served through symfony/psr-http-message-bridge (suggested, with nyholm/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 implementing ResetInterface is reset before every Invocation but the first.
  • 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; no proxy trusted, the client taken from X-Real-Ip, the scheme from X-Forwarded-Proto and the host from the host runtime option (SCALEWAY_HOST, localhost by default), as clients can forge the other forwarding headers and no Host reaches 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 prod when the process environment sets no APP_ENV, whatever the shipped .env says, and the Emulator dev (ADR 0006); APP_RUNTIME_MODE defaults to web=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 optional post-install-cmd; cache and log dirs fall back to /tmp when 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-package zips the sources with composer.json and composer.lock, without vendor/, var/, tests/, .env.local, and refuses a missing or stale lock and path repositories (ADR 0008).
  • CRON Invocations become POST / HTTP requests by default; a JSON body {"command": "...", "args": {...}, "secret": "..."} whose secret matches SCALEWAY_CRON_SECRET, in an Event without the X-Real-Ip and X-Envoy-External-Address of HTTP calls, makes it a Command Invocation run through the Console Application of the same Kernel, non-interactive, args mapped to an ArrayInput; 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 Application or a Command serves 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 Closure makes it a raw callable fn (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 (int statusCode, optional headers of strings or lists of strings, string body, optional bool isBase64Encoded), 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-serve building Events like the platform and CRON Events on POST /_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.

  1. Bootstrap: composer.json, directory layout, PHPUnit, PHPStan (max), PHP-CS-Fixer, GitHub Actions matrix, .gitignore, LICENSE, minimal README.md.
  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.
  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/).
  4. Response Application: a Front Controller returning a Symfony Response.
  5. PSR-15 Application: RequestHandlerInterface via symfony/psr-http-message-bridge and nyholm/psr7 (suggested dependencies).
  6. Console Application and CRON routing: Command Invocations, Console Application / Command Front Controllers.
  7. Raw callable Application: fn(array $event, mixed $context): array.
  8. Documentation: full README (install, configure, deploy, limitations), packaging tests; folding the probe results in is left for after the probe is deployed.
  9. Fold in the probe results (docs/probe-results.md): Scaleway installs the dependencies (ADR 0008, superseding ADR 0003), so scaleway-package zips 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's RunnerInterface::run(): int has no room for an Event nor a Function Response; extra.runtime.class and APP_RUNTIME are 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-package requires a committed composer.lock and installs with --classmap-authoritative instead of -o; relative path repositories 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 .env files (ADR 0003).
  • Phase 4: a Front Controller returning a Response is called for every Invocation rather than once per process, a Request argument 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 Console Application or a Command serve Command Invocations only, and answer a 403 to the others.
  • Phase 7: the raw callable is a Closure returned 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_ENV ran the shipped .env's dev, and that error pages dumped the exception even in prod, through FrameworkBundle's CLI error renderer: the Handler now defaults to prod (ADR 0006) and to the web runtime mode, and symfony/dotenv is a dev dependency so the tests boot like a Flex application.
  • Phase 9: the example's committed composer.lock stays the one composer link-runtime writes 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 outside composer.json (e2e/deploy-locally.sh); a read-only project only keeps var/cache as 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.
Command Invocations were then verified on that deployment through its logs (probe results): a CRON trigger lands on POST /, the app:greet arguments with the secret run the command, a wrong secret or an HTTP call do not, and a failing command is logged.
For that, the example logs from the info level to stderr, and no longer logs the body of POST /, which may hold the secret; e2e/run.sh still skips the CRON scenarios against a deployment, the triggers firing hourly and their outcome being in Cockpit only, so the example README documents the manual check.

Absolute URLs were then verified on that deployment, without host, with its domain_name and with a custom-domain-like value (probe results): the router, getUri() and redirects carry the host, never a forged X-Forwarded-Host, and framework.trusted_hosts answers a 400 until host matches it.

Where logs go was measured on 2026-11-14 (probe results): the runtime's stderr lines reach Cockpit one entry per line, with a DEBUG - prefix and a source=user stream=stderr suffix.
What a deployment whose Composer script or install fails serves was then measured (probe results): always the new code, with a working vendor/ after a failing script and none after a failing install, the function being ready and Composer's output shown nowhere.

Nothing remains.

 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
60
61
62
63
64
# Implementation plan

Vocabulary follows [GLOSSARY.md](../GLOSSARY.md); decisions are recorded in [docs/adr](adr).

## Settled design

- Package `jdecool/scaleway-runtime`, namespace `JDecool\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-runtime` adding a `path` repository on the fly for local work and CI.
- The application commits a 3-line `handler.php` stub (generated by `vendor/bin/scaleway-init`); the Scaleway handler setting is `handler.handle`.
- The Handler drives `ScalewayRuntime extends SymfonyRuntime` itself, without `vendor/autoload_runtime.php` (ADR 0001).
- The Front Controller is the unchanged `public/index.php`; its path is the `front_controller` runtime option (`extra.runtime` or `APP_RUNTIME_OPTIONS`).
- 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).
- A Front Controller returning a Response is called for every Invocation, a `Request` argument receiving the Invocation's Request (ADR 0004).
- A Front Controller returning a PSR-15 `RequestHandlerInterface` is built once like a Kernel and served through `symfony/psr-http-message-bridge` (suggested, with `nyholm/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 implementing `ResetInterface` is reset before every Invocation but the first.
- 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`; no proxy trusted, the client taken from `X-Real-Ip`, the scheme from `X-Forwarded-Proto` and the host from the `host` runtime option (`SCALEWAY_HOST`, `localhost` by default), as clients can forge the other forwarding headers and no `Host` reaches 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 `prod` when the process environment sets no `APP_ENV`, whatever the shipped `.env` says, and the Emulator `dev` (ADR 0006); `APP_RUNTIME_MODE` defaults to `web=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 optional `post-install-cmd`; cache and log dirs fall back to `/tmp` when 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-package` zips the sources with `composer.json` and `composer.lock`, without `vendor/`, `var/`, `tests/`, `.env.local`, and refuses a missing or stale lock and `path` repositories (ADR 0008).
- CRON Invocations become `POST /` HTTP requests by default; a JSON body `{"command": "...", "args": {...}, "secret": "..."}` whose secret matches `SCALEWAY_CRON_SECRET`, in an Event without the `X-Real-Ip` and `X-Envoy-External-Address` of HTTP calls, makes it a Command Invocation run through the Console Application of the same Kernel, non-interactive, `args` mapped to an `ArrayInput`; 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 `Application` or a `Command` serves 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 `Closure` makes it a raw callable `fn (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 (int `statusCode`, optional `headers` of strings or lists of strings, string `body`, optional bool `isBase64Encoded`), 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-serve` building Events like the platform and CRON Events on `POST /_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](#remaining-work).

1. **Bootstrap**: `composer.json`, directory layout, PHPUnit, PHPStan (max), PHP-CS-Fixer, GitHub Actions matrix, `.gitignore`, `LICENSE`, minimal `README.md`.
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.
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/`).
4. **Response Application**: a Front Controller returning a Symfony `Response`.
5. **PSR-15 Application**: `RequestHandlerInterface` via `symfony/psr-http-message-bridge` and `nyholm/psr7` (suggested dependencies).
6. **Console Application and CRON routing**: Command Invocations, Console `Application` / `Command` Front Controllers.
7. **Raw callable Application**: `fn(array $event, mixed $context): array`.
8. **Documentation**: full README (install, configure, deploy, limitations), packaging tests; folding the probe results in is left for after the probe is deployed.
9. **Fold in the probe results** ([docs/probe-results.md](probe-results.md)): Scaleway installs the dependencies (ADR 0008, superseding ADR 0003), so `scaleway-package` zips 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's `RunnerInterface::run(): int` has no room for an Event nor a Function Response; `extra.runtime.class` and `APP_RUNTIME` are 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-package` requires a committed `composer.lock` and installs with `--classmap-authoritative` instead of `-o`; relative `path` repositories 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 `.env` files (ADR 0003).
- **Phase 4**: a Front Controller returning a Response is called for every Invocation rather than once per process, a `Request` argument 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 Console `Application` or a `Command` serve Command Invocations only, and answer a 403 to the others.
- **Phase 7**: the raw callable is a `Closure` returned 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_ENV` ran the shipped `.env`'s `dev`, and that error pages dumped the exception even in `prod`, through FrameworkBundle's CLI error renderer: the Handler now defaults to `prod` (ADR 0006) and to the web runtime mode, and `symfony/dotenv` is a dev dependency so the tests boot like a Flex application.
- **Phase 9**: the example's committed `composer.lock` stays the one `composer link-runtime` writes 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 outside `composer.json` (`e2e/deploy-locally.sh`); a read-only project only keeps `var/cache` as 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.
Command Invocations were then verified on that deployment through its logs ([probe results](probe-results.md#cron-invocations)): a CRON trigger lands on `POST /`, the `app:greet` arguments with the secret run the command, a wrong secret or an HTTP call do not, and a failing command is logged.
For that, the example logs from the `info` level to stderr, and no longer logs the body of `POST /`, which may hold the secret; `e2e/run.sh` still skips the CRON scenarios against a deployment, the triggers firing hourly and their outcome being in Cockpit only, so the example README documents the manual check.

Absolute URLs were then verified on that deployment, without `host`, with its `domain_name` and with a custom-domain-like value ([probe results](probe-results.md#absolute-urls)): the router, `getUri()` and redirects carry the `host`, never a forged `X-Forwarded-Host`, and `framework.trusted_hosts` answers a 400 until `host` matches it.

Where logs go was measured on 2026-11-14 ([probe results](probe-results.md#logs)): the runtime's stderr lines reach Cockpit one entry per line, with a `DEBUG - ` prefix and a ` source=user stream=stderr` suffix.
What a deployment whose Composer script or install fails serves was then measured ([probe results](probe-results.md#failed-scripts-and-installs)): always the new code, with a working `vendor/` after a failing script and none after a failing install, the function being `ready` and Composer's output shown nowhere.

Nothing remains.