moonrise / laravel
Runtime glue for Laravel apps deployed with Moonrise: queue placement routing, edge origin checks and worker draining.
Requires
- php: ^8.3
- async-aws/core: ^1.30
- async-aws/s3: ^3.0
- async-aws/ssm: ^2.4
- illuminate/auth: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/queue: ^12.0|^13.0
- illuminate/routing: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
Requires (Dev)
- aws/aws-sdk-php: ^3.401
- bref/laravel-bridge: ^3.1
- brianium/paratest: ^7.20
- laravel/horizon: ^5.41
- laravel/pint: ^1.32
- league/flysystem-aws-s3-v3: ^3.0
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.5|^12.0
Suggests
- bref/laravel-bridge: Required on Lambda: Moonrise\Runtime\Lambda\QueueHandler extends its SQS handler.
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-30 18:47:55 UTC
README
The runtime package for Laravel apps deployed with Moonrise. Moonrise runs your app on AWS (containers on ECS, and functions on Lambda when you ask for them) and sets everything this package needs through environment variables, so you configure none of it by hand.
An app deployed with Moonrise requires this package: add it with
composer require moonrise/laravel
and commit composer.json and composer.lock. Moonrise's container images start the app through
vendor/bin/moonrise-env, which this package installs, so a build without it is refused.
What it does
- Loads the release's configuration at start.
bin/moonrise-envmerges the variables saved for the environment into the process before the app boots. It refuses to start rather than overwrite a variable that is already set. - Queue placement. A
moonrisequeue connection places each job on the queue the environment's routes name (SQS or Redis, container or Lambda workers), and enforces SQS's delay and size limits before a push. - Edge checks. Middleware refuses requests that did not come through the environment's CloudFront edge, takes the client address and host the visitor used from it, and answers the health check with the release number.
- Worker draining.
bin/moonrise-workerandphp artisan moonrise:drainkeep a worker task protected from ECS's stop while its consumers are busy, and drain it once its release is retired.moonrise:workbecomes the task's queue worker (Horizon orqueue:work). - Named resource bindings. Database, Redis and filesystem connections are registered from
MOONRISE_DATABASE_*,MOONRISE_CACHE_*andMOONRISE_BUCKET_*; an app's own entries win. Uploads to those buckets send no ACL. APP_KEYkeyring. WhileAPP_PREVIOUS_KEYSis set, sessions and signed values made under earlier keys are still accepted.- Failed jobs and batches. Moonrise's own subclasses of Laravel's database failed-job provider and batch
repository record each failure once.
moonrise:failed-jobslists, shows, retries or forgets failed jobs,moonrise:dead-letterscollects dead letters into them, andmoonrise:queue-clearempties a queue a restored snapshot brought back. - Lambda. A queue handler built on
bref/laravel-bridge(installed by Lambda apps only).
Requirements
PHP ^8.3, and Laravel 12 or 13 (illuminate/* ^12.0|^13.0). The package is discovered by Laravel; there is
nothing to register.
What the package does to an app that installs it
Everything below is registered by the package's service provider (MoonriseServiceProvider), which Laravel discovers.
What the package changes with no Moonrise setting
Three of these replace Laravel's own queue pieces. They look for no Moonrise setting and no AWS, so an app that installs the package while it is still hosted elsewhere gets them too:
- Failed jobs. When failed jobs are kept in the database with uuids (
queue.failed.driverisdatabase-uuids, which is Laravel's default), Laravel's failed-job provider is replaced by the package's subclass. It keeps one row per job: the same failure recorded twice stays one row (Laravel's own would stop with a duplicate-key error), and a retried job that fails again replaces its row, keeping its uuid. A new failure is written without first locking its neighbours in the table, so failures landing at the same moment do not block each other. An app's own subclass of Laravel's database-uuids provider is replaced as well. - Batches. Laravel's database batch repository is replaced by the package's subclass, and every batch it hands
out (from
Bus::batch(),Bus::findBatch()or a job'sbatch()) is the package'sBatchsubclass. A job's failure counts once in its batch. A failure of a job the batch has already counted (the same failure delivered again, or a job retried withqueue:retry-batchthat fails again) changes nothing and runs no callback: no cancel, progress, failure, catch or finally. Laravel's own counts it again and, in a batch that allows failures, runs the progress and failure callbacks again. So a batch callback runs once per job's failure, not once per attempt: work that must happen every time the job is marked failed belongs in theJobFailedevent or the job'sfailed()method. The package's repository makes its batches with its own factory, so an app's ownBatchFactorybinding is not used, and an app's own subclass of Laravel's database batch repository is replaced as well. queue:retry. In the console, while failed jobs are kept indatabase-uuids, Laravel'squeue:retryis replaced by the package's subclass. It pushes each job with a newer retry generation (amoonriseFailureGenerationkey in the payload) and then forgets the failure only if its row still holds the generation it retried, so a retry that has already failed again keeps its own failure. Its ids,all,--queue,--rangeand messages are Laravel's.
The rest are registered in every app as well, and each acts only once what it names is there or in use: its setting, your own config file, one of its commands, or a queue connection a push goes to:
- Lays your own
config/moonrise.php, if you have one, over the package's defaults, key by key (unless the configuration is cached). - Adds a
moonrisequeue connection and connector when yourconfig/queue.phphas no connection of that name. Nothing uses it unless a queue setting names it, such asQUEUE_CONNECTION=moonrise. - Stamps the logical queue on payloads the
moonriserouter places, and refuses a push to an SQS connection whose payload is over 1 MiB or whose delay is over 900 seconds (SQS's own limits), unless the connection uses Laravel's overflow storage. - Reads the queue routes at boot (
MOONRISE_QUEUE_ROUTES), and stops the boot when they are set but unreadable. - Binds the worker, drain and log-line services in the container. They do nothing until a worker or drain command runs.
- Prepends four HTTP middleware: the release header on the health check, the edge-origin check, the client address taken from CloudFront, and the viewer host. Each does nothing until its setting (a release, an edge secret, a primary domain or a public URL) is present.
- Registers named database, Redis and filesystem connections from
MOONRISE_DATABASE_*,MOONRISE_CACHE_*andMOONRISE_BUCKET_*when those are set (none otherwise), and sends no ACL on uploads to those buckets. - Points the Bref queue handler at the app's SQS connection, when
bref/laravel-bridgeis installed. - In the console, registers
moonrise:deploy-commands,moonrise:drain,moonrise:work,moonrise:failed-jobs,moonrise:dead-letters,moonrise:assets:publish,moonrise:capabilitiesandmoonrise:queue-clear.
What the package changes only when its setting is present
- Accepts every key in
APP_PREVIOUS_KEYSfor sessions and signed closures while that is set, and issues withAPP_KEY. - Forces the URL scheme to https (with a primary domain), or the root URL and its scheme (with a public URL only).
- Trusts proxies for
X-Forwarded-Forwhen an edge secret is set. - Under
LAMBDA_TASK_ROOT, turns off Bref's job logging (bref.log_jobs) and records failed jobs through its own listener. - Under
MOONRISE_WORKER_ENTRYPOINT=1(set bybin/moonrise-worker), reports consumer readiness, writes job lines and gates the worker's pops on ECS task protection. - In a web process inside an ECS task (not the console), writes a web-ready line at the task's first healthy check.
Build assets: php artisan moonrise:assets:publish
Moonrise runs this as a one-off task on the release's own image. It uploads the files Vite's manifest lists
to the environment's assets bucket under build/, never overwriting a key.
What the build must look like:
- The manifest is at
public/build/manifest.json, where laravel-vite-plugin writes it. Vite's own default,public/build/.vite/manifest.json, is refused: a dot-directory underpublic/buildstops the run. - Nothing under
public/buildmay be a symlink, a dotfile (or dot-directory) or a PHP file, listed in the manifest or not. Neitherpublicnorpublic/buildmay be a symlink either. Any of these means the build is not what Vite makes, so nothing is published. - Every listed path stays inside
public/build. Files the manifest does not list (sourcemaps, the manifest itself) are left out, not refused. - File names are content-hashed (Vite's default). A key that already holds a different file fails the run rather than serve the old one.
The command prints one result line on stderr: {"moonrise":"assets-publish","outcome":"published"|"refused"|"failed",...},
exiting 0, 78 or 1.