Alpha
Alpha
AlphaBeta: when quoting is solved

Getting Started

Deployment

Introduction

When you're ready to deploy your Laravel Bash application to production, there are some important things you can do to make sure it runs as efficiently as possible. There aren't many, because there isn't much of it.

Server Requirements

The image in the Dockerfile has everything: Bash 5, the GNU tools, socat, sqlite3, jq and tini. Whatever runs it needs to give the app:

The Image

Locally, compose mounts the project into the container. In production, the image is the app, so the Dockerfile copies it in, and .dockerignore leaves out .git, .env, the local database and everything in storage/.

tini is PID 1. It passes SIGTERM on to ./artisan dev, which stops the others and exits, and it reaps the processes socat forks for each request:

ENTRYPOINT ["tini", "-s", "--"]
CMD ["./artisan", "dev"]

When ./artisan dev starts, it makes any storage/ folders that are missing, because a new, empty volume hides the folders the image came with. Then it waits up to a minute for the database to answer, and if it has never been migrated, it runs migrate --seed before anything else starts.

Configuration

There's no .env in production. Set real environment variables instead:

APP_ENV=production
APP_DEBUG=false                                # error pages without the stack trace
APP_URL=https://laravel-bash.mrstebo.co.uk     # canonical URL for sitemap, Open Graph, llms.txt
DB_CONNECTION=pgsql                            # with DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD
PGSSLMODE=require                              # psql reads this itself
TRUSTED_PROXY_HEADER=X-Envoy-External-Address  # see Rate Limiting in the routing docs
MAX_CHILDREN=32                                # requests at once; the rest wait to be accepted
APP_DEMO=true                                  # run demo:reset every hour

MAX_CHILDREN goes to socat as max-children. Each open Server-Sent Events stream holds one until its tab closes, so leave room for them.

Health Checks

Like Laravel, Laravel Bash has a health route at /up. It answers 200 Application up when the database does, and 500 when it doesn't.

Streaming Through a Proxy

Proxies close connections that go quiet. Broadcasting streams send a : ping comment line after 15 seconds without an event, which browsers ignore. Set BROADCAST_HEARTBEAT to change the interval.

SQLite on a Volume

To keep everything in one container, put the SQLite database on the same volume as everything else:

DB_SQLITE_PATH=storage/database.sqlite

A volume can only be mounted by one container at a time, so deploys have to stop the old container before they start the new one. Expect half a minute of downtime on every deploy.

Northflank

The repository has a Northflank template in northflank.json. It creates a project with:

With nothing on the service's disk worth keeping, deploys are rolling: the new container starts, passes its health check, and only then does the old one stop.

With GitOps switched on for the template, Northflank reads the template from the repository and runs it again whenever northflank.json changes on main. There's no deploy pipeline.