Search by

moonrise / laravel

SnakeO

Runtime glue for Laravel apps deployed with Moonrise: queue placement routing, edge origin checks and worker draining.

Package info

github.com/seemoonrise/laravel

pkg:composer/moonrise/laravel

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-11-30 15:24 UTC

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-env merges 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 moonrise queue 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-worker and php artisan moonrise:drain keep a worker task protected from ECS's stop while its consumers are busy, and drain it once its release is retired. moonrise:work becomes the task's queue worker (Horizon or queue:work).
  • Named resource bindings. Database, Redis and filesystem connections are registered from MOONRISE_DATABASE_*, MOONRISE_CACHE_* and MOONRISE_BUCKET_*; an app's own entries win. Uploads to those buckets send no ACL.
  • APP_KEY keyring. While APP_PREVIOUS_KEYS is 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-jobs lists, shows, retries or forgets failed jobs, moonrise:dead-letters collects dead letters into them, and moonrise:queue-clear empties 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.driver is database-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's batch()) is the package's Batch subclass. 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 with queue:retry-batch that 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 the JobFailed event or the job's failed() method. The package's repository makes its batches with its own factory, so an app's own BatchFactory binding 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 in database-uuids, Laravel's queue:retry is replaced by the package's subclass. It pushes each job with a newer retry generation (a moonriseFailureGeneration key 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, --range and 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 moonrise queue connection and connector when your config/queue.php has no connection of that name. Nothing uses it unless a queue setting names it, such as QUEUE_CONNECTION=moonrise.
  • Stamps the logical queue on payloads the moonrise router 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_* and MOONRISE_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-bridge is installed.
  • In the console, registers moonrise:deploy-commands, moonrise:drain, moonrise:work, moonrise:failed-jobs, moonrise:dead-letters, moonrise:assets:publish, moonrise:capabilities and moonrise:queue-clear.

What the package changes only when its setting is present

  • Accepts every key in APP_PREVIOUS_KEYS for sessions and signed closures while that is set, and issues with APP_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-For when 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 by bin/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 under public/build stops the run.
  • Nothing under public/build may be a symlink, a dotfile (or dot-directory) or a PHP file, listed in the manifest or not. Neither public nor public/build may 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.