Skip to content

Beautiful Open-Source Form Builder

Move hosted production delivery from AWS to Scaleway/Coolify (#1347)

Julien Nahum285c4989575a
diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml
index 2fffe6ade..0504cd69e 100644
--- a/.github/workflows/ci-cd.yml
+++ b/.github/workflows/ci-cd.yml
@@ -10,6 +10,8 @@ on:
- "api/**"
- "client/**"
- "docker/**"
+ - "deploy/scaleway/**"
+ - "tests/Deployment/**"
- "docker-compose*.yml"
- "scripts/*security*.mjs"
- "scripts/audit-npm.mjs"
@@ -159,20 +161,6 @@ jobs:
if-no-files-found: error
retention-days: 1
- - name: Build and validate Amplify Node 24 compute
- run: npm run build:amplify
- env:
- NODE_OPTIONS: --max-old-space-size=4096
-
- - name: Upload standalone Amplify artifact
- uses: actions/upload-artifact@v7
- with:
- name: amplify-output
- path: client/.amplify-hosting
- include-hidden-files: true
- if-no-files-found: error
- retention-days: 1
-
sync_check:
runs-on: ubuntu-latest
name: Verify shared files are in sync
@@ -582,20 +570,6 @@ jobs:
docker cp client/scripts/check-built-css.mjs opnform-client-qa:/tmp/check-built-css.mjs
docker exec opnform-client-qa node /tmp/check-built-css.mjs /app/public
node scripts/check-linux-client-health.mjs
- - uses: actions/download-artifact@v8
- with:
- name: amplify-output
- path: ${{ runner.temp }}/opnform-amplify-qa
- - name: Smoke standalone Amplify compute on Linux Node 24
- run: node scripts/check-amplify-runtime.mjs "${{ runner.temp }}/opnform-amplify-qa"
- - uses: actions/upload-artifact@v7
- if: always()
- with:
- name: amplify-runtime-evidence
- path: |
- amplify-runtime*.json
- amplify-runtime.log
- retention-days: 7
- name: Capture image and API logs
if: always()
run: docker logs opnform-client-qa > client-image.log 2>&1 || true
@@ -616,10 +590,16 @@ jobs:
permissions:
contents: read
+ scaleway-runtime:
+ name: Scaleway runtime
+ uses: ./.github/workflows/scaleway-validation.yml
+ permissions:
+ contents: read
+
release-readiness:
name: Release readiness
if: always()
- needs: [code_lint, client_checks, sync_check, tests, database_compatibility, e2e, linux_client_image, dependency-security]
+ needs: [code_lint, client_checks, sync_check, tests, database_compatibility, e2e, linux_client_image, dependency-security, scaleway-runtime]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
@@ -631,63 +611,40 @@ jobs:
env:
NEEDS_JSON: ${{ toJSON(needs) }}
- production-deploy:
+ publish-scaleway-images:
+ name: Publish validated Scaleway images
needs: [release-readiness]
if: success() && github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
- name: Triggers Deployment (Vapor & Amplify)
-
+ permissions:
+ contents: read
+ packages: write
steps:
- - name: Checkout code
- uses: actions/checkout@v7
-
- - name: Get Composer cache directory
- id: composer-cache
- run: |
- echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
-
- - uses: actions/cache@v6
+ - uses: actions/checkout@v7
+ - uses: actions/download-artifact@v8
with:
- path: ${{ steps.composer-cache.outputs.dir }}
- key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
- restore-keys: |
- ${{ runner.os }}-composer-
-
- - name: Setup PHP
- uses: shivammathur/setup-php@v2
+ name: scaleway-runtime-images
+ path: ${{ runner.temp }}/scaleway-images
+ - name: Load the exact images exercised by the runtime gate
+ run: docker load -i "${{ runner.temp }}/scaleway-images/images.tar"
+ - uses: docker/login-action@v3
with:
- php-version: 8.3
- extensions: dom, curl, mbstring, pdo, sqlite, pdo_sqlite, pdo_pgsql, pdo_mysql, bcmath, gd, zip, pcntl, intl
- tools: composer:v2
- coverage: none
-
- - name: Prepare the environment
- working-directory: ./api
- run: cp .env.example .env
-
- - name: Install composer dependencies
- working-directory: ./api
- run: composer install --prefer-dist --no-dev --no-interaction --no-progress --optimize-autoloader
-
- - name: Directory permissions
- working-directory: ./api
- run: chmod -R 777 storage bootstrap/cache
-
- - name: Trigger front-end deployment
- run: |
- URL="${{ secrets.AMPLIFY_DEPLOY_URL }}"
- curl -X POST -d {} "$URL" -H "Content-Type: application/json"
-
- - name: Created encrypted .env file before deployment
- working-directory: ./api
- run: |
- echo "${{ secrets.ENCRYPTED_ENV_FILE }}" >> .env.production.encrypted
-
- - name: Deploy back-end to production
- working-directory: ./api
- run: php vendor/bin/vapor deploy api-production --commit="${GITHUB_SHA}" --message="${GITHUB_REF}"
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+ - name: Publish immutable private images and the Coolify promotion descriptor
env:
- VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: python3 deploy/scaleway/publish-release.py --output release.json
+ - uses: actions/upload-artifact@v7
+ with:
+ name: opnform-coolify-release
+ overwrite: true
+ path: release.json
+ retention-days: 30
+ - name: Record the deployment boundary
+ run: |
+ echo 'Validated main release published. The private OpnForm controller deploys after this CI run completes successfully. No AWS deployment.' >> "$GITHUB_STEP_SUMMARY"
publish-docker-images:
name: Push Docker images to Docker Hub
diff --git a/.github/workflows/scaleway-deployment.yml b/.github/workflows/scaleway-deployment.yml
new file mode 100644
index 000000000..92dd3c401
--- /dev/null
+++ b/.github/workflows/scaleway-deployment.yml
@@ -0,0 +1,58 @@
+name: Scaleway production deployment
+
+on:
+ workflow_run:
+ workflows: [CI/CD Pipeline]
+ types: [completed]
+ branches: [main]
+
+permissions:
+ contents: read
+
+concurrency:
+ group: opnform-production-observation
+ cancel-in-progress: false
+
+jobs:
+ verify-live-release:
+ name: Verify automatic Coolify deployment
+ if: >-
+ github.event.workflow_run.conclusion == 'success' &&
+ github.event.workflow_run.event == 'push' &&
+ github.event.workflow_run.head_branch == 'main' &&
+ github.event.workflow_run.head_repository.full_name == 'OpnForm/OpnForm'
+ runs-on: ubuntu-latest
+ timeout-minutes: 180
+ steps:
+ - name: Await the private controller and verify the deployed pair
+ env:
+ EXPECTED_SHA: ${{ github.event.workflow_run.head_sha }}
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ python3 - <<'PY'
+ import json, os, time, urllib.request
+ expected = os.environ['EXPECTED_SHA']
+ def read(url, authenticated=False):
+ headers = {'Accept': 'application/json', 'Cache-Control': 'no-cache', 'User-Agent': 'opnform-deployment-observer'}
+ if authenticated:
+ headers['Authorization'] = 'Bearer ' + os.environ['GH_TOKEN']
+ with urllib.request.urlopen(urllib.request.Request(url, headers=headers), timeout=20) as response:
+ return json.load(response)
+ end = time.monotonic() + 10500
+ while time.monotonic() < end:
+ try:
+ current = read('https://api.github.com/repos/OpnForm/OpnForm/commits/main', True)
+ if current['sha'] != expected:
+ print('Superseded by a newer main release; the controller selects current main only.')
+ break
+ api = read('https://api.opnform.com/healthz')
+ frontend = read('https://opnform.com/release.json')
+ if api.get('status') == 'ok' and api.get('revision') == expected and frontend.get('revision') == expected:
+ print('The validated main backend/frontend pair is live on Coolify: ' + expected)
+ break
+ except Exception:
+ pass
+ time.sleep(15)
+ else:
+ raise SystemExit('Deployment was not confirmed; inspect the private controller journal.')
+ PY
diff --git a/.github/workflows/scaleway-validation.yml b/.github/workflows/scaleway-validation.yml
new file mode 100644
index 000000000..7a352bf53
--- /dev/null
+++ b/.github/workflows/scaleway-validation.yml
@@ -0,0 +1,73 @@
+name: Scaleway runtime validation
+
+on:
+ workflow_call:
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+jobs:
+ tooling:
+ name: Deployment contracts
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v7
+ - run: python3 -m unittest discover -s tests/Deployment -p 'test_*.py'
+ runtime:
+ name: Native AMD64 application images
+ runs-on: ubuntu-latest
+ timeout-minutes: 40
+ steps:
+ - uses: actions/checkout@v7
+ - uses: docker/setup-buildx-action@v4
+ - name: Build backend image without secrets or publication
+ uses: docker/build-push-action@v7
+ with:
+ context: .
+ file: deploy/scaleway/Dockerfile.api
+ target: production
+ platforms: linux/amd64
+ load: true
+ tags: opnform-scaleway-api:local
+ build-args: SOURCE_COMMIT=${{ github.sha }}
+ cache-from: type=gha,scope=opnform-scaleway-api
+ cache-to: type=gha,mode=max,scope=opnform-scaleway-api
+ - name: Build frontend image without secrets or publication
+ uses: docker/build-push-action@v7
+ with:
+ context: .
+ file: deploy/scaleway/Dockerfile.client
+ platforms: linux/amd64
+ load: true
+ tags: opnform-scaleway-client:local
+ build-args: SOURCE_COMMIT=${{ github.sha }}
+ cache-from: type=gha,scope=opnform-scaleway-client
+ cache-to: type=gha,mode=max,scope=opnform-scaleway-client
+ - name: Record source hashes used by the embedded-image check
+ run: python3 tests/Deployment/ci-source-proof.py --output-dir "$RUNNER_TEMP/scaleway-proof"
+ - name: Pull fictional fixture dependencies
+ run: |
+ docker pull postgres:16-bookworm
+ docker pull redis:7.4-bookworm
+ - name: Exercise the exact pair without source or vendor overlays
+ run: sudo --preserve-env=HOME,RUNNER_TEMP,GITHUB_SHA python3 tests/Deployment/test-runtime.py --output-dir "$RUNNER_TEMP/scaleway-proof" --host-firewall-guard
+ - name: Preserve the exact tested pair for the publishing job
+ if: github.ref == 'refs/heads/main' && github.event_name == 'push'
+ run: docker save -o "$RUNNER_TEMP/scaleway-proof/images.tar" opnform-scaleway-api:local opnform-scaleway-client:local
+ - uses: actions/upload-artifact@v7
+ if: github.ref == 'refs/heads/main' && github.event_name == 'push'
+ with:
+ name: scaleway-runtime-images
+ overwrite: true
+ path: ${{ runner.temp }}/scaleway-proof/images.tar
+ retention-days: 1
+ - uses: actions/upload-artifact@v7
+ if: always()
+ with:
+ name: scaleway-runtime-evidence
+ overwrite: true
+ path: |
+ ${{ runner.temp }}/scaleway-proof/*.json
+ ${{ runner.temp }}/scaleway-proof/*.log
+ retention-days: 7
diff --git a/api/app/Http/Controllers/Content/SignedStorageUrlController.php b/api/app/Http/Controllers/Content/SignedStorageUrlController.php
index 45053621a..5311cdb3c 100644
--- a/api/app/Http/Controllers/Content/SignedStorageUrlController.php
+++ b/api/app/Http/Controllers/Content/SignedStorageUrlController.php
@@ -2,9 +2,14 @@
namespace App\Http\Controllers\Content;
+use Aws\Middleware;
+use Aws\S3\S3Client;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
+use Illuminate\Support\Facades\Storage;
+use InvalidArgumentException;
use Laravel\Vapor\Http\Controllers\SignedStorageUrlController as Controller;
+use Psr\Http\Message\RequestInterface;
class SignedStorageUrlController extends Controller
{
@@ -15,8 +20,10 @@ class SignedStorageUrlController extends Controller
*/
public function store(Request $request)
{
- $this->ensureEnvironmentVariablesAreAvailable($request);
- $bucket = $request->input('bucket') ?: $_ENV['AWS_BUCKET'];
+ $bucket = $request->input('bucket') ?: config('filesystems.disks.s3.bucket');
+ if (! is_string($bucket) || $bucket === '') {
+ throw new InvalidArgumentException('An S3 bucket must be configured to issue signed uploads.');
+ }
$client = $this->storageClient();
@@ -39,4 +46,48 @@ class SignedStorageUrlController extends Controller
'headers' => $this->headers($request, $signedRequest),
], 201);
}
+
+ protected function storageClient()
+ {
+ // Keep signed uploads on the same endpoint/credentials as Flysystem.
+ // AWS credentials may remain dedicated to SES and DynamoDB.
+ return Storage::disk('s3')->getClient();
+ }
+
+ protected function createCommand(Request $request, S3Client $client, $bucket, $key)
+ {
+ $command = parent::createCommand($request, $client, $bucket, $key);
+
+ // The locked SDK builds SignedHeaders in request order but sorts the
+ // canonical request. Sort this command only, before it is presigned.
+ $command->getHandlerList()->appendBuild(Middleware::mapRequest(function (RequestInterface $signedRequest) {
+ $headers = $signedRequest->getHeaders();
+ uksort($headers, fn ($left, $right) => strcasecmp($left, $right));
+
+ foreach (array_keys($headers) as $name) {
+ $signedRequest = $signedRequest->withoutHeader($name);
+ }
+
+ foreach ($headers as $name => $values) {
+ $signedRequest = $signedRequest->withHeader($name, $values);
+ }
+
+ return $signedRequest;
+ }), 'sort-signed-storage-headers');
+
+ return $command;
+ }
+
+ protected function headers(Request $request, $signedRequest)
+ {
+ $headers = parent::headers($request, $signedRequest);
+
+ // Cache-Control is deliberately not signed by the SDK and is stripped
+ // from its request. The browser must still send the requested metadata.
+ if ($cacheControl = $request->input('cache_control')) {
+ $headers['Cache-Control'] = $cacheControl;
+ }
+
+ return $headers;
+ }
}
diff --git a/api/app/Providers/AppServiceProvider.php b/api/app/Providers/AppServiceProvider.php
index d6cee5cdc..fac1d19b8 100644
--- a/api/app/Providers/AppServiceProvider.php
+++ b/api/app/Providers/AppServiceProvider.php
@@ -105,6 +105,12 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
+ if (config('jwt.blacklist_store') !== null) {
+ $this->app->when(\Tymon\JWTAuth\Providers\Storage\Illuminate::class)
+ ->needs(\Illuminate\Contracts\Cache\Repository::class)
+ ->give(fn ($app) => $app['cache']->store($app['config']->get('jwt.blacklist_store')));
+ }
+
$this->app->bind(\Aws\Sns\MessageValidator::class, fn () => new \Aws\Sns\MessageValidator(
fn ($url) => \Illuminate\Support\Facades\Cache::remember(
'sns-signing-cert:'.hash('sha256', $url),
diff --git a/api/config/cache.php b/api/config/cache.php
index 4f41fdf96..0248a07dc 100644
--- a/api/config/cache.php
+++ b/api/config/cache.php
@@ -18,7 +18,7 @@ return [
|
*/
- 'default' => env('CACHE_DRIVER', 'file'),
+ 'default' => env('CACHE_DRIVER', env('OPNFORM_STATE_MODE') === 'redis-fresh' ? 'redis' : 'file'),
/*
|--------------------------------------------------------------------------
@@ -73,8 +73,22 @@ return [
],
'redis' => [
+ 'driver' => 'redis',
+ 'connection' => env('OPNFORM_STATE_MODE') === 'redis-fresh' ? 'state' : 'cache',
+ 'prefix' => env('OPNFORM_STATE_MODE') === 'redis-fresh'
+ ? env('REDIS_STATE_KEY_PREFIX', 'opnform:state:') : null,
+ ],
+
+ 'auth' => [
+ 'driver' => 'redis',
+ 'connection' => 'auth',
+ 'prefix' => env('REDIS_AUTH_KEY_PREFIX', 'opnform:auth:'),
+ ],
+
+ 'volatile' => [
'driver' => 'redis',
'connection' => 'cache',
+ 'prefix' => env('REDIS_CACHE_KEY_PREFIX', 'opnform:cache:'),
],
'dynamodb' => [
diff --git a/api/config/database.php b/api/config/database.php
index d196ec140..af59420a6 100644
--- a/api/config/database.php
+++ b/api/config/database.php
@@ -149,11 +149,28 @@ return [
'database' => env('REDIS_DB', '0'),
],
+ // One durable Redis process, distinct logical DBs for protected state and auth.
+ 'state' => [
+ 'url' => env('REDIS_STATE_URL'),
+ 'host' => env('REDIS_STATE_HOST', env('REDIS_HOST', '127.0.0.1')),
+ 'password' => env('REDIS_STATE_PASSWORD', env('REDIS_PASSWORD')),
+ 'port' => env('REDIS_STATE_PORT', env('REDIS_PORT', '6379')),
+ 'database' => env('REDIS_STATE_DB', '3'),
+ ],
+
+ 'auth' => [
+ 'url' => env('REDIS_AUTH_URL'),
+ 'host' => env('REDIS_AUTH_HOST', env('REDIS_HOST', '127.0.0.1')),
+ 'password' => env('REDIS_AUTH_PASSWORD', env('REDIS_PASSWORD')),
+ 'port' => env('REDIS_AUTH_PORT', env('REDIS_PORT', '6379')),
+ 'database' => env('REDIS_AUTH_DB', '2'),
+ ],
+
'cache' => [
- 'url' => env('REDIS_URL'),
- 'host' => env('REDIS_HOST', '127.0.0.1'),
- 'password' => env('REDIS_PASSWORD', null),
- 'port' => env('REDIS_PORT', '6379'),
+ 'url' => env('REDIS_CACHE_URL', env('REDIS_CACHE_HOST') ? null : env('REDIS_URL')),
+ 'host' => env('REDIS_CACHE_HOST', env('REDIS_HOST', '127.0.0.1')),
+ 'password' => env('REDIS_CACHE_PASSWORD', env('REDIS_PASSWORD', null)),
+ 'port' => env('REDIS_CACHE_PORT', env('REDIS_PORT', '6379')),
'database' => env('REDIS_CACHE_DB', '1'),
],
diff --git a/api/config/filesystems.php b/api/config/filesystems.php
index 3468cc16d..507f6963b 100644
--- a/api/config/filesystems.php
+++ b/api/config/filesystems.php
@@ -60,13 +60,14 @@ return [
's3' => [
'driver' => 's3',
- 'key' => env('AWS_ACCESS_KEY_ID'),
- 'secret' => env('AWS_SECRET_ACCESS_KEY'),
- 'region' => env('AWS_DEFAULT_REGION'),
- 'bucket' => env('AWS_BUCKET'),
- 'url' => env('AWS_URL'),
- 'endpoint' => env('AWS_ENDPOINT'),
- 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', true),
+ 'key' => env('S3_ACCESS_KEY_ID', env('AWS_ACCESS_KEY_ID')),
+ 'secret' => env('S3_SECRET_ACCESS_KEY', env('AWS_SECRET_ACCESS_KEY')),
+ 'token' => env('S3_SESSION_TOKEN', env('S3_ACCESS_KEY_ID') ? null : env('AWS_SESSION_TOKEN')),
+ 'region' => env('S3_REGION', env('AWS_DEFAULT_REGION')),
+ 'bucket' => env('S3_BUCKET', env('AWS_BUCKET')),
+ 'url' => env('S3_URL', env('AWS_URL')),
+ 'endpoint' => env('S3_ENDPOINT', env('AWS_ENDPOINT')),
+ 'use_path_style_endpoint' => env('S3_USE_PATH_STYLE_ENDPOINT', env('AWS_USE_PATH_STYLE_ENDPOINT', true)),
'temporary_url_rewrites' => json_decode(env('AWS_TEMPORARY_URL_REWRITES', '{}'), true),
],
diff --git a/api/config/jwt.php b/api/config/jwt.php
index 5a81341f6..93ace36e4 100644
--- a/api/config/jwt.php
+++ b/api/config/jwt.php
@@ -231,6 +231,9 @@ return [
'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true),
+ // Null retains the package default; hosted Redis keeps its existing auth store.
+ 'blacklist_store' => env('OPNFORM_STATE_MODE') === 'redis-fresh' ? 'auth' : null,
+
/*
| -------------------------------------------------------------------------
| Blacklist Grace Period
diff --git a/api/config/queue.php b/api/config/queue.php
index 122229666..9b00454ce 100644
--- a/api/config/queue.php
+++ b/api/config/queue.php
@@ -61,9 +61,9 @@ return [
'redis' => [
'driver' => 'redis',
- 'connection' => 'default',
+ 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'),
'queue' => env('REDIS_QUEUE', 'default'),
- 'retry_after' => 90,
+ 'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90),
'block_for' => null,
],
diff --git a/api/config/session.php b/api/config/session.php
index 5819290a9..ed0ae05bb 100644
--- a/api/config/session.php
+++ b/api/config/session.php
@@ -1,5 +1,7 @@
<?php
+$redisState = env('OPNFORM_STATE_MODE') === 'redis-fresh';
+
return [
/*
@@ -16,7 +18,7 @@ return [
|
*/
- 'driver' => env('SESSION_DRIVER', 'file'),
+ 'driver' => env('SESSION_DRIVER', $redisState ? 'redis' : 'file'),
/*
|--------------------------------------------------------------------------
@@ -70,7 +72,7 @@ return [
|
*/
- 'connection' => env('SESSION_CONNECTION', null),
+ 'connection' => env('SESSION_CONNECTION', $redisState ? 'auth' : null),
/*
|--------------------------------------------------------------------------
@@ -98,7 +100,7 @@ return [
|
*/
- 'store' => env('SESSION_STORE', null),
+ 'store' => env('SESSION_STORE', $redisState ? 'auth' : null),
/*
|--------------------------------------------------------------------------
diff --git a/api/tests/Feature/CaddyMigrationContractTest.php b/api/tests/Feature/CaddyMigrationContractTest.php
new file mode 100644
index 000000000..b4ee43262
--- /dev/null
+++ b/api/tests/Feature/CaddyMigrationContractTest.php
@@ -0,0 +1,39 @@
+<?php
+
+beforeEach(function () {
+ config()->set('trustedproxy.proxies', ['127.0.0.1']);
+ config()->set('custom-domains.enabled', true);
+ config()->set('custom-domains.authorized_ips', ['192.0.2.10']);
+ config()->set('custom-domains.caddy_secret', 'fictional-caddy-secret');
+ $this->withServerVariables(['REMOTE_ADDR' => '192.0.2.10']);
+});
+
+it('authorizes a registered customer domain from the pinned proxy', function () {
+ $workspace = $this->createUserWorkspace($this->createUser());
+ $workspace->forceFill(['custom_domains' => ['customer.example.test']])->save();
+
+ $this->getJson('/caddy/ask-certificate/fictional-caddy-secret?domain=customer.example.test')
+ ->assertSuccessful()
+ ->assertJson(['success' => true]);
+});
+
+it('rejects an unknown domain even from the pinned proxy', function () {
+ $this->getJson('/caddy/ask-certificate/fictional-caddy-secret?domain=other-product.example.test')
+ ->assertStatus(400)
+ ->assertJson(['message' => 'Unauthorized domain']);
+});
+
+it('rejects a wrong secret before authorizing a certificate', function () {
+ $this->getJson('/caddy/ask-certificate/wrong-secret?domain=customer.example.test')
+ ->assertUnauthorized();
+});
+
+it('does not accept a spoofed proxy header from another IP', function () {
+ $this->withServerVariables(['REMOTE_ADDR' => '198.51.100.20']);
+ $response = $this->withHeader('X-Forwarded-For', '192.0.2.10')
+ ->getJson('/caddy/ask-certificate/fictional-caddy-secret?domain=customer.example.test');
+
+ expect(request()->server('REMOTE_ADDR'))->toBe('198.51.100.20');
+ expect(request()->ip())->toBe('198.51.100.20');
+ $response->assertUnauthorized();
+});
diff --git a/api/tests/Feature/Forms/SignedStorageBackendTest.php b/api/tests/Feature/Forms/SignedStorageBackendTest.php
new file mode 100644
index 000000000..d8fb01ea0
--- /dev/null
+++ b/api/tests/Feature/Forms/SignedStorageBackendTest.php
@@ -0,0 +1,81 @@
+<?php
+
+use App\Http\Controllers\Content\SignedStorageUrlController;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Storage;
+
+beforeEach(function () {
+ config()->set('filesystems.disks.s3', [
+ 'driver' => 's3',
+ 'key' => 'fictional-storage-key',
+ 'secret' => 'fictional-storage-secret',
+ 'region' => 'fr-par',
+ 'bucket' => 'fixture-documents',
+ 'endpoint' => 'https://objects.fixture.test',
+ 'use_path_style_endpoint' => true,
+ ]);
+ Storage::forgetDisk('s3');
+});
+
+it('signs uploads with the configured storage endpoint and credentials without AWS environment variables', function () {
+ $response = app(SignedStorageUrlController::class)->store(new Request([
+ 'content_type' => 'image/png',
+ ]));
+ $data = $response->getData(true);
+
+ expect($response->getStatusCode())->toBe(201)
+ ->and($data['bucket'])->toBe('fixture-documents')
+ ->and($data['key'])->toStartWith('tmp/')
+ ->and($data['url'])->toStartWith('https://objects.fixture.test/fixture-documents/tmp/')
+ ->and($data['headers']['Content-Type'])->toBe('image/png');
+ parse_str(parse_url($data['url'], PHP_URL_QUERY), $query);
+ expect($query['X-Amz-Credential'])->toStartWith('fictional-storage-key/');
+});
+
+it('preserves legacy AWS S3 signing when no custom endpoint is configured', function () {
+ config()->set('filesystems.disks.s3.endpoint', null);
+ config()->set('filesystems.disks.s3.region', 'eu-west-3');
+ Storage::forgetDisk('s3');
+
+ $data = app(SignedStorageUrlController::class)->store(new Request())->getData(true);
+
+ expect(parse_url($data['url'], PHP_URL_HOST))->toBe('s3.eu-west-3.amazonaws.com')
+ ->and($data['bucket'])->toBe('fixture-documents');
+});
+
+it('fails before signing when no bucket is configured', function () {
+ config()->set('filesystems.disks.s3.bucket', null);
+
+ expect(fn () => app(SignedStorageUrlController::class)->store(new Request()))
+ ->toThrow(InvalidArgumentException::class);
+});
+
+it('returns cache metadata with canonically ordered signed headers and independent upload expiry', function () {
+ $data = app(SignedStorageUrlController::class)->store(new Request([
+ 'content_type' => 'application/pdf',
+ 'cache_control' => 'private, max-age=0',
+ 'expires' => '2030-01-01T00:00:00Z',
+ ]))->getData(true);
+ parse_str(parse_url($data['url'], PHP_URL_QUERY), $query);
+ $signed = explode(';', $query['X-Amz-SignedHeaders']);
+ $sorted = $signed;
+ sort($sorted);
+
+ expect($signed)->toBe($sorted)
+ ->and($signed)->toContain('expires', 'host', 'x-amz-acl')
+ ->and($data['headers']['Cache-Control'])->toBe('private, max-age=0')
+ ->and($data['headers']['Expires'])->toBe(['Tue, 01 Jan 2030 00:00:00 GMT'])
+ ->and($query['X-Amz-Expires'])->toBe('300');
+});
+
+it('preserves explicit public assets and default private upload headers', function () {
+ $private = app(SignedStorageUrlController::class)->store(new Request())->getData(true);
+ $public = app(SignedStorageUrlController::class)->store(new Request([
+ 'visibility' => 'public-read',
+ ]))->getData(true);
+
+ expect($private['headers']['x-amz-acl'])->toBe(['private'])
+ ->and($public['headers']['x-amz-acl'])->toBe(['public-read'])
+ ->and($private['headers'])->not->toHaveKey('Cache-Control')
+ ->and($private['headers'])->not->toHaveKey('Expires');
+});
diff --git a/api/tests/Feature/HostedWorkerQueueTest.php b/api/tests/Feature/HostedWorkerQueueTest.php
new file mode 100644
index 000000000..b7ec6c260
--- /dev/null
+++ b/api/tests/Feature/HostedWorkerQueueTest.php
@@ -0,0 +1,27 @@
+<?php
+
+use Illuminate\Queue\Console\WorkCommand;
+use Illuminate\Queue\Worker;
+use Illuminate\Support\Facades\Cache;
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Input\StringInput;
+use Symfony\Component\Console\Output\BufferedOutput;
+
+it('uses the producer queue configuration for the hosted supervisor worker', function (string $queue) {
+ config(['queue.connections.redis.queue' => $queue]);
+ $worker = Mockery::mock(Worker::class);
+ $worker->shouldReceive('setName')->once()->andReturnSelf();
+ $worker->shouldReceive('setCache')->once()->andReturnSelf();
+ $worker->shouldReceive('daemon')->once()->with('redis', $queue, Mockery::any())->andReturn(0);
+
+ $configuration = file_get_contents(base_path('../deploy/scaleway/supervisor-jobs.conf'));
+ preg_match('/^command=php \/app\/artisan queue:work (.+)$/m', $configuration, $matches);
+ $arguments = str_replace('%(ENV_WORKER_TRIES)s', '3', $matches[1]);
+ $command = new WorkCommand($worker, Cache::store());
+ $command->setLaravel(app());
+ $console = new Application();
+ $console->setAutoExit(false);
+ $console->add($command);
+
+ expect($console->run(new StringInput('queue:work '.$arguments), new BufferedOutput()))->toBe(0);
+})->with(['default', 'custom-fixture']);
diff --git a/api/tests/Feature/Security/JwtStorageBindingTest.php b/api/tests/Feature/Security/JwtStorageBindingTest.php
new file mode 100644
index 000000000..57004d89f
--- /dev/null
+++ b/api/tests/Feature/Security/JwtStorageBindingTest.php
@@ -0,0 +1,44 @@
+<?php
+
+use App\Providers\AppServiceProvider;
+use Illuminate\Contracts\Cache\Repository;
+use Illuminate\Support\Facades\Cache;
+use Tymon\JWTAuth\Providers\Storage\Illuminate as JwtStorage;
+
+it('reads existing auth-store revocations with the stock JWT provider without changing the default cache', function () {
+ config([
+ 'cache.stores.auth' => ['driver' => 'array', 'serialize' => true],
+ 'jwt.blacklist_store' => 'auth',
+ ]);
+ (new AppServiceProvider(app()))->register();
+ app()->forgetInstance('tymon.jwt.provider.storage');
+
+ // The removed adapter passed this exact repository to the same stock provider.
+ $legacy = new JwtStorage(Cache::store('auth'));
+ $value = ['valid_until' => time() + 120];
+ $legacy->forever('existing-revocation', $value);
+ $provider = app('tymon.jwt.provider.storage');
+
+ expect(config('jwt.providers.storage'))->toBe(JwtStorage::class)
+ ->and(get_class($provider))->toBe(JwtStorage::class)
+ ->and($provider->get('existing-revocation'))->toBe($value)
+ ->and(Cache::tags('tymon.jwt')->get('existing-revocation'))->toBeNull()
+ ->and(app(Repository::class))->toBe(Cache::store());
+
+ $provider->forever('new-revocation', $value);
+ expect($legacy->get('new-revocation'))->toBe($value)
+ ->and(Cache::tags('tymon.jwt')->get('new-revocation'))->toBeNull();
+});
+
+it('keeps the package default cache when no JWT store is selected', function () {
+ config(['jwt.blacklist_store' => null]);
+ (new AppServiceProvider(app()))->register();
+ app()->forgetInstance('tymon.jwt.provider.storage');
+
+ $provider = app('tymon.jwt.provider.storage');
+ $provider->forever('default-revocation', ['valid_until' => time() + 120]);
+
+ expect(get_class($provider))->toBe(JwtStorage::class)
+ ->and($provider->get('default-revocation'))->toBe(Cache::tags('tymon.jwt')->get('default-revocation'))
+ ->and(Cache::tags('tymon.jwt')->get('default-revocation'))->not->toBeNull();
+});
diff --git a/deploy/scaleway/.gitignore b/deploy/scaleway/.gitignore
new file mode 100644
index 000000000..7a60b85e1
--- /dev/null
+++ b/deploy/scaleway/.gitignore
@@ -0,0 +1,2 @@
+__pycache__/
+*.pyc
diff --git a/deploy/scaleway/Caddyfile.opnform.template b/deploy/scaleway/Caddyfile.opnform.template
new file mode 100644
index 000000000..f1a04820e
--- /dev/null
+++ b/deploy/scaleway/Caddyfile.opnform.template
@@ -0,0 +1,37 @@
+{
+ admin {$CADDY_ADMIN}
+ default_bind {$CADDY_BIND_IP}
+ auto_https disable_redirects
+ storage file_system {
+ root "{$CADDY_STORAGE_ROOT}"
+ }
+ on_demand_tls {
+ ask {$CADDY_ASK_URL}
+ }
+}
+:80 {
+ bind {$CADDY_BIND_IP}
+ @not_health not path /health
+ redir @not_health https://{host}{uri} 308
+ respond /health "opnform: ready"
+}
+:443 {
+ bind {$CADDY_BIND_IP}
+ on_demand
+ }
+ reverse_proxy https://{$OPNFORM_ORIGIN_IP} {
+ transport http {
+ tls_server_name opnform.com
+ }
+ header_up Host opnform.com
+ header_up User-Custom-Domain {host}
+ header_up X-Forwarded-For {remote_host}
+ header_up X-Real-IP {remote_host}
+ header_up True-Client-IP {remote_host}
+ header_up CloudFront-Viewer-Address {remote}
+ header_up -CloudFront-Viewer-Country
+ header_up X-Forwarded-Port {server_port}
+ health_timeout 5s
+ }
+}
diff --git a/deploy/scaleway/Dockerfile.api b/deploy/scaleway/Dockerfile.api
new file mode 100644
index 000000000..fb6564f7a
--- /dev/null
+++ b/deploy/scaleway/Dockerfile.api
@@ -0,0 +1,49 @@
+# syntax=docker/dockerfile:1
+FROM php:8.3.36-fpm-bookworm@sha256:6b4641a875dd3e0f7551b2751e1f5909084856d18166af7fbb522ac230feb702 AS extensions
+RUN apt-get update && apt-get install -y --no-install-recommends libzip-dev libpng-dev libjpeg62-turbo-dev libwebp-dev libpq-dev libicu-dev \
+ && docker-php-ext-configure gd --with-jpeg --with-webp \
+ && docker-php-ext-install -j4 pdo_pgsql gd exif bcmath zip pcntl posix intl opcache \
+ && pecl install redis-6.3.0 && docker-php-ext-enable redis
+
+FROM php:8.3.36-fpm-bookworm@sha256:6b4641a875dd3e0f7551b2751e1f5909084856d18166af7fbb522ac230feb702 AS runtime
+RUN apt-get update && apt-get install -y --no-install-recommends nginx supervisor tini curl ca-certificates libzip4 libpng16-16 libjpeg62-turbo libwebp7 libpq5 libicu72 unzip procps \
+ && rm -rf /var/lib/apt/lists/*
+COPY --from=extensions /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
+COPY --from=extensions /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
+WORKDIR /app
+
+FROM runtime AS build
+COPY --from=composer:2@sha256:af98f42dfff7c68ba8d53c2164fd9fde1087b7d449514baa38c418b1f6bc4bac /usr/bin/composer /usr/local/bin/composer
+COPY api/composer.json api/composer.lock ./
+RUN --mount=type=cache,target=/root/.composer/cache COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --no-scripts --no-autoloader --prefer-dist --no-interaction
+COPY api/app ./app
+COPY api/bootstrap ./bootstrap
+COPY api/config ./config
+COPY api/database ./database
+COPY api/public ./public
+COPY api/resources ./resources
+COPY api/routes ./routes
+COPY api/artisan ./artisan
+RUN mkdir -p storage/framework/cache/data storage/framework/sessions storage/framework/views storage/logs storage/app/public bootstrap/cache \
+ && COMPOSER_ALLOW_SUPERUSER=1 composer dump-autoload --no-dev --optimize \
+ && composer check-platform-reqs --no-dev
+
+FROM runtime AS production
+ARG SOURCE_COMMIT=local-unpublished
+LABEL org.opencontainers.image.source="https://github.com/OpnForm/OpnForm" org.opencontainers.image.revision=$SOURCE_COMMIT
+ENV APP_ROLE=api SELF_HOSTED=false WORKER_COUNT=4 WORKER_TRIES=3
+RUN printf '%s' "$SOURCE_COMMIT" > /app-revision
+COPY --from=build --chown=www-data:www-data /app /app
+COPY deploy/scaleway/nginx.conf /etc/nginx/nginx.conf
+COPY deploy/scaleway/supervisor-*.conf /etc/opnform/
+COPY deploy/scaleway/health.php deploy/scaleway/preflight.php deploy/scaleway/scheduler.php /opt/opnform/
+COPY --chmod=755 deploy/scaleway/entrypoint.sh deploy/scaleway/role-health.sh /usr/local/bin/
+RUN printf 'access.log = /dev/null\n' >> /usr/local/etc/php-fpm.d/zz-docker.conf \
+ && printf 'upload_max_filesize=100M\npost_max_size=110M\nmemory_limit=512M\nexpose_php=Off\n' > /usr/local/etc/php/conf.d/opnform-hosted.ini
+# PHP advisory of 23 Oct: disable upload progress before request parsing.
+RUN printf 'session.upload_progress.enabled=0\n' > /usr/local/etc/php/conf.d/zz-session-upload-progress.ini
+USER www-data
+EXPOSE 8080
+STOPSIGNAL SIGTERM
+HEALTHCHECK --interval=10s --timeout=8s --start-period=90s --retries=3 CMD ["role-health.sh"]
+ENTRYPOINT ["/usr/bin/tini", "--", "entrypoint.sh"]
diff --git a/deploy/scaleway/Dockerfile.client b/deploy/scaleway/Dockerfile.client
new file mode 100644
index 000000000..1452738ba
--- /dev/null
+++ b/deploy/scaleway/Dockerfile.client
@@ -0,0 +1,33 @@
+# syntax=docker/dockerfile:1
+FROM --platform=$BUILDPLATFORM node:24.22.1-bookworm-slim AS build
+WORKDIR /app
+COPY client/package.json client/package-lock.json ./
+RUN --mount=type=cache,target=/root/.npm npm ci --no-audit --no-fund
+COPY client/ ./
+ARG NUXT_PUBLIC_ENV=production
+ARG NUXT_PUBLIC_API_BASE=https://api.opnform.com
+ARG NUXT_PUBLIC_APP_URL=https://opnform.com
+ENV NUXT_PUBLIC_ENV=$NUXT_PUBLIC_ENV NUXT_PUBLIC_API_BASE=$NUXT_PUBLIC_API_BASE NUXT_PUBLIC_APP_URL=$NUXT_PUBLIC_APP_URL
+ENV NUXT_TELEMETRY_DISABLED=1 NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096
+# Builds must not fetch live forms, CMS contents or telemetry.
+ARG SOURCE_COMMIT=local-unpublished
+# Nitro indexes public assets at build time; adding this file afterwards is not served.
+RUN printf '{"revision":"%s"}\n' "$SOURCE_COMMIT" > /app/public/release.json
+RUN --network=none npm run build
+# The host-native JS build may only emit architecture-independent runtime files.
+RUN test -z "$(find /app/.output -type f -name '*.node' -print -quit)"
+
+FROM node:24.22.1-bookworm-slim AS production
+ARG SOURCE_COMMIT=local-unpublished
+LABEL org.opencontainers.image.source="https://github.com/OpnForm/OpnForm" org.opencontainers.image.revision=$SOURCE_COMMIT
+ENV NODE_ENV=production NITRO_HOST=0.0.0.0 NITRO_PORT=3000
+WORKDIR /app
+COPY --from=build --chown=node:node /app/.output/ ./
+RUN printf '%s' "$SOURCE_COMMIT" > /app-revision \
+ && printf '{"revision":"%s"}\n' "$SOURCE_COMMIT" > /app/public/release.json
+USER node
+EXPOSE 3000
+STOPSIGNAL SIGTERM
+HEALTHCHECK --interval=10s --timeout=8s --start-period=90s --retries=3 CMD node -e "const q=require('node:http').get({hostname:'127.0.0.1',port:3000,path:'/login',headers:{Host:new URL(process.env.NUXT_PUBLIC_APP_URL||'https://opnform.com').host,'X-Forwarded-Proto':'https'}},r=>{r.resume();process.exit(r.statusCode===200?0:1)});q.setTimeout(6000,()=>{q.destroy();process.exit(1)});q.on('error',()=>process.exit(1))"
+ENTRYPOINT ["/usr/local/bin/node"]
+CMD ["/app/server/index.mjs"]
diff --git a/deploy/scaleway/auto-release.py b/deploy/scaleway/auto-release.py
new file mode 100644
index 000000000..adefe3e0e
--- /dev/null
+++ b/deploy/scaleway/auto-release.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python3
+"""Private outbound-only OpnForm controller. Installed code is never downloaded/executed."""
+import argparse
+import fcntl
+import importlib.util
+import json
+import os
+from pathlib import Path
+import subprocess
+import tempfile
+
+CHANNEL = 'ghcr.io/opnform/hosted-release:production'
+spec = importlib.util.spec_from_file_location('promotion', Path(__file__).with_name('coolify-service-release.py'))
+promotion = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(promotion)
+
+
+def eligible_run():
+ current = promotion.github('/repos/OpnForm/OpnForm/commits/main')['sha']
+ runs = promotion.github('/repos/OpnForm/OpnForm/actions/workflows/ci-cd.yml/runs?branch=main&event=push&status=success&per_page=10')['workflow_runs']
+ for run in runs:
+ if run['head_sha'] != current or run.get('name') != 'CI/CD Pipeline':
+ continue
+ artifacts = promotion.github('/repos/OpnForm/OpnForm/actions/runs/' + str(run['id']) + '/artifacts')['artifacts']
+ if any(a['name'] == 'opnform-coolify-release' and not a.get('expired') for a in artifacts):
+ return run
+ return None
+
+
+def fetch_release(directory):
+ promotion.execute(['docker', 'pull', CHANNEL], timeout=120)
+ # Bind extraction to the pulled image ID, never to a subsequently moved tag.
+ image = json.loads(promotion.execute(['docker', 'image', 'inspect', CHANNEL], text=True))[0]
+ container = promotion.execute(['docker', 'create', '--network', 'none', image['Id'], '/not-executed'], text=True).strip()
+ try:
+ path = directory / 'release.json'
+ promotion.execute(['docker', 'cp', container + ':/release.json', str(path)])
+ if path.stat().st_size > 65536:
+ raise ValueError('Oversized release descriptor')
+ release = json.loads(path.read_text())
+ promotion.validate_release(release)
+ if release['automatic_deployment'] is not True:
+ raise ValueError('Release is not eligible for automatic deployment')
+ if image['Config'].get('Labels', {}).get('org.opencontainers.image.revision') != release['sha']:
+ raise ValueError('Deployment channel revision mismatch')
+ return release, path
+ finally:
+ promotion.execute(['docker', 'rm', container])
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--target', required=True, type=Path)
+ parser.add_argument('--state-dir', required=True, type=Path)
+ parser.add_argument('--check-only', action='store_true')
+ args = parser.parse_args()
+ os.umask(0o077)
+ args.state_dir.mkdir(parents=True, exist_ok=True)
+ with (args.state_dir / 'controller.lock').open('w') as handle:
+ fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ target = json.loads(args.target.read_text())
+ promotion.validate_target(target)
+ state_file = args.state_dir / 'state.json'
+ state = json.loads(state_file.read_text()) if state_file.exists() else {}
+ if state.get('status') in ('deploying', 'needs-inspection'):
+ raise RuntimeError('Prior deployment requires inspection; no automatic retry')
+ run = eligible_run()
+ if not run:
+ print('No eligible main release; production unchanged.')
+ return
+ sequence = [run['id'], run['run_attempt']]
+ if state.get('sequence') == sequence:
+ return
+ with tempfile.TemporaryDirectory(prefix='release-', dir=args.state_dir) as temporary:
+ release, path = fetch_release(Path(temporary))
+ if [release['run_id'], release['run_attempt']] != sequence or release['sha'] != run['head_sha']:
+ print('Waiting for the matching successful main deployment channel.')
+ return
+ promotion.verify_ci(release)
+ promotion.controller(target, release)
+ promotion.check_current(target)
+ if args.check_only:
+ print('Eligible main release and private target verified; no deployment requested.')
+ return
+ state = {'sequence': sequence, 'sha': release['sha'], 'status': 'deploying'}
+ state_file.write_text(json.dumps(state) + '\n')
+ journal = args.state_dir / ('deployment-' + str(run['id']) + '-' + str(run['run_attempt']) + '.json')
+ try:
+ subprocess.run(['python3', str(Path(__file__).with_name('coolify-service-release.py')),
+ str(path), '--target', str(args.target), '--apply', '--allow-service-restart',
+ '--journal', str(journal)], check=True)
+ state['status'] = 'success'
+ state_file.write_text(json.dumps(state) + '\n')
+ except Exception:
+ if not journal.exists() and promotion.github('/repos/OpnForm/OpnForm/commits/main')['sha'] != release['sha']:
+ state['status'] = 'superseded-before-selection'
+ state_file.write_text(json.dumps(state) + '\n')
+ return
+ state['status'] = 'needs-inspection'
+ state_file.write_text(json.dumps(state) + '\n')
+ raise RuntimeError('Deployment stopped; inspect private journal before retry') from None
+
+
+if __name__ == '__main__':
+ main()
diff --git a/deploy/scaleway/coolify-service-release.py b/deploy/scaleway/coolify-service-release.py
new file mode 100644
index 000000000..f5e574f9a
--- /dev/null
+++ b/deploy/scaleway/coolify-service-release.py
@@ -0,0 +1,324 @@
+#!/usr/bin/env python3
+"""Private promotion for the five-role Coolify Compose service.
+
+The default is a read-only plan. The installed main-release controller applies
+successful main releases with --apply --allow-service-restart.
+"""
+import argparse
+import base64
+import fcntl
+import hashlib
+import ipaddress
+import inspect
+import json
+import os
+from pathlib import Path
+import re
+import subprocess
+import time
+import urllib.request
+
+ROLES = ('api', 'frontend', 'jobs', 'scheduler', 'migrate')
+
+
+def native_image_name(image):
+ """Docker archives retain tags, not registry RepoDigests, across engines."""
+ package, digest = image.split('@sha256:')
+ role = package.rsplit('/', 1)[-1]
+ return 'opnform-' + role + ':sha256-' + digest
+
+
+def image_fingerprint(meta):
+ # Image IDs can denote a config or an OCI index depending on the engine.
+ # Bind the actual layers and runtime configuration instead of comparing types.
+ record = {name: meta[name] for name in ('Architecture', 'Os', 'RootFS')}
+ # Classic Docker adds legacy container-creation fields that containerd omits.
+ # Missing and null OCI defaults have the same runtime meaning.
+ record['Config'] = {name: meta['Config'].get(name) for name in (
+ 'Env', 'Entrypoint', 'Cmd', 'User', 'WorkingDir', 'Labels', 'ExposedPorts',
+ 'Volumes', 'StopSignal', 'Healthcheck', 'Shell')}
+ return hashlib.sha256(json.dumps(record, sort_keys=True).encode()).hexdigest()
+
+
+def execute(args, timeout=120, **kwargs):
+ result = subprocess.run(args, capture_output=True, timeout=timeout, **kwargs)
+ if result.returncode:
+ raise RuntimeError(args[0] + ' failed; remote output withheld')
+ return result.stdout
+
+
+def validate_release(release):
+ if (release.get('schema') != 'opnform-coolify-service-release/v1'
+ or release.get('repository') != 'OpnForm/OpnForm'
+ or release.get('ref') != 'refs/heads/main'
+ or not re.fullmatch('[0-9a-f]{40}', release.get('sha', ''))
+ or type(release.get('automatic_deployment')) is not bool):
+ raise ValueError('A validated OpnForm main release is required')
+ for name in ('run_id', 'run_attempt'):
+ if type(release.get(name)) is not int or release[name] <= 0:
+ raise ValueError('Missing CI run identity')
+ if set(release.get('images', {})) != {'backend', 'frontend'}:
+ raise ValueError('A complete image pair is required')
+ for role, image in release['images'].items():
+ if not re.fullmatch(re.escape('ghcr.io/opnform/hosted-' + role + '@sha256:') + '[0-9a-f]{64}', image):
+ raise ValueError('Refusing a foreign or mutable image reference')
+
+
+def validate_target(target):
+ if (target.get('product') != 'opnform'
+ or not re.fullmatch('[a-z0-9]{20,32}', target.get('service_uuid', ''))):
+ raise ValueError('Explicit private OpnForm service allowlist required')
+ for name in ('server_id', 'project_id', 'team_id'):
+ if type(target.get(name)) is not int or target[name] < 0:
+ raise ValueError('Invalid private resource allowlist')
+ for name in ('controller_alias', 'native_alias'):
+ if not re.fullmatch('[a-zA-Z0-9_-]+', target.get(name, '')):
+ raise ValueError('Invalid SSH alias')
+ if ipaddress.ip_address(target['native_address']) not in ipaddress.ip_network('100.64.0.0/10'):
+ raise ValueError('The allowlisted native server must use Tailscale')
+ config = Path(target['ssh_config'])
+ if not config.is_absolute() or not config.is_file() or config.stat().st_mode & 0o077:
+ raise ValueError('Use a private absolute SSH config file')
+ for role in ('backend', 'frontend'):
+ if not re.fullmatch('sha256:[0-9a-f]{64}', target.get('expected_current_images', {}).get(role, '')):
+ raise ValueError('Pin the currently running image identities before promotion')
+ for name in ('api_url', 'frontend_url'):
+ expected = 'https://api.opnform.com' if name == 'api_url' else 'https://opnform.com'
+ if target.get(name) != expected:
+ raise ValueError('Refusing another product domain')
+
+
+def ssh(target, alias):
+ base = ['ssh', '-F', target['ssh_config'], '-o', 'BatchMode=yes', '-o',
+ 'StrictHostKeyChecking=yes', '-o', 'UpdateHostKeys=no', '-o',
+ 'ForwardAgent=no', '-o', 'IdentitiesOnly=yes', alias]
+ effective = execute(base[:-1] + ['-G', alias], text=True)
+ options = dict(line.split(' ', 1) for line in effective.splitlines() if ' ' in line)
+ try:
+ address = ipaddress.ip_address(options['hostname'])
+ if address not in ipaddress.ip_network('100.64.0.0/10'):
+ raise ValueError('SSH must remain on Tailscale')
+ if alias == target['native_alias'] and str(address) != target['native_address']:
+ raise ValueError('Native SSH alias differs from the allowlisted server address')
+ except (KeyError, ValueError):
+ raise ValueError('SSH must use an explicitly pinned Tailscale address') from None
+ return base
+
+
+def verify_ci(release):
+ run = github('/repos/OpnForm/OpnForm/actions/runs/' + str(release['run_id']))
+ if (run.get('name') != 'CI/CD Pipeline' or run.get('head_sha') != release['sha']
+ or run.get('head_branch') != 'main' or run.get('event') != 'push'
+ or run.get('status') != 'completed' or run.get('conclusion') != 'success'
+ or run.get('run_attempt') != release['run_attempt']):
+ raise ValueError('The exact main revision needs a fully successful CI run')
+ current = github('/repos/OpnForm/OpnForm/commits/main')
+ if current['sha'] != release['sha']:
+ raise ValueError('A newer main revision exists; do not silently deploy stale code')
+
+
+def github(path):
+ token = os.environ.get('GH_TOKEN')
+ if not token:
+ return json.loads(execute(['gh', 'api', path], text=True))
+ request = urllib.request.Request('https://api.github.com' + path, headers={
+ 'Authorization': 'Bearer ' + token, 'Accept': 'application/vnd.github+json',
+ 'User-Agent': 'opnform-production-release'})
+ with urllib.request.urlopen(request, timeout=30) as response:
+ return json.load(response)
+
+
+def controller(target, release, apply=False, finish=False):
+ payload = base64.b64encode(json.dumps({'target': target, 'release': release,
+ 'release_id': release['sha'] + '-' + str(release['run_id']) + '-' + str(release['run_attempt']),
+ 'native_images': {role: native_image_name(image) for role, image in release['images'].items()},
+ 'apply': apply, 'finish': finish}).encode()).decode()
+ program = r'''<?php
+require '/var/www/html/vendor/autoload.php';
+$app=require '/var/www/html/bootstrap/app.php';
+$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+$x=json_decode(base64_decode('__PAYLOAD__'),true,512,JSON_THROW_ON_ERROR);$t=$x['target'];
+$s=App\Models\Service::where('uuid',$t['service_uuid'])->sole();
+if($s->server_id!==$t['server_id']||$s->environment->project->id!==$t['project_id']||$s->environment->project->team_id!==$t['team_id'])throw new RuntimeException('Resource allowlist mismatch');
+if($s->server->ip!==$t['native_address'])throw new RuntimeException('Native address mismatch');
+$raw=json_decode($s->docker_compose_raw,true,512,JSON_THROW_ON_ERROR);
+$roles=['api','frontend','jobs','scheduler','migrate'];
+if(array_diff($roles,array_keys($raw['services']))||array_diff(array_keys($raw['services']),$roles))throw new RuntimeException('Unexpected service roles');
+$dir='/var/www/html/storage/app/opnform-release-history/'.$s->uuid;$lease=$dir.'/.promotion-active';
+if($x['finish']){
+ $active=json_decode(file_get_contents($lease),true,512,JSON_THROW_ON_ERROR);
+ if($active['release_id']!==$x['release_id'])throw new RuntimeException('Promotion lease differs');
+ if(!unlink($lease))throw new RuntimeException('Cannot release promotion lease');
+}elseif(file_exists($lease))throw new RuntimeException('Prior promotion needs inspection');
+if($x['apply']){
+ if(!is_dir($dir)&&!mkdir($dir,0700,true))throw new RuntimeException('Cannot save previous configuration');
+ $handle=fopen($lease,'x');if($handle===false)throw new RuntimeException('Another promotion acquired the service');
+ chmod($lease,0600);fwrite($handle,json_encode(['release_id'=>$x['release_id'],'started_at'=>time()]));fclose($handle);
+ $file=$dir.'/'.$x['release_id'].'.json';
+ if(file_exists($file))throw new RuntimeException('Prior promotion needs inspection');
+ if(file_put_contents($file,$s->docker_compose_raw,LOCK_EX)===false)throw new RuntimeException('Cannot save previous configuration');chmod($file,0600);
+ foreach($roles as$r)$raw['services'][$r]['image']=$x['native_images'][$r==='frontend'?'frontend':'backend'];
+ $s->docker_compose_raw=json_encode($raw,JSON_THROW_ON_ERROR);$s->save();$s->parse();$s->saveComposeConfigs();
+}
+echo json_encode(['service_uuid'=>$s->uuid,'server_id'=>$s->server_id,'images_selected'=>$x['apply'],'containers_restarted'=>false]);
+'''.replace('__PAYLOAD__', payload)
+ command = (['docker', 'exec', '-i', 'coolify', 'php'] if target.get('controller_local') is True
+ else ssh(target, target['controller_alias']) + ['docker exec -i coolify php'])
+ return json.loads(execute(command, input=program, text=True))
+
+
+def native(target, program):
+ return json.loads(execute(ssh(target, target['native_alias']) + ['python3 -'], input=program, text=True))
+
+
+def check_current(target):
+ payload = json.dumps({'uuid': target['service_uuid'], 'expected': target['expected_current_images']})
+ return native(target, """import subprocess,json
+x=json.loads(__PAYLOAD__);roles=['api','frontend','jobs','scheduler']
+rows=json.loads(subprocess.check_output(['docker','inspect',*[r+'-'+x['uuid']for r in roles]]))
+for r in rows:
+ role=r['Name'].lstrip('/').split('-')[0];component='frontend'if role=='frontend'else'backend'
+ assert r['Image']==x['expected'][component],'Live image identity drifted'
+ assert r['State']['Running']and r['State'].get('Health',{}).get('Status')=='healthy','Live role is not healthy'
+print(json.dumps({'current_roles_healthy':True,'current_image_identities_match':True}))
+""".replace('__PAYLOAD__', repr(payload)))
+
+
+def stage_images(target, release):
+ for image in release['images'].values():
+ execute(['docker', 'pull', '--platform', 'linux/amd64', image], timeout=900)
+ meta = json.loads(execute(['docker', 'image', 'inspect', image], text=True))[0]
+ if (meta['Config']['Labels'].get('org.opencontainers.image.revision') != release['sha']
+ or meta['Architecture'] != 'amd64' or meta['Os'] != 'linux'):
+ raise ValueError('Image revision differs from the reviewed release')
+ selected = native_image_name(image)
+ execute(['docker', 'tag', image, selected])
+ source = subprocess.Popen(['docker', 'save', selected], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
+ try:
+ loaded = subprocess.run(ssh(target, target['native_alias']) + ['docker load'],
+ stdin=source.stdout, capture_output=True, timeout=1200)
+ source.stdout.close()
+ if source.wait(timeout=30) or loaded.returncode:
+ raise RuntimeError('Private image staging failed; live containers unchanged')
+ finally:
+ if source.poll() is None:
+ source.terminate()
+ expected = image_fingerprint(meta)
+ observed = native(target, 'import subprocess,json,hashlib\n' + inspect.getsource(image_fingerprint)
+ + "\nx=json.loads(subprocess.check_output(['docker','image','inspect'," + repr(selected)
+ + "]))[0]\nprint(json.dumps({'fingerprint':image_fingerprint(x)}))\n")
+ if observed['fingerprint'] != expected:
+ raise ValueError('Staged image layers/configuration differ from the registry image')
+
+
+def remember_current_images(target, release, path):
+ """Advance the private image pins only after every role and public gate passed."""
+ references = {role: native_image_name(image) for role, image in release['images'].items()}
+ payload = repr(json.dumps({'uuid': target['service_uuid'], 'images': references}))
+ images = native(target, """import json,subprocess
+x=json.loads(__PAYLOAD__)
+expected={role:json.loads(subprocess.check_output(['docker','image','inspect',image]))[0]['Id']for role,image in x['images'].items()}
+for role in ['api','frontend','jobs','scheduler']:
+ row=json.loads(subprocess.check_output(['docker','inspect',role+'-'+x['uuid']]))[0]
+ assert row['State']['Running']and row['State'].get('Health',{}).get('Status')=='healthy'
+ assert row['Image']==expected['frontend'if role=='frontend'else'backend']
+print(json.dumps(expected))
+""".replace('__PAYLOAD__', payload))
+ updated = {**target, 'expected_current_images': images}
+ temporary = path.with_suffix('.next')
+ temporary.write_text(json.dumps(updated, indent=2) + '\n')
+ temporary.chmod(0o600)
+ temporary.replace(path)
+
+
+def promote(target, release, journal):
+ payload = repr(json.dumps({'uuid': target['service_uuid'], 'sha': release['sha']}))
+ program = r'''import subprocess,json,pathlib,time
+x=json.loads(__PAYLOAD__);base=pathlib.Path('/data/coolify/services')/x['uuid'];assert base.is_dir()
+compose=['docker','compose','--project-directory',str(base),'--env-file',str(base/'.env'),'-f',str(base/'docker-compose.yml')]
+def run(args):
+ p=subprocess.run(args,capture_output=True,text=True,timeout=4000)
+ if p.returncode:raise RuntimeError('Role operation failed; inspect private Docker logs')
+ return p.stdout.strip()
+def healthy(name,seconds=240):
+ end=time.monotonic()+seconds
+ while time.monotonic()<end:
+ row=json.loads(run(['docker','inspect',name]))[0]
+ if row['State'].get('Health',{}).get('Status')=='healthy':return
+ if not row['State']['Running']:raise RuntimeError('Role exited before health')
+ time.sleep(3)
+ raise RuntimeError('Health timeout; inspect before retry')
+migration='opnform-release-migrate-'+x['sha'][:16]
+run(compose+['--profile','schema-migration','run','-d','--no-deps','--pull','never','--name',migration,'migrate'])
+healthy(migration,1800)
+# Migration readiness is a marker; its process intentionally keeps sleeping.
+run(['docker','stop','--time','20',migration]);run(['docker','rm',migration])
+for role in ['jobs','scheduler']:
+ run(['docker','stop','--time','3700',role+'-'+x['uuid']])
+for role,profile in [('api','application-prepared'),('frontend','application-prepared'),('jobs','writers-approved'),('scheduler','writers-approved')]:
+ run(compose+['--profile',profile,'up','-d','--no-deps','--pull','never',role]);healthy(role+'-'+x['uuid'])
+print(json.dumps({'roles_healthy':True,'revision':x['sha']}))
+'''.replace('__PAYLOAD__', payload)
+ # The long wait is confined to an explicitly requested promotion, never CI/merge.
+ result = subprocess.run(ssh(target, target['native_alias']) + ['python3 -'], input=program,
+ text=True, capture_output=True, timeout=12000)
+ if result.returncode:
+ raise RuntimeError('Promotion stopped; inspect journal and private role logs before retry')
+ journal['runtime'] = json.loads(result.stdout)
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('release', type=Path)
+ parser.add_argument('--target', required=True, type=Path)
+ parser.add_argument('--apply', action='store_true')
+ parser.add_argument('--allow-service-restart', action='store_true')
+ parser.add_argument('--journal', type=Path)
+ args = parser.parse_args()
+ release = json.loads(args.release.read_text()); target = json.loads(args.target.read_text())
+ validate_release(release); validate_target(target); verify_ci(release)
+ controller(target, release); check_current(target)
+ if not args.apply:
+ print(json.dumps({'plan_only': True, 'sha': release['sha'], 'service': target['service_uuid'],
+ 'images': release['images'], 'roles': ROLES, 'live_containers_unchanged': True}))
+ return
+ if not args.allow_service_restart or not args.journal:
+ parser.error('Promotion requires --allow-service-restart and a private --journal')
+ os.umask(0o077)
+ with args.journal.with_suffix('.lock').open('w') as lock:
+ fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ if args.journal.exists():
+ raise RuntimeError('A prior promotion journal exists; reconcile it before retry')
+ stage_images(target, release)
+ verify_ci(release)
+ check_current(target)
+ journal = {'sha': release['sha'], 'started_at': time.time(), 'status': 'selecting-images',
+ 'previous_images': target['expected_current_images']}
+ def save():
+ args.journal.write_text(json.dumps(journal, indent=2) + '\n')
+ save()
+ try:
+ controller(target, release, apply=True)
+ journal['status'] = 'migrating-and-promoting'; save()
+ promote(target, release, journal)
+ for base, route in [(target['api_url'], '/healthz'), (target['frontend_url'], '/release.json')]:
+ with urllib.request.urlopen(base + route, timeout=20) as response:
+ if json.load(response).get('revision') != release['sha']:
+ raise RuntimeError('Public revision does not match the selected release')
+ remember_current_images(target, release, args.target)
+ controller(target, release, finish=True)
+ journal['status'] = 'success'; journal['finished_at'] = time.time(); save()
+ except Exception:
+ journal['status'] = 'needs-inspection'; save()
+ raise
+ if target.get('controller_local') is True:
+ # Only this controller's just-staged references; never native images
+ # or a shared Docker prune. Images still in use cannot be removed.
+ for image in release['images'].values():
+ for reference in (native_image_name(image), image):
+ subprocess.run(['docker', 'image', 'rm', reference], capture_output=True, timeout=60)
+ print('Selected release is healthy. AWS, DNS, databases and other services were not reconfigured.')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/deploy/scaleway/entrypoint.sh b/deploy/scaleway/entrypoint.sh
new file mode 100644
index 000000000..5d6389269
--- /dev/null
+++ b/deploy/scaleway/entrypoint.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+set -eu
+cd /app
+case "${APP_ROLE:-api}" in api|jobs|scheduler|migrate) ;; *) echo 'Unknown APP_ROLE' >&2; exit 64;; esac
+rm -f bootstrap/cache/config.php
+php /opt/opnform/preflight.php
+# Compile only local runtime configuration. Never flush the shared cache here.
+php artisan config:cache --no-interaction
+case "${APP_ROLE:-api}" in
+ api) exec supervisord -c /etc/opnform/supervisor-api.conf ;;
+ jobs) exec supervisord -c /etc/opnform/supervisor-jobs.conf ;;
+ scheduler) exec php /opt/opnform/scheduler.php ;;
+ migrate)
+ rm -f /tmp/opnform-migration-ok
+ if php artisan mcp:check-oauth-keys --environment-only --no-interaction && php artisan migrate --force --isolated=75 --no-interaction; then
+ touch /tmp/opnform-migration-ok
+ else
+ echo 'Migration gate failed; resource will remain unhealthy' >&2
+ fi
+ exec sleep infinity ;;
+esac
diff --git a/deploy/scaleway/health.php b/deploy/scaleway/health.php
new file mode 100644
index 000000000..600273a7c
--- /dev/null
+++ b/deploy/scaleway/health.php
@@ -0,0 +1,16 @@
+<?php
+try {
+ require '/app/vendor/autoload.php';
+ $app = require '/app/bootstrap/app.php';
+ $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+ Illuminate\Support\Facades\DB::select('SELECT 1');
+ Illuminate\Support\Facades\Redis::connection(config('queue.connections.redis.connection'))->ping();
+ Illuminate\Support\Facades\Redis::connection('cache')->ping();
+ header('Cache-Control: no-store');
+ header('Content-Type: application/json');
+ echo json_encode(['status' => 'ok', 'revision' => trim(file_get_contents('/app-revision'))]);
+} catch (Throwable $error) {
+ http_response_code(503);
+ echo '{"status":"error"}';
+ exit(1);
+}
diff --git a/deploy/scaleway/nginx.conf b/deploy/scaleway/nginx.conf
new file mode 100644
index 000000000..a9c66037a
--- /dev/null
+++ b/deploy/scaleway/nginx.conf
@@ -0,0 +1,34 @@
+worker_processes auto;
+pid /tmp/nginx.pid;
+error_log /dev/stderr warn;
+events { worker_connections 1024; }
+http {
+ include /etc/nginx/mime.types;
+ access_log /dev/stdout;
+ client_body_temp_path /tmp/nginx-body;
+ fastcgi_temp_path /tmp/nginx-fastcgi;
+ proxy_temp_path /tmp/nginx-proxy;
+ uwsgi_temp_path /tmp/nginx-uwsgi;
+ scgi_temp_path /tmp/nginx-scgi;
+ server {
+ listen 8080;
+ root /app/public;
+ index index.php;
+ server_tokens off;
+ client_max_body_size 100m;
+ location = /healthz {
+ include fastcgi_params;
+ fastcgi_pass 127.0.0.1:9000;
+ fastcgi_param SCRIPT_FILENAME /opt/opnform/health.php;
+ }
+ location / { try_files $uri /index.php?$query_string; }
+ location = /index.php {
+ include fastcgi_params;
+ fastcgi_pass 127.0.0.1:9000;
+ fastcgi_param SCRIPT_FILENAME /app/public/index.php;
+ fastcgi_read_timeout 120s;
+ }
+ location ~ \.php$ { return 404; }
+ location ~ /\. { deny all; }
+ }
+}
diff --git a/deploy/scaleway/preflight.php b/deploy/scaleway/preflight.php
new file mode 100644
index 000000000..4737a5b69
--- /dev/null
+++ b/deploy/scaleway/preflight.php
@@ -0,0 +1,115 @@
+<?php
+// Hosted runtime only; fail before consumers start. Never prints variable values.
+use Illuminate\Support\Facades\Cache;
+
+require '/app/vendor/autoload.php';
+$app = require '/app/bootstrap/app.php';
+$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+$fail = static function (string $message): never {
+ fwrite(STDERR, $message."\n");
+ exit(78);
+};
+if (config('app.self_hosted') || config('app.debug')) {
+ $fail('Hosted runtime requires SELF_HOSTED=false and APP_DEBUG=false');
+}
+// Vapor otherwise defaults to trusting every caller, including spoofed X-Forwarded-For.
+$proxies = config('trustedproxy.proxies');
+$proxies = is_string($proxies) ? array_map('trim', explode(',', $proxies)) : $proxies;
+if (! is_array($proxies) || ! $proxies) {
+ $fail('Hosted runtime requires an explicit TRUSTED_PROXIES allowlist');
+}
+foreach ($proxies as $proxy) {
+ $parts = explode('/', (string) $proxy);
+ $ip = $parts[0];
+ $bits = str_contains($ip, ':') ? 128 : 32;
+ if (! filter_var($ip, FILTER_VALIDATE_IP) || count($parts) > 2
+ || (isset($parts[1]) && (! ctype_digit($parts[1]) || (int) $parts[1] < 8 || (int) $parts[1] > $bits))) {
+ $fail('TRUSTED_PROXIES must contain explicit IPs or narrow CIDRs');
+ }
+}
+$key = (string) config('app.key');
+if (str_starts_with($key, 'base64:')) {
+ $key = base64_decode(substr($key, 7), true) ?: '';
+}
+if (! Illuminate\Encryption\Encrypter::supported($key, config('app.cipher')) || strlen((string) config('jwt.secret')) < 32) {
+ $fail('APP_KEY and a valid JWT signing secret must be supplied; never generate replacements');
+}
+if (config('queue.default') !== 'redis' || config('database.default') !== 'pgsql') {
+ $fail('Hosted runtime requires PostgreSQL and Redis queues');
+}
+if (config('queue.connections.redis.retry_after') <= 3650) {
+ $fail('REDIS_QUEUE_RETRY_AFTER must exceed worker and job shutdown limits (3650 seconds)');
+}
+if (! preg_match('/^[1-9][0-9]?$/', getenv('WORKER_COUNT') ?: '4')) {
+ $fail('WORKER_COUNT must be an integer between 1 and 99');
+}
+if (! preg_match('/^[1-9][0-9]?$/', getenv('WORKER_TRIES') ?: '3')) {
+ $fail('WORKER_TRIES must be an integer between 1 and 99');
+}
+// Preserve the live Laravel cache/auth/session bindings; there is no import mode.
+if (config('cache.default') !== 'redis' || config('cache.stores.redis.connection') !== 'state'
+ || config('session.driver') !== 'redis' || config('session.store') !== 'auth'
+ || config('session.connection') !== 'auth'
+ || config('jwt.providers.storage') !== Tymon\JWTAuth\Providers\Storage\Illuminate::class
+ || config('jwt.blacklist_store') !== 'auth'
+ || config('jwt.blacklist_enabled') !== true) {
+ $fail('Hosted runtime requires the existing Redis cache, session and JWT stores');
+}
+try {
+ $servers = $databases = $prefixes = [];
+ foreach (['default', 'cache', 'auth', 'state'] as $name) {
+ $settings = config('database.redis.'.$name);
+ if (! is_array($settings) || (empty($settings['url']) && empty($settings['host']))) {
+ throw new RuntimeException('Explicit logical Redis bindings are required');
+ }
+ $connection = app('redis')->connection($name);
+ $server = $connection->info('server');
+ $servers[$name] = $server['run_id'] ?? $server['Server']['run_id'] ?? null;
+ $databases[$name] = $connection->client()->getDBNum();
+ $prefixes[$name] = $connection->client()->getOption(\Redis::OPT_PREFIX);
+ if (! is_string($servers[$name]) || $servers[$name] === ''
+ || ! is_int($databases[$name]) || ! is_string($prefixes[$name]) || $prefixes[$name] === '') {
+ throw new RuntimeException('Effective Redis identity, DB or product prefix is unavailable');
+ }
+ }
+ if (count(array_unique($servers)) !== 1 || count(array_unique($databases)) !== 4
+ || count(array_unique($prefixes)) !== 1) {
+ throw new RuntimeException('One Redis requires four distinct effective DBs and one explicit product prefix');
+ }
+ $logical = ['default' => 'queues:'];
+ foreach (['cache' => 'volatile', 'auth' => 'auth', 'state' => 'redis'] as $connection => $storeName) {
+ $store = Cache::store($storeName)->getStore();
+ if ($store->connection() !== app('redis')->connection($connection)) {
+ throw new RuntimeException('Effective cache/auth/state store connection differs from its role');
+ }
+ $logical[$connection] = $store->getPrefix();
+ if (! is_string($logical[$connection]) || $logical[$connection] === '') {
+ throw new RuntimeException('Each Redis role requires its own nonempty key prefix');
+ }
+ }
+ foreach ($logical as $left => $prefix) {
+ foreach ($logical as $right => $other) {
+ if ($left !== $right && (str_starts_with($prefix, $other) || str_starts_with($other, $prefix))) {
+ throw new RuntimeException('Redis logical role prefixes overlap');
+ }
+ }
+ }
+ $state = app('redis')->connection('state');
+ $policy = $state->command('config', ['GET', 'maxmemory-policy']);
+ $sync = $state->command('config', ['GET', 'appendfsync']);
+ $limit = $state->command('config', ['GET', 'maxmemory']);
+ $persistence = $state->info('persistence');
+ $persistence = $persistence['Persistence'] ?? $persistence;
+ $memory = $state->info('memory');
+ $memory = $memory['Memory'] ?? $memory;
+ if (($policy['maxmemory-policy'] ?? null) !== 'noeviction'
+ || ($sync['appendfsync'] ?? null) !== 'always'
+ || (int) ($limit['maxmemory'] ?? 0) <= 0
+ || (int) ($memory['used_memory'] ?? PHP_INT_MAX) >= (int) ($limit['maxmemory'] ?? 0)
+ || ($persistence['aof_enabled'] ?? null) !== 1
+ || ($persistence['aof_last_write_status'] ?? null) !== 'ok') {
+ throw new RuntimeException('Shared Redis requires AOF/always/noeviction and available bounded memory');
+ }
+} catch (RuntimeException $exception) {
+ $fail($exception->getMessage());
+}
diff --git a/deploy/scaleway/publish-release.py b/deploy/scaleway/publish-release.py
new file mode 100644
index 000000000..a46b80188
--- /dev/null
+++ b/deploy/scaleway/publish-release.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python3
+"""Publish only the tested local image pair; never contact Coolify or AWS."""
+import argparse
+import json
+import os
+from pathlib import Path
+import re
+import subprocess
+import tempfile
+
+
+def command(*args):
+ result = subprocess.run(args, capture_output=True, text=True, timeout=900)
+ if result.returncode:
+ raise RuntimeError(args[0] + ' failed; inspect the scoped CI step')
+ return result.stdout.strip()
+
+
+def package_is_private(name, allow_missing=False):
+ response = subprocess.run(['gh', 'api', '/orgs/opnform/packages/container/' + name],
+ capture_output=True, text=True, timeout=30)
+ if response.returncode:
+ if allow_missing and '(HTTP 404)' in response.stderr:
+ return
+ raise RuntimeError('Cannot verify the private registry package')
+ if json.loads(response.stdout).get('visibility') != 'private':
+ raise RuntimeError('Hosted images must remain private')
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--output', required=True, type=Path)
+ args = parser.parse_args()
+ sha = os.environ['GITHUB_SHA']
+ if (os.environ.get('GITHUB_REPOSITORY') != 'OpnForm/OpnForm'
+ or os.environ.get('GITHUB_REF') != 'refs/heads/main'
+ or os.environ.get('GITHUB_EVENT_NAME') != 'push'
+ or not re.fullmatch('[0-9a-f]{40}', sha)):
+ raise RuntimeError('Only a tested main push can publish a hosted release')
+ images = {}
+ for role, local, package in [('backend', 'opnform-scaleway-api:local', 'hosted-backend'),
+ ('frontend', 'opnform-scaleway-client:local', 'hosted-frontend')]:
+ image = json.loads(command('docker', 'image', 'inspect', local))[0]
+ if (image['Config']['Labels'].get('org.opencontainers.image.revision') != sha
+ or image['Architecture'] != 'amd64' or image['Os'] != 'linux'):
+ raise RuntimeError('The tested image does not match the release revision/platform')
+ package_is_private(package, allow_missing=True)
+ tag = 'ghcr.io/opnform/' + package + ':' + sha
+ command('docker', 'tag', image['Id'], tag)
+ command('docker', 'push', tag)
+ package_is_private(package)
+ refs = json.loads(command('docker', 'image', 'inspect', tag))[0]['RepoDigests']
+ expected = 'ghcr.io/opnform/' + package + '@sha256:'
+ matches = [ref for ref in refs if ref.startswith(expected)]
+ if len(matches) != 1 or not re.fullmatch(re.escape(expected) + '[0-9a-f]{64}', matches[0]):
+ raise RuntimeError('The published image has no unambiguous immutable digest')
+ images[role] = matches[0]
+ args.output.write_text(json.dumps({
+ 'schema': 'opnform-coolify-service-release/v1', 'repository': 'OpnForm/OpnForm',
+ 'sha': sha, 'ref': 'refs/heads/main', 'run_id': int(os.environ['GITHUB_RUN_ID']),
+ 'run_attempt': int(os.environ['GITHUB_RUN_ATTEMPT']), 'images': images,
+ 'automatic_deployment': True,
+ }, indent=2) + '\n')
+ # The controller reads this tiny image without starting it. Its credentials
+ # remain private on the controller; CI never receives Coolify/SSH access.
+ package_is_private('hosted-release', allow_missing=True)
+ with tempfile.TemporaryDirectory(prefix='opnform-release-') as directory:
+ context = Path(directory)
+ (context / 'release.json').write_bytes(args.output.read_bytes())
+ (context / 'Dockerfile').write_text('FROM scratch\n'
+ 'LABEL org.opencontainers.image.source="https://github.com/OpnForm/OpnForm" '
+ 'org.opencontainers.image.revision="' + sha + '"\n'
+ 'COPY release.json /release.json\n')
+ immutable = 'ghcr.io/opnform/hosted-release:' + sha + '-' + os.environ['GITHUB_RUN_ID'] + '-' + os.environ['GITHUB_RUN_ATTEMPT']
+ command('docker', 'build', '-t', immutable, str(context))
+ command('docker', 'push', immutable)
+ package_is_private('hosted-release')
+ if json.loads(command('gh', 'api', '/repos/OpnForm/OpnForm/commits/main'))['sha'] != sha:
+ raise RuntimeError('A newer main exists; do not publish a stale deployment channel')
+ command('docker', 'tag', immutable, 'ghcr.io/opnform/hosted-release:production')
+ command('docker', 'push', 'ghcr.io/opnform/hosted-release:production')
+ print('Validated private release published; the controller deploys after this main CI succeeds.')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/deploy/scaleway/role-health.sh b/deploy/scaleway/role-health.sh
new file mode 100644
index 000000000..366d56812
--- /dev/null
+++ b/deploy/scaleway/role-health.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+set -eu
+case "${APP_ROLE:-api}" in
+ api) exec curl -fsS --max-time 6 http://127.0.0.1:8080/healthz ;;
+ migrate) test -f /tmp/opnform-migration-ok ;;
+ jobs) test "$(pgrep -fc 'artisan queue:work redis')" -eq "${WORKER_COUNT:-4}" && php /opt/opnform/health.php ;;
+ scheduler)
+ php -r 'exit(!is_file("/tmp/opnform-scheduler-heartbeat") || time()-filemtime("/tmp/opnform-scheduler-heartbeat") > 90);'
+ ;;
+ *) exit 64 ;;
+esac
diff --git a/deploy/scaleway/scheduler.php b/deploy/scaleway/scheduler.php
new file mode 100644
index 000000000..97d5d94d6
--- /dev/null
+++ b/deploy/scaleway/scheduler.php
@@ -0,0 +1,44 @@
+<?php
+// One scheduler per database, including during overlapping releases.
+require '/app/vendor/autoload.php';
+$app = require '/app/bootstrap/app.php';
+$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+$pdo = Illuminate\Support\Facades\DB::connection()->getPdo();
+if (! $pdo->query('SELECT pg_try_advisory_lock(1869639270, 1)')->fetchColumn()) {
+ fwrite(STDERR, "Another OpnForm scheduler owns the database lock\n");
+ exit(75);
+}
+$stopping = false;
+pcntl_async_signals(true);
+pcntl_signal(SIGTERM, static function () use (&$stopping) { $stopping = true; });
+pcntl_signal(SIGINT, static function () use (&$stopping) { $stopping = true; });
+$lastMinute = null;
+try {
+ while (! $stopping) {
+ // Fail closed if the connection holding the advisory lock is lost.
+ $pdo->query('SELECT 1');
+ touch('/tmp/opnform-scheduler-heartbeat');
+ $minute = intdiv(time(), 60);
+ if ($minute !== $lastMinute) {
+ $lastMinute = $minute;
+ $child = proc_open(['php', '/app/artisan', 'schedule:run', '--no-interaction'], [STDIN, STDOUT, STDERR], $pipes);
+ if (! is_resource($child)) {
+ throw new RuntimeException('Unable to start schedule tick');
+ }
+ // Drain the current tick on SIGTERM before releasing singleton lock.
+ while (($status = proc_get_status($child))['running']) {
+ touch('/tmp/opnform-scheduler-heartbeat');
+ usleep(250000);
+ }
+ $exitCode = $status['exitcode'];
+ proc_close($child);
+ if ($exitCode !== 0) {
+ throw new RuntimeException('Schedule tick failed');
+ }
+ }
+ usleep(250000);
+ }
+} finally {
+ @unlink('/tmp/opnform-scheduler-heartbeat');
+ $pdo->query('SELECT pg_advisory_unlock(1869639270, 1)');
+}
diff --git a/deploy/scaleway/service-target.example.json b/deploy/scaleway/service-target.example.json
new file mode 100644
index 000000000..926642f5d
--- /dev/null
+++ b/deploy/scaleway/service-target.example.json
@@ -0,0 +1,17 @@
+{
+ "product": "opnform",
+ "service_uuid": "REPLACE_WITH_APPROVED_UUID",
+ "server_id": 0,
+ "project_id": 0,
+ "team_id": 0,
+ "controller_alias": "coolify",
+ "native_alias": "opnform-production",
+ "native_address": "100.64.0.1",
+ "ssh_config": "/absolute/private/opnform-ssh-config",
+ "api_url": "https://api.opnform.com",
+ "frontend_url": "https://opnform.com",
+ "expected_current_images": {
+ "backend": "sha256:REPLACE_WITH_RUNNING_IMAGE_ID",
+ "frontend": "sha256:REPLACE_WITH_RUNNING_IMAGE_ID"
+ }
+}
diff --git a/deploy/scaleway/supervisor-api.conf b/deploy/scaleway/supervisor-api.conf
new file mode 100644
index 000000000..b70de0cfe
--- /dev/null
+++ b/deploy/scaleway/supervisor-api.conf
@@ -0,0 +1,24 @@
+[supervisord]
+nodaemon=true
+pidfile=/tmp/supervisord.pid
+logfile=/dev/null
+[program:php-fpm]
+command=php-fpm -F
+stopsignal=QUIT
+stopwaitsecs=130
+priority=10
+autorestart=true
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/fd/2
+stderr_logfile_maxbytes=0
+[program:nginx]
+command=nginx -g "daemon off;"
+stopsignal=QUIT
+stopwaitsecs=130
+priority=20
+autorestart=true
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/fd/2
+stderr_logfile_maxbytes=0
diff --git a/deploy/scaleway/supervisor-jobs.conf b/deploy/scaleway/supervisor-jobs.conf
new file mode 100644
index 000000000..777b4df29
--- /dev/null
+++ b/deploy/scaleway/supervisor-jobs.conf
@@ -0,0 +1,16 @@
+[supervisord]
+nodaemon=true
+pidfile=/tmp/supervisord.pid
+logfile=/dev/null
+[program:worker]
+command=php /app/artisan queue:work redis --sleep=1 --tries=%(ENV_WORKER_TRIES)s --timeout=3610 --max-time=3600 --memory=512 --no-interaction
+numprocs=%(ENV_WORKER_COUNT)s
+process_name=worker_%(process_num)02d
+stopsignal=TERM
+stopwaitsecs=3650
+autorestart=true
+startsecs=2
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+stderr_logfile=/dev/fd/2
+stderr_logfile_maxbytes=0
diff --git a/deploy/scaleway/www-canonical.yml b/deploy/scaleway/www-canonical.yml
new file mode 100644
index 000000000..1ec733a7a
--- /dev/null
+++ b/deploy/scaleway/www-canonical.yml
@@ -0,0 +1,17 @@
+http:
+ routers:
+ opnform-www-canonical:
+ entryPoints:
+ - https
+ rule: Host(`www.opnform.com`)
+ priority: 2000
+ service: noop@internal
+ middlewares:
+ - opnform-www-canonical
+ tls: {}
+ middlewares:
+ opnform-www-canonical:
+ redirectRegex:
+ regex: ^https?://www\.opnform\.com(?::[0-9]+)?/(.*)
+ replacement: https://opnform.com/${1}
+ permanent: true
diff --git a/scripts/check-ci-readiness.mjs b/scripts/check-ci-readiness.mjs
index fa2714256..084f12e7e 100644
--- a/scripts/check-ci-readiness.mjs
+++ b/scripts/check-ci-readiness.mjs
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict'
const needs = JSON.parse(process.env.NEEDS_JSON || '{}')
-for (const name of ['code_lint', 'client_checks', 'sync_check', 'tests', 'database_compatibility', 'e2e', 'linux_client_image', 'dependency-security']) {
+for (const name of ['code_lint', 'client_checks', 'sync_check', 'tests', 'database_compatibility', 'e2e', 'linux_client_image', 'dependency-security', 'scaleway-runtime']) {
assert.ok(Object.hasOwn(needs, name), `Missing release prerequisite: ${name}`)
}
for (const [name, job] of Object.entries(needs)) {
diff --git a/scripts/tests/dependency-security.test.mjs b/scripts/tests/dependency-security.test.mjs
index 9c4a87892..71d918efb 100644
--- a/scripts/tests/dependency-security.test.mjs
+++ b/scripts/tests/dependency-security.test.mjs
@@ -62,10 +62,21 @@ test('docs-only PRs execute the stable required check without path filters', ()
assert.equal(pipeline.jobs['release-readiness'].name, 'Release readiness')
assert.equal(pipeline.jobs['release-readiness'].if, 'always()')
})
-test('both delivery jobs depend on the security and QA aggregate', () => {
- for (const name of ['production-deploy', 'publish-docker-images']) assert.deepEqual(pipeline.jobs[name].needs, ['release-readiness'])
+test('hosted and self-hosted publications depend on the security and QA aggregate', () => {
+ for (const name of ['publish-scaleway-images', 'publish-docker-images']) assert.deepEqual(pipeline.jobs[name].needs, ['release-readiness'])
assert.ok(pipeline.jobs['release-readiness'].needs.includes('dependency-security'))
+ assert.ok(pipeline.jobs['release-readiness'].needs.includes('scaleway-runtime'))
assert.equal(pipeline.jobs['dependency-security'].uses, './.github/workflows/dependency-security.yml')
+ assert.equal(pipeline.jobs['production-deploy'], undefined)
+ assert.equal(pipeline.jobs['scaleway-runtime'].uses, './.github/workflows/scaleway-validation.yml')
+ const publication = pipeline.jobs['publish-scaleway-images']
+ assert.match(publication.if, /github\.ref == 'refs\/heads\/main'/)
+ assert.match(publication.if, /github\.event_name == 'push'/)
+ assert.equal(publication.permissions.packages, 'write')
+ const raw = JSON.stringify(publication)
+ for (const forbidden of ['VAPOR_API_TOKEN', 'AMPLIFY_DEPLOY_URL', 'COOLIFY_TOKEN', 'vapor deploy']) {
+ assert.equal(raw.includes(forbidden), false)
+ }
})
test('general PHP suite is honestly SQLite and real database checks gate releases', () => {
assert.match(pipeline.jobs.tests.name, /SQLite/)
@@ -77,6 +88,16 @@ test('general PHP suite is honestly SQLite and real database checks gate release
assert.equal(check.env.APP_ENV, 'database-compatibility')
assert.match(check.run, /check-database-compatibility\.php/)
})
+test('production deployment observation follows only successful main push CI without administrator credentials', () => {
+ const workflow = parse(readFileSync(new URL('../../.github/workflows/scaleway-deployment.yml', import.meta.url), 'utf8'))
+ assert.deepEqual(workflow.on.workflow_run.workflows, ['CI/CD Pipeline'])
+ assert.deepEqual(workflow.on.workflow_run.types, ['completed'])
+ assert.deepEqual(workflow.on.workflow_run.branches, ['main'])
+ const job = workflow.jobs['verify-live-release']
+ for (const condition of ["conclusion == 'success'", "event == 'push'", "head_branch == 'main'", "head_repository.full_name == 'OpnForm/OpnForm'"]) assert.ok(job.if.includes(condition))
+ const raw = JSON.stringify(workflow)
+ for (const secret of ['COOLIFY_TOKEN', 'SSH_PRIVATE_KEY', 'VAPOR_API_TOKEN', 'AMPLIFY_DEPLOY_URL']) assert.equal(raw.includes(secret), false)
+})
test('release readiness fails for failed, skipped, cancelled or missing prerequisites', () => {
const needs = Object.fromEntries(pipeline.jobs['release-readiness'].needs.map(name => [name, { result: 'success' }]))
const run = value => spawnSync(process.execPath, [new URL('../check-ci-readiness.mjs', import.meta.url).pathname], { env: { ...process.env, NEEDS_JSON: JSON.stringify(value) }, encoding: 'utf8' })
@@ -85,8 +106,11 @@ test('release readiness fails for failed, skipped, cancelled or missing prerequi
assert.notEqual(run({ ...needs, 'dependency-security': { result } }).status, 0)
}
assert.notEqual(run({ ...needs, future_check: { result: 'failure' } }).status, 0)
- delete needs.tests
- assert.notEqual(run(needs).status, 0)
+ for (const name of ['tests', 'scaleway-runtime']) {
+ const incomplete = { ...needs }
+ delete incomplete[name]
+ assert.notEqual(run(incomplete).status, 0)
+ }
})
test('resolves the actual Nuxt/Nitro/builders and site-config cycles to reviewed roots', () => {
@@ -130,7 +154,7 @@ test('CLI retains the raw nonzero scan, rejects a new upstream release and rejec
assert.notEqual(run().status, 0)
})
-test('Amplify explicitly emits Node 24 compute and validates the target output', () => {
+test('legacy Amplify recovery configuration remains valid but regular CI does not build it', () => {
const config = readFileSync(new URL('../../client/nuxt.config.ts', import.meta.url), 'utf8')
assert.match(config, /awsAmplify: \{ runtime: 'nodejs24\.x' \}/)
const amplify = parse(readFileSync(new URL('../../amplify.yml', import.meta.url), 'utf8'))
@@ -139,8 +163,9 @@ test('Amplify explicitly emits Node 24 compute and validates the target output',
assert.match(pkg.scripts['build:amplify'], /NITRO_PRESET=aws-amplify npm run build/)
assert.match(pkg.scripts['build:amplify'], /check-amplify-output\.mjs/)
const smoke = pipeline.jobs.linux_client_image.steps.find(step => step.name === 'Smoke standalone Amplify compute on Linux Node 24')
- assert.match(smoke.run, /check-amplify-runtime\.mjs/)
- assert.match(smoke.run, /runner\.temp/)
+ assert.equal(smoke, undefined)
+ assert.equal(pipeline.jobs.client_checks.steps.some(step => step.run?.includes('npm run build:amplify')), false)
+ assert.equal(pipeline.jobs.linux_client_image.steps.some(step => step.with?.name === 'amplify-output'), false)
assert.ok(pipeline.jobs['release-readiness'].needs.includes('linux_client_image'))
})
diff --git a/tests/Deployment/.gitignore b/tests/Deployment/.gitignore
new file mode 100644
index 000000000..7a60b85e1
--- /dev/null
+++ b/tests/Deployment/.gitignore
@@ -0,0 +1,2 @@
+__pycache__/
+*.pyc
diff --git a/tests/Deployment/ci-source-proof.py b/tests/Deployment/ci-source-proof.py
new file mode 100644
index 000000000..2714d9ac4
--- /dev/null
+++ b/tests/Deployment/ci-source-proof.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+"""Bind the embedded-image regression check to committed runtime source files."""
+import argparse
+import hashlib
+import json
+import os
+from pathlib import Path
+import subprocess
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--output-dir', required=True, type=Path)
+ args = parser.parse_args()
+ root = Path(__file__).resolve().parents[2]
+ sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root, text=True).strip()
+ if sha != os.environ['GITHUB_SHA']:
+ raise RuntimeError('Checkout does not match the CI revision')
+ names = subprocess.check_output(['git', 'ls-files', '-z', 'api/artisan', 'api/composer.json', 'api/composer.lock', 'api/app', 'api/bootstrap',
+ 'api/config', 'api/database', 'api/public', 'api/resources', 'api/routes',
+ 'deploy/scaleway'], cwd=root).decode().split('\0')
+ hashes = {name: hashlib.sha256((root / name).read_bytes()).hexdigest()
+ for name in names if name and (root / name).is_file()}
+ args.output_dir.mkdir(parents=True, exist_ok=True)
+ (args.output_dir / 'proof.json').write_text(json.dumps({
+ 'source_hashes': hashes, 'source_revision_marker': sha,
+ 'real_release_commit': sha, 'source_base_commit': sha,
+ }, indent=2) + '\n')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/Deployment/coolify-model-fixture.php b/tests/Deployment/coolify-model-fixture.php
new file mode 100644
index 000000000..5a31a9eef
--- /dev/null
+++ b/tests/Deployment/coolify-model-fixture.php
@@ -0,0 +1,28 @@
+<?php
+// Local model double: the generated promotion program still owns its real
+// history/lease files, but no Coolify database, SSH or Docker can be reached.
+namespace App\Models {
+ class Service
+ {
+ public $server_id = 5;
+ public $uuid = 'ssssssssssssssssssssssss';
+ public $server;
+ public $environment;
+ public $docker_compose_raw;
+
+ public function __construct()
+ {
+ $this->server = (object) ['ip' => '100.65.151.96'];
+ $this->environment = (object) ['project' => (object) ['id' => 4, 'team_id' => 0]];
+ $this->docker_compose_raw = json_encode(['services' => array_fill_keys(
+ ['api', 'frontend', 'jobs', 'scheduler', 'migrate'], ['image' => 'previous-image']
+ )]);
+ }
+
+ public static function where(...$arguments) { return new self; }
+ public function sole() { return $this; }
+ public function save() {}
+ public function parse() {}
+ public function saveComposeConfigs() {}
+ }
+}
diff --git a/tests/Deployment/redis-runtime.php b/tests/Deployment/redis-runtime.php
new file mode 100644
index 000000000..bc4c102c4
--- /dev/null
+++ b/tests/Deployment/redis-runtime.php
@@ -0,0 +1,79 @@
+<?php
+// Executed only inside the production image with disposable CI dependencies.
+require '/app/vendor/autoload.php';
+$app = require '/app/bootstrap/app.php';
+$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+
+use Illuminate\Support\Facades\Cache;
+
+if (! str_starts_with(config('database.redis.default.host'), 'opnform-fixture-')) {
+ throw new RuntimeException('This test requires disposable runtime dependencies');
+}
+$check = static function (bool $condition): void {
+ if (! $condition) {
+ throw new RuntimeException('Laravel Redis runtime contract failed');
+ }
+};
+$check(Cache::getStore() instanceof Illuminate\Cache\RedisStore);
+
+// Seed the same tagged repository the removed adapter used, then resolve the
+// stock provider through Laravel's container. Reading must preserve its expiry.
+$auth = Cache::store('auth');
+$legacyValue = ['valid_until' => time() + 120];
+$auth->tags('tymon.jwt')->put('existing-runtime-revocation', $legacyValue, 120);
+$key = $auth->getStore()->getPrefix().$auth->tags('tymon.jwt')->taggedItemKey('existing-runtime-revocation');
+$redisAuth = app('redis')->connection('auth');
+$expiresAt = $redisAuth->pexpiretime($key);
+$jwtStorage = app('tymon.jwt.provider.storage');
+$check(get_class($jwtStorage) === Tymon\JWTAuth\Providers\Storage\Illuminate::class);
+$check($jwtStorage->get('existing-runtime-revocation') === $legacyValue);
+$check($redisAuth->pexpiretime($key) === $expiresAt && $expiresAt > time() * 1000);
+$check(Cache::tags('tymon.jwt')->get('existing-runtime-revocation') === null);
+$jwtStorage->forever('new-runtime-revocation', $legacyValue);
+$check($auth->tags('tymon.jwt')->get('new-runtime-revocation') === $legacyValue);
+$check(Cache::tags('tymon.jwt')->get('new-runtime-revocation') === null);
+
+Cache::put('runtime-counter', 1, 120);
+$check(Cache::increment('runtime-counter') === 2);
+$lock = Cache::lock('runtime-lock', 10);
+$check($lock->get());
+$check(! Cache::lock('runtime-lock', 10)->get());
+$lock->release();
+
+$session = (new Illuminate\Session\SessionManager(app()))->driver();
+$session->setId(str_repeat('a', 40));
+$session->start();
+$session->put('runtime-user', 42);
+$session->save();
+$reopened = (new Illuminate\Session\SessionManager(app()))->driver();
+$reopened->setId($session->getId());
+$reopened->start();
+$check($reopened->get('runtime-user') === 42);
+$store = Cache::store('auth')->getStore();
+$expiry = app('redis')->connection('auth')->pttl($store->getPrefix().$session->getId());
+$check($expiry > 0 && $expiry <= config('session.lifetime') * 60000);
+
+$state = app('redis')->connection('state');
+$queue = app('redis')->connection('default');
+$queueKey = 'queues:'.config('queue.connections.redis.queue');
+$check($queueKey !== 'queues:default');
+$pending = $queue->llen($queueKey);
+$check($pending > 0); // The real HTTP submission is waiting for its worker.
+$memory = $state->info('memory');
+$state->command('config', ['SET', 'maxmemory', (string) ($memory['used_memory'] + 100000)]);
+try {
+ $oom = false;
+ try {
+ Cache::store('volatile')->put('oversized-runtime-test', str_repeat('x', 3000000), 120);
+ } catch (RedisException $exception) {
+ $oom = str_contains($exception->getMessage(), 'OOM');
+ }
+ $check($oom);
+ $check(Cache::get('runtime-counter') === 2);
+ $check(Cache::store('auth')->get($session->getId()) !== null);
+ $check($queue->llen($queueKey) === $pending);
+ $check($state->info('stats')['evicted_keys'] === 0);
+} finally {
+ $state->command('config', ['SET', 'maxmemory', '32mb']);
+}
+echo "Laravel Redis runtime contracts passed\n";
diff --git a/tests/Deployment/test-runtime.py b/tests/Deployment/test-runtime.py
new file mode 100644
index 000000000..2d9ce115d
--- /dev/null
+++ b/tests/Deployment/test-runtime.py
@@ -0,0 +1,314 @@
+#!/usr/bin/env python3
+"""Current single-Redis image qualification on disposable fictional data; no application/vendor overlays."""
+import argparse
+import base64
+import json
+import ipaddress
+import os
+from pathlib import Path
+import subprocess
+import tempfile
+import time
+import uuid
+
+
+def run(*command, check=True, env=None, input=None, timeout=90):
+ result = subprocess.run(command, capture_output=True, text=True, input=input,
+ env=env, timeout=timeout)
+ if check and result.returncode:
+ raise RuntimeError(f'{command[0]} failed ({result.returncode}): {result.stderr[-1500:]} {result.stdout[-1500:]}')
+ return result
+
+
+def wait_for(check, label, seconds=90):
+ end = time.monotonic() + seconds
+ while time.monotonic() < end:
+ if check():
+ return
+ time.sleep(0.5)
+ raise RuntimeError(f'Timed out: {label}')
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--api-image', default='opnform-scaleway-api:local')
+ parser.add_argument('--client-image', default='opnform-scaleway-client:local')
+ parser.add_argument('--skip-client', action='store_true')
+ parser.add_argument('--host-firewall-guard', action='store_true', help='Linux root only: deny fixture access to host and other networks')
+ parser.add_argument('--output-dir',type=Path,required=True)
+ args = parser.parse_args()
+ args.output_dir.mkdir(parents=True,exist_ok=True)
+ prefix = 'opnform-fixture-' + uuid.uuid4().hex[:10]
+ names = []
+ passed = []
+ network_created = False
+ firewall_table = None
+ image_checks=[]
+
+ def docker(*command, **kwargs):
+ return run('docker', *command, **kwargs)
+
+ def record(label):
+ passed.append(label)
+ print('PASS ' + label, flush=True)
+
+ def start(suffix, image, *options, command=(), environment=None):
+ name = prefix + '-' + suffix
+ # Register before execution so cleanup also covers ambiguous run results.
+ names.append(name)
+ flags = []
+ for key in (environment or {}):
+ flags += ['--env', key]
+ docker('run', '-d', '--pull=never', '--name', name, '--network', prefix, '--dns', '127.0.0.1',
+ *flags, *options, image, *command,
+ env={**os.environ, **(environment or {})})
+ return name
+
+ try:
+ ids = docker('network', 'ls', '-q').stdout.split()
+ existing = json.loads(docker('network', 'inspect', *ids).stdout)
+ used = [ipaddress.ip_network(config['Subnet']) for net in existing
+ for config in (net.get('IPAM', {}).get('Config') or []) if config.get('Subnet')]
+ candidates = [ipaddress.ip_network(f'10.254.{index}.0/24') for index in range(240, 255)]
+ subnet = next((net for net in candidates if not any(
+ net.version == other.version and net.overlaps(other) for other in used)), None)
+ if subnet is None:
+ raise RuntimeError('No non-overlapping local fixture subnet available')
+ docker('network', 'create', '--internal', '--subnet', str(subnet), prefix)
+ network_created = True
+ inspect = json.loads(docker('network', 'inspect', prefix).stdout)[0]
+ assert inspect['Internal'] is True
+ if args.host_firewall_guard:
+ firewall_table = 'opnform_fixture_' + prefix.rsplit('-', 1)[1]
+ bridge = 'br-' + inspect['Id'][:12]
+ rules = f'''add table inet {firewall_table}
+add chain inet {firewall_table} input_guard {{ type filter hook input priority -30; policy accept; }}
+add chain inet {firewall_table} forward_guard {{ type filter hook forward priority -30; policy accept; }}
+add rule inet {firewall_table} input_guard ct state established,related accept
+add rule inet {firewall_table} input_guard iifname "{bridge}" drop
+add rule inet {firewall_table} forward_guard iifname "{bridge}" oifname != "{bridge}" drop
+'''
+ run('nft', '-f', '-', input=rules)
+ record('network is internal; no public ports')
+ db = start('db', 'postgres:16-bookworm', '--tmpfs', '/var/lib/postgresql/data',
+ environment={'POSTGRES_PASSWORD': 'fictional-local-only', 'POSTGRES_DB': 'opnform_fixture'})
+ queue = start('redis', 'redis:7.4-bookworm', command=('redis-server','--appendonly','yes','--appendfsync','always','--maxmemory','32mb','--maxmemory-policy','noeviction'))
+ state=cache=queue
+ wait_for(lambda: docker('exec', db, 'pg_isready', '-U', 'postgres', check=False).returncode == 0, 'Postgres')
+ fixture_root = Path.home() / '.codex' / 'tmp'
+ fixture_root.mkdir(parents=True, exist_ok=True)
+ with tempfile.TemporaryDirectory(prefix='opnform-fixtures-', dir=fixture_root) as directory:
+ fixture = Path(directory)
+ fixture.chmod(0o777)
+ private = run('openssl', 'genpkey', '-algorithm', 'RSA', '-pkeyopt', 'rsa_keygen_bits:2048').stdout
+ public = run('openssl', 'pkey', '-pubout', input=private).stdout
+ environment = {
+ 'APP_ENV': 'production', 'TRUSTED_PROXIES': '127.0.0.1', 'APP_DEBUG': 'false', 'SELF_HOSTED': 'false',
+ 'APP_KEY': 'base64:' + base64.b64encode(os.urandom(32)).decode(),
+ 'JWT_SECRET': 'fictional-runtime-test-signing-secret-at-least-32-characters',
+ 'FRONT_API_SECRET': base64.b64encode(os.urandom(48)).decode(),
+ 'PASSPORT_PRIVATE_KEY': private, 'PASSPORT_PUBLIC_KEY': public,
+ 'APP_URL': 'http://api.fixture.test', 'FRONT_URL': 'http://client.fixture.test',
+ 'DB_CONNECTION': 'pgsql', 'DB_HOST': db, 'DB_PORT': '5432',
+ 'DB_DATABASE': 'opnform_fixture', 'DB_USERNAME': 'postgres', 'DB_PASSWORD': 'fictional-local-only',
+ 'QUEUE_CONNECTION': 'redis', 'REDIS_HOST': queue, 'REDIS_QUEUE': 'custom-fixture', 'REDIS_QUEUE_RETRY_AFTER': '3700',
+ 'REDIS_CACHE_HOST': cache, 'REDIS_STATE_HOST':state,'REDIS_AUTH_HOST':state,'REDIS_DB':'0','REDIS_CACHE_DB':'1','REDIS_AUTH_DB':'2','REDIS_STATE_DB':'3','REDIS_PREFIX':'opnform_fixture:', 'OPNFORM_STATE_MODE':'redis-fresh', 'CACHE_DRIVER': 'redis',
+ 'MAIL_MAILER': 'log', 'FILESYSTEM_DRIVER': 'local', 'WORKER_COUNT': '1',
+ 'OPNFORM_ANONYMOUS_TELEMETRY_DISABLED': 'true', 'SESSION_DRIVER': 'redis','SESSION_STORE':'auth','SESSION_CONNECTION':'auth',
+ }
+ mount = ('--mount', f'type=bind,src={fixture},dst=/fixtures')
+
+ def app(suffix, role, *options, override=None, command=()):
+ return start(suffix, args.api_image, *mount, *options,
+ environment={**environment, 'APP_ROLE': role, **(override or {})}, command=command)
+
+ probe = app('probe', 'api', '--entrypoint', 'sleep', command=('infinity',))
+ script = "foreach ([['1.1.1.1',443],['169.254.169.254',80],['[2606:4700:4700::1111]',443],['host.docker.internal',80],['8.8.8.8',53],['1.1.1.1',25],['example.com',443]] as [$h,$p]) { if (@fsockopen($h,$p,$e,$s,1)) {fwrite(STDERR,'Unexpected egress');exit(1);} }"
+ docker('exec', probe, 'php', '-r', script)
+ docker('exec', probe, 'php', '-r', "if (@gethostbyname('example.com') !== 'example.com') exit(1);")
+ if args.host_firewall_guard:
+ gateway = str(subnet.network_address + 1)
+ docker('exec', probe, 'php', '-r', f"if (@fsockopen('{gateway}',22,$e,$s,1)) exit(1);")
+ record('IPv4 IPv6 metadata host-gateway SMTP DNS and external HTTPS egress probes denied')
+ for suffix, proxies in [('missing-proxy', ''), ('wildcard-proxy', '*')]:
+ bad_proxy = app(suffix, 'api', override={'TRUSTED_PROXIES': proxies})
+ wait_for(lambda: docker('inspect', '-f', '{{.State.Running}}', bad_proxy).stdout.strip() == 'false', 'proxy guard')
+ assert docker('inspect', '-f', '{{.State.ExitCode}}', bad_proxy).stdout.strip() == '78'
+ record('missing or wildcard trusted proxies block startup')
+ invalid = app('invalid', 'jobs', override={'REDIS_QUEUE_RETRY_AFTER': '90'})
+ wait_for(lambda: docker('inspect', '-f', '{{.State.Running}}', invalid).stdout.strip() == 'false', 'invalid preflight')
+ assert docker('inspect', '-f', '{{.State.ExitCode}}', invalid).stdout.strip() == '78'
+ record('short Redis reservation blocks worker startup')
+ source_proof=json.loads((args.output_dir/'proof.json').read_text())
+ manifest={('/app/'+f[4:]):h for f,h in source_proof['source_hashes'].items() if f.startswith('api/')}
+ for filename,target in [('health.php','/opt/opnform/health.php'),('preflight.php','/opt/opnform/preflight.php'),('scheduler.php','/opt/opnform/scheduler.php'),('entrypoint.sh','/usr/local/bin/entrypoint.sh'),('role-health.sh','/usr/local/bin/role-health.sh')]:
+ manifest[target]=source_proof['source_hashes']['deploy/scaleway/'+filename]
+ hash_script='$m=json_decode(stream_get_contents(STDIN),true);foreach($m as $f=>$h){if(!is_file($f)||hash_file("sha256",$f)!==$h){fwrite(STDERR,"Runtime hash mismatch: ".$f);exit(1);}}echo count($m);'
+ matched=int(docker('exec','-i',probe,'php','-r',hash_script,input=json.dumps(manifest)).stdout)
+ assert docker('exec',probe,'cat','/app-revision').stdout==source_proof['source_revision_marker']
+ assert docker('exec',probe,'php','-r',"echo PHP_VERSION.'|'.ini_get('session.upload_progress.enabled');").stdout.strip()=='8.3.36|0'
+ assert 'session.upload_progress.enabled => Off' in docker('exec',probe,'php-fpm','-i').stdout
+ record('actual backend image matches '+str(matched)+' frozen runtime source hashes and revision')
+ image_checks.append({'runtime_source_hashes_matched':matched,'image':docker('inspect','-f','{{.Image}}',probe).stdout.strip()})
+ # Exercise the actual production profile with disposable dependencies.
+ fresh = app('fresh-production-preflight', 'api', '--entrypoint', 'php',
+ override={'APP_ENV': 'production', 'OPNFORM_STATE_MODE': 'redis-fresh'},
+ command=('/opt/opnform/preflight.php',))
+ wait_for(lambda: docker('inspect', '-f', '{{.State.Running}}', fresh).stdout.strip() == 'false', 'fresh Redis production preflight')
+ assert docker('inspect', '-f', '{{.State.ExitCode}}', fresh).stdout.strip() == '0'
+ docker('exec', state, 'redis-cli', 'CONFIG', 'SET', 'maxmemory-policy', 'allkeys-lru')
+ unsafe = app('unsafe-fresh-production', 'api', '--entrypoint', 'php',
+ override={'APP_ENV': 'production', 'OPNFORM_STATE_MODE': 'redis-fresh'},
+ command=('/opt/opnform/preflight.php',))
+ wait_for(lambda: docker('inspect', '-f', '{{.State.Running}}', unsafe).stdout.strip() == 'false', 'unsafe fresh Redis policy rejection')
+ assert docker('inspect', '-f', '{{.State.ExitCode}}', unsafe).stdout.strip() == '78'
+ docker('exec', state, 'redis-cli', 'CONFIG', 'SET', 'maxmemory-policy', 'noeviction')
+ environment['OPNFORM_STATE_MODE'] = 'redis-fresh'
+ environment['APP_ENV'] = 'production'
+ record('production Laravel Redis bindings boot; unsafe eviction is rejected')
+
+ api = app('api', 'api')
+ wait_for(lambda: docker('exec', api, 'role-health.sh', check=False).returncode == 0, 'API dependencies')
+ count = docker('exec', db, 'psql', '-U', 'postgres', '-d', 'opnform_fixture', '-tAc',
+ "SELECT count(*) FROM pg_tables WHERE schemaname='public'").stdout.strip()
+ assert count == '0', count
+ record('API startup performs no migrations')
+ migration = app('migration', 'migrate')
+ wait_for(lambda: docker('exec', migration, 'test', '-f', '/tmp/opnform-migration-ok', check=False).returncode == 0, 'migration gate')
+ record('explicit Migration role validates OAuth keys and schema')
+ docker('exec', api, 'php', 'artisan', 'db:seed', '--class=E2ETestSeeder', '--force', '--no-interaction')
+ record('synthetic E2E forms and submissions seeded')
+ settings = "require 'vendor/autoload.php';$a=require 'bootstrap/app.php';$a->make(Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap();echo json_encode([config('database.redis.default.host'),config('database.redis.cache.host'),config('queue.connections.redis.retry_after')]);"
+ assert json.loads(docker('exec', api, 'php', '-r', settings).stdout) == [queue, cache, 3700]
+ record('queue/cache/auth/state share one endpoint with separate logical DBs and 3700s reservation')
+ smoke = "require 'vendor/autoload.php';$a=require 'bootstrap/app.php';$a->make(Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap();$f=App\\Models\\Forms\\Form::where('title','Product feedback')->firstOrFail();if(App\\Models\\Forms\\FormSubmission::count()!==6)exit(1);$t=auth('api')->attempt(['email'=>'[email protected]','password'=>'Abcd@1234']);if(!$t)exit(2);echo $f->slug;"
+ slug = docker('exec', api, 'php', '-r', smoke).stdout.strip()
+ assert slug
+ response = docker('exec', api, 'curl', '-fsS', f'http://127.0.0.1:8080/forms/{slug}').stdout
+ assert 'Product feedback' in response
+ record('real HTTP form read and synthetic JWT login work')
+ form_data = json.loads(response)
+ form_data = form_data.get('data', form_data)
+ values = {'Full name': 'Migration Fixture', 'Email address': '[email protected]',
+ 'Satisfaction': 5, 'Feedback': 'Synthetic isolated runtime submission'}
+ payload = {field['id']: values[field['name']] for field in form_data['properties'] if field['name'] in values}
+ submitted = docker('exec', api, 'curl', '-fsS', '-H', 'Content-Type: application/json',
+ '-H', 'Accept: application/json', '-d', json.dumps(payload),
+ f'http://127.0.0.1:8080/forms/{slug}/answer').stdout
+ assert 'Form submission saved' in submitted
+ (fixture / 'pixel.png').write_bytes(base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9ZlS8AAAAASUVORK5CYII='))
+ uploaded = json.loads(docker('exec', api, 'curl', '-fsS', '-H', 'Accept: application/json',
+ '-F', 'file=@/fixtures/pixel.png', 'http://127.0.0.1:8080/upload-file').stdout)
+ assert uploaded.get('uuid') and uploaded.get('key', '').startswith('tmp/')
+ record('public HTTP submission accepted and PNG upload stored on isolated local disk')
+ (fixture / 'redis-runtime.php').write_bytes(Path(__file__).with_name('redis-runtime.php').read_bytes())
+ docker('exec', api, 'php', '/fixtures/redis-runtime.php')
+ record('standard Laravel cache, session, locks and queued work survive explicit saturation without eviction')
+
+ (fixture / 'queue.php').write_text('''<?php
+require '/app/vendor/autoload.php';
+$a=require '/app/bootstrap/app.php';$a->make(Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap();
+$job=Illuminate\\Queue\\CallQueuedClosure::create(function () {
+ file_put_contents('/fixtures/job-started','1');
+ $end=microtime(true)+4;while(microtime(true)<$end){usleep(100000);}
+ file_put_contents('/fixtures/job-finished','1');
+});dispatch($job);
+''')
+ (fixture / 'retry.php').write_text('''<?php
+require '/app/vendor/autoload.php';
+$a=require '/app/bootstrap/app.php';$a->make(Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap();
+$job=Illuminate\\Queue\\CallQueuedClosure::create(function () {
+ $path='/fixtures/retry-count';$count=is_file($path)?(int)file_get_contents($path):0;
+ file_put_contents($path,++$count);
+ if($count<3)throw new RuntimeException('Synthetic retryable failure');
+ file_put_contents('/fixtures/retry-finished','1');
+});$job->tries=null;dispatch($job);
+''')
+ docker('exec', api, 'php', '/fixtures/retry.php')
+ jobs = app('jobs', 'jobs')
+ wait_for(lambda: (fixture / 'retry-finished').exists(), 'third worker attempt')
+ assert (fixture / 'retry-count').read_text() == '3'
+ assert '--tries=3' in docker('exec', jobs, 'pgrep', '-af', 'artisan queue:work redis').stdout
+ record('worker consumes the configured custom queue and retries a synthetic job through success')
+ docker('exec', api, 'php', '/fixtures/queue.php')
+ wait_for(lambda: (fixture / 'job-started').exists(), 'queued synthetic job')
+ docker('stop', '-t', '15', jobs)
+ assert (fixture / 'job-finished').read_text() == '1'
+ assert docker('inspect', '-f', '{{.State.ExitCode}}', jobs).stdout.strip() == '0'
+ stored = docker('exec', db, 'psql', '-U', 'postgres', '-d', 'opnform_fixture', '-tAc',
+ 'SELECT count(*) FROM form_submissions').stdout.strip()
+ assert stored == '7', stored
+ record('queued public submission persisted before worker shutdown')
+ record('SIGTERM drains an actual queued job before worker exit')
+ revoked = "require 'vendor/autoload.php';$a=require 'bootstrap/app.php';$a->make(Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap();$t=auth('api')->login(App\\Models\\User::firstOrFail());auth('api')->setToken($t)->logout();echo $t;"
+ token = docker('exec', api, 'php', '-r', revoked).stdout.strip()
+ verify = "require 'vendor/autoload.php';$a=require 'bootstrap/app.php';$a->make(Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap();exit(auth('api')->setToken(getenv('FIXTURE_REVOKED_TOKEN'))->check()?1:0);"
+ docker('exec', '--env', 'FIXTURE_REVOKED_TOKEN=' + token, api, 'php', '-r', verify)
+ record('revoked JWT remains rejected across processes sharing the same state store')
+
+ scheduler = app('scheduler', 'scheduler')
+ wait_for(lambda:docker('exec',scheduler,'test','-f','/tmp/opnform-scheduler-heartbeat',check=False).returncode==0,'actual scheduler heartbeat')
+ second = app('scheduler-second', 'scheduler')
+ wait_for(lambda:docker('inspect','-f','{{.State.Running}}',second).stdout.strip()=='false','second actual scheduler rejection')
+ assert docker('inspect','-f','{{.State.ExitCode}}',second).stdout.strip()=='75'
+ docker('stop','-t','20',scheduler)
+ assert docker('inspect','-f','{{.State.ExitCode}}',scheduler).stdout.strip()=='0'
+ record('actual unmodified artisan scheduler holds Postgres singleton and exits cleanly on SIGTERM')
+ bad = app('bad-migration', 'migrate',override={'PASSPORT_PRIVATE_KEY':'fictional-invalid-key','PASSPORT_PUBLIC_KEY':'fictional-invalid-key'})
+ wait_for(lambda:'Migration gate failed' in docker('logs',bad).stdout+docker('logs',bad).stderr,'invalid OAuth migration gate')
+ assert docker('exec',bad,'role-health.sh',check=False).returncode!=0
+ record('actual migration role refuses invalid fictional OAuth keys without application overlay')
+ if not args.skip_client:
+ client = start('client', args.client_image, environment={
+ 'NUXT_PRIVATE_API_BASE': f'http://{api}:8080',
+ 'NUXT_API_SECRET': environment['FRONT_API_SECRET'],
+ 'NUXT_PUBLIC_API_BASE': 'http://api.fixture.test',
+ 'NUXT_PUBLIC_APP_URL': 'http://client.fixture.test',
+ })
+ wait_for(lambda: docker('exec', client, 'node', '-e', "fetch('http://127.0.0.1:3000/login').then(r=>process.exit(r.status===200?0:1)).catch(()=>process.exit(1))", check=False).returncode == 0, 'frontend SSR')
+ release_check = "fetch('http://127.0.0.1:3000/release.json').then(async r=>{if(r.status!==200||(await r.json()).revision!==process.argv[1])process.exit(1)}).catch(()=>process.exit(1))"
+ docker('exec', client, 'node', '-e', release_check, source_proof['source_revision_marker'])
+ record('frontend serves its exact build revision through the public release endpoint')
+ targets = ['https://1.1.1.1', 'http://169.254.169.254', 'https://example.com', 'http://[2606:4700:4700::1111]']
+ if args.host_firewall_guard:
+ targets.append('http://' + str(subnet.network_address + 1) + ':22')
+ javascript = "const urls=JSON.parse(process.argv[1]);Promise.all(urls.map(u=>fetch(u,{signal:AbortSignal.timeout(1500)}).then(()=>{throw Error('Unexpected egress '+u)},()=>true))).catch(e=>{console.error(e.message);process.exitCode=1})"
+ docker('exec', client, 'node', '-e', javascript, json.dumps(targets))
+ docker('exec', client, 'node', '-e', "require('node:dns').promises.lookup('example.com').then(()=>process.exit(1),()=>process.exit(0))")
+ record('exact frontend image serves SSR login and denies external/metadata/host egress')
+ login = json.loads(docker('exec', api, 'curl', '-fsS', '-H', 'Content-Type: application/json', '-H', 'Accept: application/json', '-H', 'User-Agent: FixtureBrowser', '-d', json.dumps({'email': '[email protected]', 'password': 'Abcd@1234'}), 'http://127.0.0.1:8080/login').stdout)
+ browser_token = login['token']
+ ssr_php = '$c=curl_init(getenv("FIXTURE_CLIENT_URL"));curl_setopt_array($c,[CURLOPT_RETURNTRANSFER=>true,CURLOPT_HTTPHEADER=>["Cookie: opnform_token=".getenv("FIXTURE_BROWSER_JWT")],CURLOPT_TIMEOUT=>30]);$s=curl_exec($c);$status=curl_getinfo($c,CURLINFO_RESPONSE_CODE);exit($status===200&&is_string($s)&&str_contains($s,"Product feedback")&&!str_contains($s,"This form is temporarily unavailable")?0:1);'
+ ssr = docker('exec', '--env', 'FIXTURE_BROWSER_JWT=' + browser_token, '--env', 'FIXTURE_CLIENT_URL=http://' + client + ':3000/forms/' + slug, api, 'php', '-r', ssr_php)
+ docker('exec', api, 'curl', '-fsS', '-H', 'Accept: application/json', '-H', 'User-Agent: FixtureBrowser', '-H', 'Authorization: Bearer ' + browser_token, 'http://127.0.0.1:8080/user')
+ record('shared private SSR secret preserves browser JWT across Nuxt server requests')
+
+ except Exception:
+ for name in names:
+ if name.endswith(('-api', '-invalid', '-migration', '-jobs', '-bad-migration', '-client')):
+ log = docker('logs', '--tail', '12', name, check=False)
+ print(f'FIXTURE DIAGNOSTIC {name}\n{log.stdout}\n{log.stderr}', flush=True)
+ raise
+ finally:
+ runtime_inventory=[]
+ for name in names:
+ result=docker('inspect',name,check=False)
+ if result.returncode:continue
+ inspected=json.loads(result.stdout)[0]
+ mounts=[{'type':m['Type'],'destination':m['Destination']} for m in inspected.get('Mounts',[])]
+ assert not any(m['destination']=='/app' or m['destination'].startswith('/app/') or m['destination'].startswith('/opt/opnform') for m in mounts)
+ assert not inspected['HostConfig'].get('PortBindings')
+ runtime_inventory.append({'name':name,'image_id':inspected['Image'],'mounts':mounts,'public_ports':False})
+ for name in reversed(names):
+ docker('rm', '-f', '-v', name, check=False)
+ if network_created:
+ docker('network', 'rm', prefix, check=False)
+ if firewall_table:
+ run('nft', 'delete', 'table', 'inet', firewall_table, check=False)
+ report={'passed':passed,'backend_image':args.api_image,'frontend_image':args.client_image,'image_checks':image_checks,'runtime_inventory':runtime_inventory,'application_or_vendor_overlays':False,'actual_pair_revision_verified_separately':True,'execution':('native AMD64 runner' if __import__('platform').machine() in ('x86_64','amd64') else 'local ARM host running linux/amd64 under emulation'),'powerloss_or_native_RPO_or_real_identity_qualified':False,'containers_removed':all(not docker('ps','-aq','--filter','name=^'+n+'$').stdout.strip() for n in names),'network_removed':not docker('network','ls','-q','--filter','name=^'+prefix+'$').stdout.strip()}
+ (args.output_dir/'runtime-proof.json').write_text(json.dumps(report,indent=2)+'\n')
+ print(json.dumps({'passed':passed,'containers_removed':report['containers_removed'],'network_removed':report['network_removed']}),flush=True)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/Deployment/test_service_release.py b/tests/Deployment/test_service_release.py
new file mode 100644
index 000000000..363f77ef7
--- /dev/null
+++ b/tests/Deployment/test_service_release.py
@@ -0,0 +1,204 @@
+import copy
+import importlib.util
+import json
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import tempfile
+import unittest
+from unittest.mock import patch
+
+ROOT = Path(__file__).resolve().parents[2] / 'deploy/scaleway'
+
+
+def module(file):
+ spec = importlib.util.spec_from_file_location(file, ROOT / file)
+ value = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(value)
+ return value
+
+
+class ServiceReleaseTests(unittest.TestCase):
+ def setUp(self):
+ self.release = module('coolify-service-release.py')
+ self.candidate = {'schema': 'opnform-coolify-service-release/v1',
+ 'repository': 'OpnForm/OpnForm', 'ref': 'refs/heads/main', 'sha': 'c' * 40,
+ 'run_id': 42, 'run_attempt': 1, 'automatic_deployment': False,
+ 'images': {r: 'ghcr.io/opnform/hosted-' + r + '@sha256:' + 'a' * 64
+ for r in ('backend', 'frontend')}}
+
+ def test_only_an_explicit_complete_immutable_opnform_pair_is_accepted(self):
+ self.release.validate_release(self.candidate)
+ for key, value in [('repository', 'other/repo'), ('ref', 'refs/pull/1/merge'),
+ ('automatic_deployment', 'true'), ('sha', 'main'), ('run_attempt', True)]:
+ candidate = copy.deepcopy(self.candidate); candidate[key] = value
+ with self.subTest(key=key), self.assertRaises(ValueError):
+ self.release.validate_release(candidate)
+ for image in ['ghcr.io/opnform/hosted-backend:latest',
+ 'ghcrXio/opnform/hosted-backend@sha256:' + 'a' * 64,
+ 'ghcr.io/other/hosted-backend@sha256:' + 'a' * 64]:
+ candidate = copy.deepcopy(self.candidate); candidate['images']['backend'] = image
+ with self.subTest(image=image), self.assertRaises(ValueError):
+ self.release.validate_release(candidate)
+
+ def test_ci_must_be_complete_and_green_for_the_current_main_commit_and_attempt(self):
+ good = {'name': 'CI/CD Pipeline', 'head_sha': 'c' * 40, 'head_branch': 'main',
+ 'event': 'push', 'status': 'completed', 'conclusion': 'success', 'run_attempt': 1}
+ with patch.object(self.release, 'github', side_effect=[good, {'sha': 'c' * 40}]):
+ self.release.verify_ci(self.candidate)
+
+ for key, value in [('conclusion', 'failure'), ('status', 'in_progress'),
+ ('head_sha', 'd' * 40), ('event', 'pull_request'), ('run_attempt', 2)]:
+ run = dict(good); run[key] = value
+ with self.subTest(key=key), patch.object(self.release, 'github', return_value=run), self.assertRaises(ValueError):
+ self.release.verify_ci(self.candidate)
+ with patch.object(self.release, 'github', side_effect=[good, {'sha': 'd' * 40}]), self.assertRaises(ValueError):
+ self.release.verify_ci(self.candidate)
+
+ def test_native_archive_reference_is_bound_to_the_immutable_digest(self):
+ image = self.candidate['images']['backend']
+ self.assertEqual(self.release.native_image_name(image), 'opnform-hosted-backend:sha256-' + 'a' * 64)
+ meta = {'Architecture': 'amd64', 'Os': 'linux', 'Config': {'Labels': {'revision': 'c' * 40}},
+ 'RootFS': {'Type': 'layers', 'Layers': ['sha256:' + 'a' * 64]}, 'Id': 'engine-dependent'}
+ original = self.release.image_fingerprint(meta)
+ meta['Id'] = 'another-engine-identity'
+ meta['Config']['AttachStdin'] = False
+ meta['Config']['Cmd'] = None
+ self.assertEqual(self.release.image_fingerprint(meta), original)
+ meta['RootFS']['Layers'].append('sha256:' + 'b' * 64)
+ self.assertNotEqual(self.release.image_fingerprint(meta), original)
+ def test_no_apply_means_no_registry_pull_config_mutation_or_role_restart(self):
+ with tempfile.TemporaryDirectory() as directory:
+ root = Path(directory); descriptor = root / 'release.json'; descriptor.write_text(json.dumps(self.candidate))
+ target = root / 'target.json'; target.write_text(json.dumps({'service_uuid': 's' * 24}))
+ with patch('sys.argv', ['promote', str(descriptor), '--target', str(target)]), \
+ patch.object(self.release, 'validate_target'), patch.object(self.release, 'verify_ci'), \
+ patch.object(self.release, 'controller') as controller, patch.object(self.release, 'check_current'), \
+ patch.object(self.release, 'stage_images') as stage, patch.object(self.release, 'promote') as promote:
+ self.release.main()
+ controller.assert_called_once()
+ self.assertNotIn('apply', controller.call_args.kwargs)
+ stage.assert_not_called(); promote.assert_not_called()
+
+ def test_automatic_release_requires_a_real_boolean_and_the_same_main_ci_gate(self):
+ candidate = copy.deepcopy(self.candidate)
+ candidate['automatic_deployment'] = True
+ self.release.validate_release(candidate)
+ candidate['automatic_deployment'] = 'true'
+ with self.assertRaises(ValueError):
+ self.release.validate_release(candidate)
+
+ def test_local_controller_uses_only_the_installed_coolify_container(self):
+ target = {'controller_local': True}
+ with patch.object(self.release, 'execute', return_value='{}') as execute, \
+ patch.object(self.release, 'ssh') as ssh:
+ self.release.controller(target, self.candidate)
+ self.assertEqual(execute.call_args.args[0], ['docker', 'exec', '-i', 'coolify', 'php'])
+ ssh.assert_not_called()
+
+ def run_controller_fixture(self, directory, candidate, **options):
+ target = {'controller_local': True, 'service_uuid': 's' * 24,
+ 'server_id': 5, 'project_id': 4, 'team_id': 0, 'native_address': '100.65.151.96'}
+ with patch.object(self.release, 'execute', return_value='{}') as execute:
+ self.release.controller(target, candidate, **options)
+ # Execute the exact generated PHP against a model double. Only its
+ # bootstrap and private history root are substituted for this fixture.
+ program = '$x=json_decode' + execute.call_args.kwargs['input'].split('$x=json_decode', 1)[1]
+ program = program.replace('/var/www/html/storage/app/opnform-release-history', directory)
+ fixture = Path(__file__).with_name('coolify-model-fixture.php').read_text()
+ return subprocess.run(['php'], input=fixture + '\nnamespace {\n' + program + '\n}\n',
+ capture_output=True, text=True, timeout=10)
+
+ @unittest.skipUnless(shutil.which('php'), 'PHP is required for the generated controller fixture')
+ def test_successful_same_sha_reruns_have_independent_history_and_release_their_lease(self):
+ with tempfile.TemporaryDirectory() as directory:
+ for attempt in (1, 2):
+ candidate = {**self.candidate, 'run_attempt': attempt}
+ applied = self.run_controller_fixture(directory, candidate, apply=True)
+ self.assertEqual(applied.returncode, 0, applied.stderr)
+ finished = self.run_controller_fixture(directory, candidate, finish=True)
+ self.assertEqual(finished.returncode, 0, finished.stderr)
+ root = Path(directory) / ('s' * 24)
+ self.assertEqual(len(list(root.glob('*.json'))), 2)
+ self.assertFalse((root / '.promotion-active').exists())
+
+ @unittest.skipUnless(shutil.which('php'), 'PHP is required for the generated controller fixture')
+ def test_another_attempt_of_the_same_sha_cannot_release_an_active_promotion(self):
+ with tempfile.TemporaryDirectory() as directory:
+ applied = self.run_controller_fixture(directory, self.candidate, apply=True)
+ self.assertEqual(applied.returncode, 0, applied.stderr)
+ other = {**self.candidate, 'run_attempt': 2}
+ finished = self.run_controller_fixture(directory, other, finish=True)
+ self.assertNotEqual(finished.returncode, 0)
+ self.assertTrue((Path(directory) / ('s' * 24) / '.promotion-active').exists())
+ finished = self.run_controller_fixture(directory, self.candidate, finish=True)
+ self.assertEqual(finished.returncode, 0, finished.stderr)
+
+ def test_new_image_pins_are_persisted_only_after_successful_runtime_verification(self):
+ with tempfile.TemporaryDirectory() as directory:
+ path = Path(directory) / 'target.json'
+ target = {'product': 'opnform', 'service_uuid': 's' * 24, 'expected_current_images': {'backend': 'old'}}
+ path.write_text(json.dumps(target))
+ with patch.object(self.release, 'native', side_effect=RuntimeError('not healthy')):
+ with self.assertRaises(RuntimeError):
+ self.release.remember_current_images(target, self.candidate, path)
+ self.assertEqual(json.loads(path.read_text()), target)
+ images = {'backend': 'sha256:' + 'a' * 64, 'frontend': 'sha256:' + 'b' * 64}
+ with patch.object(self.release, 'native', return_value=images):
+ self.release.remember_current_images(target, self.candidate, path)
+ self.assertEqual(json.loads(path.read_text())['expected_current_images'], images)
+ self.assertEqual(path.stat().st_mode & 0o777, 0o600)
+
+ def test_old_main_without_a_release_artifact_cannot_trigger_the_controller(self):
+ automatic = module('auto-release.py')
+ with patch.object(automatic.promotion, 'github', side_effect=[{'sha': 'c' * 40},
+ {'workflow_runs': [{'id': 42, 'head_sha': 'c' * 40, 'name': 'CI/CD Pipeline'}]},
+ {'artifacts': []}]):
+ self.assertIsNone(automatic.eligible_run())
+
+ def test_automatic_controller_check_only_never_applies_even_an_eligible_release(self):
+ automatic = module('auto-release.py')
+ candidate = copy.deepcopy(self.candidate)
+ candidate['automatic_deployment'] = True
+ run = {'id': 42, 'run_attempt': 1, 'head_sha': 'c' * 40}
+ with tempfile.TemporaryDirectory() as directory:
+ root = Path(directory); target = root / 'target.json'; target.write_text('{}')
+ descriptor = root / 'release.json'; descriptor.write_text(json.dumps(candidate))
+ with patch('sys.argv', ['auto', '--target', str(target), '--state-dir', str(root), '--check-only']), \
+ patch.object(automatic.promotion, 'validate_target'), \
+ patch.object(automatic, 'eligible_run', return_value=run), \
+ patch.object(automatic, 'fetch_release', return_value=(candidate, descriptor)), \
+ patch.object(automatic.promotion, 'verify_ci'), \
+ patch.object(automatic.promotion, 'controller'), \
+ patch.object(automatic.promotion, 'check_current'), \
+ patch.object(automatic.subprocess, 'run') as apply:
+ automatic.main()
+ apply.assert_not_called()
+ self.assertFalse((root / 'state.json').exists())
+
+ def test_private_registry_visibility_is_checked_and_public_packages_are_rejected(self):
+ publisher = module('publish-release.py')
+ response = type('Response', (), {'returncode': 0, 'stdout': '{"visibility":"public"}'})()
+ with patch.object(publisher.subprocess, 'run', return_value=response), self.assertRaises(RuntimeError):
+ publisher.package_is_private('hosted-backend')
+
+ def test_publishing_cannot_be_invoked_from_a_pr(self):
+ publisher = module('publish-release.py')
+ env = {'GITHUB_SHA': 'c' * 40, 'GITHUB_REPOSITORY': 'OpnForm/OpnForm',
+ 'GITHUB_REF': 'refs/pull/42/merge', 'GITHUB_EVENT_NAME': 'pull_request'}
+ with patch.dict(os.environ, env), patch('sys.argv', ['publish', '--output', '/tmp/not-created']), \
+ patch.object(publisher, 'command') as command, self.assertRaises(RuntimeError):
+ publisher.main()
+ command.assert_not_called()
+
+ def test_main_workflow_cannot_call_legacy_deployments(self):
+ workflow = (ROOT.parents[1] / '.github/workflows/ci-cd.yml').read_text()
+ for legacy in ['vapor deploy', 'AMPLIFY_DEPLOY_URL', 'VAPOR_API_TOKEN', 'production-deploy:', 'build:amplify', 'name: amplify-output']:
+ self.assertNotIn(legacy, workflow)
+ self.assertIn('scaleway-runtime]', workflow)
+ self.assertIn('private OpnForm controller deploys after this CI run completes successfully', workflow)
+
+
+if __name__ == '__main__':
+ unittest.main()