feat(probe): record whether Composer runs its scripts at deploy timeUnverified
Scaleway documents installing the dependencies of a shipped composer.json; whether it runs scripts (Symfony auto-scripts) and with --no-dev decides whether shipping vendor/ is safe. Document the risk for the example.
eff7276 parent: 38787d3 modified
example/README.md +3 -0 | @@ -32,6 +32,9 @@ APP_ENV=prod APP_SECRET=local php /tmp/function/vendor/bin/scaleway-serve | ||
| 32 | 32 | ## Deploy it |
| 33 | 33 | |
| 34 | 34 | The Terraform code is unvalidated: it was written against the `scaleway/scaleway` provider v2.92 documentation and never applied. |
| 35 | +Scaleway documents that it installs the dependencies of a shipped `composer.json` at deploy time. | |
| 36 | +If it does so over the shipped `vendor/`, deploying this example likely fails: its `composer.lock` installs the runtime from `..`, which is not in the zip. | |
| 37 | +The [probe](../probe) settles whether and how Composer runs. | |
| 35 | 38 | |
| 36 | 39 | ```sh |
| 37 | 40 | cd example |
| @@ -32,6 +32,9 @@ APP_ENV=prod APP_SECRET=local php /tmp/function/vendor/bin/scaleway-serve | |||
| 32 | ## Deploy it | 32 | ## Deploy it |
| 33 | 33 | ||
| 34 | The Terraform code is unvalidated: it was written against the `scaleway/scaleway` provider v2.92 documentation and never applied. | 34 | The Terraform code is unvalidated: it was written against the `scaleway/scaleway` provider v2.92 documentation and never applied. |
| 35 | +Scaleway documents that it installs the dependencies of a shipped `composer.json` at deploy time. | ||
| 36 | +If it does so over the shipped `vendor/`, deploying this example likely fails: its `composer.lock` installs the runtime from `..`, which is not in the zip. | ||
| 37 | +The [probe](../probe) settles whether and how Composer runs. | ||
| 35 | 38 | ||
| 36 | ```sh | 39 | ```sh |
| 37 | cd example | 40 | cd example |
modified
probe/README.md +2 -2 | @@ -16,7 +16,7 @@ terraform -chdir=probe/terraform apply | ||
| 16 | 16 | export PROBE_URL=$(terraform -chdir=probe/terraform output -raw endpoint) |
| 17 | 17 | ``` |
| 18 | 18 | |
| 19 | -To probe the PHP 8.4 runtime too, run `terraform -chdir=probe/terraform apply -var runtime=php84` afterwards and repeat the checks. | |
| 19 | +To probe the PHP 8.4 runtime too, run `terraform -chdir=probe/terraform apply -var runtime=php84` afterwards: it replaces the function, so export `PROBE_URL` again and repeat the checks in a separate results directory. | |
| 20 | 20 | |
| 21 | 21 | ## Run the checks |
| 22 | 22 | |
| @@ -90,7 +90,7 @@ The answers the files settle: | ||
| 90 | 90 | | Body encoding (base64 or not), size limit | `06-*` | |
| 91 | 91 | | `$_SERVER`, `argv`, `SCRIPT_FILENAME`, superglobals | `01-facts.json` `globals` | |
| 92 | 92 | | Read-only code dir, writable `/tmp`, free space | `01-facts.json` `filesystem` | |
| 93 | -| Shipped `vendor/` kept, Composer run at deploy | `01-facts.json` `vendorMarkerKept`, `composerLockPresent`, `vendorListing` | | |
| 93 | +| Shipped `vendor/` kept, Composer run at deploy (scripts, `--no-dev`) | `01-facts.json` `vendorMarkerKept`, `composerLockPresent`, `composerRun`, `vendorListing` | | |
| 94 | 94 | | stdout, uncaught exceptions | `07-*.txt`, logs | |
| 95 | 95 | |
| 96 | 96 | ## Clean up |
| @@ -16,7 +16,7 @@ terraform -chdir=probe/terraform apply | |||
| 16 | export PROBE_URL=$(terraform -chdir=probe/terraform output -raw endpoint) | 16 | export PROBE_URL=$(terraform -chdir=probe/terraform output -raw endpoint) |
| 17 | ``` | 17 | ``` |
| 18 | 18 | ||
| 19 | -To probe the PHP 8.4 runtime too, run `terraform -chdir=probe/terraform apply -var runtime=php84` afterwards and repeat the checks. | 19 | +To probe the PHP 8.4 runtime too, run `terraform -chdir=probe/terraform apply -var runtime=php84` afterwards: it replaces the function, so export `PROBE_URL` again and repeat the checks in a separate results directory. |
| 20 | 20 | ||
| 21 | ## Run the checks | 21 | ## Run the checks |
| 22 | 22 | ||
| @@ -90,7 +90,7 @@ The answers the files settle: | |||
| 90 | | Body encoding (base64 or not), size limit | `06-*` | | 90 | | Body encoding (base64 or not), size limit | `06-*` | |
| 91 | | `$_SERVER`, `argv`, `SCRIPT_FILENAME`, superglobals | `01-facts.json` `globals` | | 91 | | `$_SERVER`, `argv`, `SCRIPT_FILENAME`, superglobals | `01-facts.json` `globals` | |
| 92 | | Read-only code dir, writable `/tmp`, free space | `01-facts.json` `filesystem` | | 92 | | Read-only code dir, writable `/tmp`, free space | `01-facts.json` `filesystem` | |
| 93 | -| Shipped `vendor/` kept, Composer run at deploy | `01-facts.json` `vendorMarkerKept`, `composerLockPresent`, `vendorListing` | | 93 | +| Shipped `vendor/` kept, Composer run at deploy (scripts, `--no-dev`) | `01-facts.json` `vendorMarkerKept`, `composerLockPresent`, `composerRun`, `vendorListing` | |
| 94 | | stdout, uncaught exceptions | `07-*.txt`, logs | | 94 | | stdout, uncaught exceptions | `07-*.txt`, logs | |
| 95 | 95 | ||
| 96 | ## Clean up | 96 | ## Clean up |
modified
probe/function/composer.json +6 -1 | @@ -1,5 +1,10 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "name": "jdecool/scaleway-runtime-probe", |
| 3 | 3 | "description": "Ships vendor/ to find out whether Scaleway runs Composer over it at deploy time", |
| 4 | - "require": {} | |
| 4 | + "require": {}, | |
| 5 | + "scripts": { | |
| 6 | + "record-composer-run": "@php -r \"file_put_contents('composer-run.json', json_encode(['devMode' => getenv('COMPOSER_DEV_MODE'), 'cwd' => getcwd(), 'at' => date(DATE_ATOM)]));\"", | |
| 7 | + "post-install-cmd": "@record-composer-run", | |
| 8 | + "post-update-cmd": "@record-composer-run" | |
| 9 | + } | |
| 5 | 10 | } |
| @@ -1,5 +1,10 @@ | |||
| 1 | { | 1 | { |
| 2 | "name": "jdecool/scaleway-runtime-probe", | 2 | "name": "jdecool/scaleway-runtime-probe", |
| 3 | "description": "Ships vendor/ to find out whether Scaleway runs Composer over it at deploy time", | 3 | "description": "Ships vendor/ to find out whether Scaleway runs Composer over it at deploy time", |
| 4 | - "require": {} | 4 | + "require": {}, |
| 5 | + "scripts": { | ||
| 6 | + "record-composer-run": "@php -r \"file_put_contents('composer-run.json', json_encode(['devMode' => getenv('COMPOSER_DEV_MODE'), 'cwd' => getcwd(), 'at' => date(DATE_ATOM)]));\"", | ||
| 7 | + "post-install-cmd": "@record-composer-run", | ||
| 8 | + "post-update-cmd": "@record-composer-run" | ||
| 9 | + } | ||
| 5 | } | 10 | } |
modified
probe/function/handler.php +2 -0 | @@ -112,6 +112,8 @@ function facts($event, $context, int $invocations, string $firstInvocationAt): a | ||
| 112 | 112 | 'vendorListing' => @scandir(__DIR__.'/vendor'), |
| 113 | 113 | 'vendorMarkerKept' => defined('PROBE_VENDOR_MARKER'), |
| 114 | 114 | 'composerLockPresent' => is_file(__DIR__.'/composer.lock'), |
| 115 | + // Written by the composer.json scripts: tells whether Composer ran its scripts, and with --no-dev or not. | |
| 116 | + 'composerRun' => json_decode((string) @file_get_contents(__DIR__.'/composer-run.json'), true), | |
| 115 | 117 | 'tmpWritable' => is_writable('/tmp'), |
| 116 | 118 | 'tmpWriteWorks' => false !== @file_put_contents($tmpProbe, 'x') && @unlink($tmpProbe), |
| 117 | 119 | 'tmpFreeBytes' => @disk_free_space('/tmp'), |
| @@ -112,6 +112,8 @@ function facts($event, $context, int $invocations, string $firstInvocationAt): a | |||
| 112 | 'vendorListing' => @scandir(__DIR__.'/vendor'), | 112 | 'vendorListing' => @scandir(__DIR__.'/vendor'), |
| 113 | 'vendorMarkerKept' => defined('PROBE_VENDOR_MARKER'), | 113 | 'vendorMarkerKept' => defined('PROBE_VENDOR_MARKER'), |
| 114 | 'composerLockPresent' => is_file(__DIR__.'/composer.lock'), | 114 | 'composerLockPresent' => is_file(__DIR__.'/composer.lock'), |
| 115 | + // Written by the composer.json scripts: tells whether Composer ran its scripts, and with --no-dev or not. | ||
| 116 | + 'composerRun' => json_decode((string) @file_get_contents(__DIR__.'/composer-run.json'), true), | ||
| 115 | 'tmpWritable' => is_writable('/tmp'), | 117 | 'tmpWritable' => is_writable('/tmp'), |
| 116 | 'tmpWriteWorks' => false !== @file_put_contents($tmpProbe, 'x') && @unlink($tmpProbe), | 118 | 'tmpWriteWorks' => false !== @file_put_contents($tmpProbe, 'x') && @unlink($tmpProbe), |
| 117 | 'tmpFreeBytes' => @disk_free_space('/tmp'), | 119 | 'tmpFreeBytes' => @disk_free_space('/tmp'), |