Deployment
This is the production runbook for the supported Linux one-line installer and manual Docker Compose alternative.
Supported Swarm architecture
Section titled “Supported Swarm architecture”The installer creates one manager-pinned Docker Swarm stack:
- Caddy publishes ports 80 and 443 and obtains TLS certificates automatically.
- FrankenPHP, PostgreSQL, Redis, and Gotenberg stay private on an attachable overlay.
- PostgreSQL, Redis, Caddy state, and app storage use local persistent volumes.
- Docker Secrets supply application, database, Redis, storage, mail, and Meilisearch credentials.
The stable installer uses the checksummed version.json from the latest stable
GitHub Release. Its image value resolves to the per-commit FrankenPHP GHCR
reference built for that release. Use the separate
edge channel only for staging or development; it follows the current
unreleased master commit and uses the mutable edge-frankenphp image.
First deployment
Section titled “First deployment”Before installation, point the production domain to the VPS and make ports 80/443 available:
curl -fsSL https://github.com/yukazakiri/koakademy/releases/latest/download/install.sh | bashFor a non-interactive installation such as koakademy.koamishin.com, pass the domain through the environment:
curl -fsSL https://github.com/yukazakiri/koakademy/releases/latest/download/install.sh \ | env KOAKADEMY_DOMAIN=koakademy.koamishin.com bashThe bootstrap can be started as a normal user. It self-elevates only for
Docker, Swarm, and /opt/koakademy operations, then adds the invoking user to
Docker’s docker group. Activate the change in the current shell with
newgrp docker, or log out and back in, before using Docker without sudo.
Docker-group membership grants root-equivalent access to the host.
The process installs Docker if necessary, initializes Swarm if it is inactive, preserves an active manager, creates an attachable overlay network, creates Docker Secrets, starts Caddy and dependencies, runs one migration job, starts the app, and verifies https://koakademy.koamishin.com/up.
Complete https://koakademy.koamishin.com/setup, then check https://koakademy.koamishin.com/admin. The initial local application volume is suitable for a new single node only; configure external S3/R2 and backups before production reliance.
For an unreleased master build in staging without a domain, use the edge
bootstrap. It publishes the app directly on port 8000:
curl -fsSL https://raw.githubusercontent.com/yukazakiri/koakademy/master/scripts/install.sh | bash -s -- edgeOpen http://127.0.0.1:8000/setup, or pass --port 8080 to choose another
port. Edge is not a stable or production-supported release and may change or
break without notice.
Day-two operations
Section titled “Day-two operations”koakademy statuskoakademy updatekoakademy update --stablekoakademy update --edgekoakademy configure storage r2koakademy configure mail smtpkoakademy configure search enableupdate follows the installed channel by default. Pass --stable to select a
published release or --edge to select the current unreleased master build.
Stable updates download and verify the release bundle; edge updates download
the matching files from the master commit and use edge-frankenphp. Both
create a custom-format PostgreSQL dump under /opt/koakademy/backups, run
release migrations, perform a start-first app rollout, and check the HTTPS
health endpoint.
The command retains the preceding image:
koakademy rollbackRollback changes application code only. It never runs migrate:rollback or restores a database automatically. If the deployed migration is incompatible with old code, restore the recorded database backup and previous image together during a maintenance window.
Zero-interruption updates
Section titled “Zero-interruption updates”KoAkademy coordinates infrastructure cutover and live browser sessions so portal users can finish grading, enrollment, and form entry without being abruptly kicked out on every release:
- Start-first health-gated rollouts & decoupled Horizon: The Swarm stack (
scripts/swarm-stack.yml) and production Compose stack (compose.production.yaml) run Horizon in its ownhorizonservice (HORIZON_IN_HTTP_CONTAINER=false,stop_grace_period: 30m) while the webappservice usesorder: start-first,failure_action: rollback,stop_grace_period: 30s, and shared cache-backed maintenance state (APP_MAINTENANCE_DRIVER=cache,APP_MAINTENANCE_STORE=redis). - Retained Vite build assets: On HTTP container startup (
RETAIN_PREVIOUS_BUILD_ASSETS=true), hashed files from/app/public/build/assetsare copied additively into/app/storage/app/build-assetsand symlinked back while keeping each container’s/app/public/build/manifest.jsonlocal. Open browser tabs and overlapping replicas duringstart-firstrollouts continue resolving previous JS/CSS chunks forBUILD_ASSETS_RETENTION_DAYS(default7days) without 404 errors. - Soft Inertia version updates: Instead of immediately forcing a
409 Conflictfull-page reload on the next click (INERTIA_SOFT_VERSION_UPDATES=true), the server returns the normal Inertia page response alongside updatedappBuildmetadata. Active tabs display a non-blocking “Update ready” notification and seamlessly transition to the new build on the next clean cross-page navigation once no forms are dirty or dialogs are open. - Breaking-release escape hatch: If a deployment introduces a breaking frontend/API contract that requires every open tab to hard-reload immediately, increment
INERTIA_FORCE_RELOAD_VERSION(for example,INERTIA_FORCE_RELOAD_VERSION=2). - Expand-and-contract database migrations: Because
php artisan migrate --forceruns before the newappreplicas roll out (or under a blocking lock viaphp artisan app:migrate-lockedwhenAUTO_MIGRATE=trueandAUTO_MIGRATE_LOCK=trueare used for unattended PaaS auto-deploys), schema changes must remain backward-compatible with the currently running release (add nullable columns/tables in Release N, backfill asynchronously, and drop legacy columns only in Release N+1).
The migration release step
Section titled “The migration release step”Migrations are a release step, not a container boot. AUTO_MIGRATE=false is
the default, so an application replica never migrates the database while it
starts. A replica that boots against a schema it does not expect serves
traffic it cannot serve correctly, and a fleet that migrates from every
replica races itself.
The release order is:
- Back up the database.
koakademy updatetakes a PostgreSQL dump before it migrates. - Run
php artisan migrate --forceonce, in a dedicated job against the same database. The installer andkoakademy updatedo this for you; a manual deployment runs it in a one-off container. - Roll out the application. The new replicas start against the migrated schema.
- Verify the health endpoint.
docker compose --env-file .env -f compose.production.yaml run --rm app php artisan migrate --force --no-interactionThe installer runs the same command as a one-shot Swarm job before the
application rollout, and koakademy update runs it before it replaces the
application service.
Rollback never reverses a migration. koakademy rollback restores the
previous application image only. If a migration is not compatible with the
previous code, restore the recorded database backup and the previous image
together during a maintenance window.
Module releases and upgrades
Section titled “Module releases and upgrades”The module registry and the application image have separate release lifecycles. The registry publishes signed catalog and Composer metadata; it does not change code in an existing Swarm service. To update a standalone module such as Announcement:
- Release the module repository with a matching semver tag, for example
v1.0.2. - Update and sign the registry catalog, then wait for the registry Pages workflow to publish it.
- In the KoAkademy repository, run
composer update koakademy/announcement --with-dependenciesand commitcomposer.jsonandcomposer.lock. Usecomposer requirefor a package that is not declared yet. - Build and deploy a new application image through the normal stable or edge release process.
- Run
php artisan migrate --forcein the release container when the module has migrations, clear/rebuild application caches, and roll every Swarm replica. - Container startup runs
modules:sync-statusesafter migrations. It records installed package metadata without overwriting existing enabled/disabled choices or clearing restart-required markers. - Open Administrators → Marketplace and enable the installed module if it is disabled, then roll the workers when the Marketplace reports that a restart is required.
- After every replica has been updated and verified healthy, run
php artisan modules:sync-statuses --acknowledge-restartonce to clear the completed rollout marker.
Refreshing Marketplace only refreshes signed catalog information. It does not
install Composer packages, rebuild frontend assets, run migrations, or restart
Swarm. Module activation state is stored in the module_installations database
table; modules_statuses.json remains a first-boot and rollback fallback.
Existing source-tree modules under Modules/ also do not receive updates from
their standalone repositories until the application is deliberately migrated
to the Composer package. Keep the legacy module enabled during that migration
unless the migration plan explicitly changes its status.
Adding optional or community Composer modules (Self-Hosters)
Section titled “Adding optional or community Composer modules (Self-Hosters)”Self-hosting operators do not need to fork or clone the full KoAkademy source repository to install an optional Composer module or regulatory report adapter. Extend the official FrankenPHP release image with a 5-line Dockerfile:
FROM ghcr.io/yukazakiri/koakademy:v1.30.0-frankenCOPY --from=composer:2.10 /usr/bin/composer /usr/local/bin/composerUSER laravelRUN composer require vendor/koakademy-custom-module --no-interaction --no-scripts \ && composer dump-autoload --optimize --classmap-authoritative --no-dev --no-scriptsUSER rootBuild and deploy the extended image:
docker build -t local/koakademy-custom:v1.30.0-franken .
# Docker Swarm operator:koakademy update --image local/koakademy-custom:v1.30.0-franken
# Or Docker Compose (.env):# KOAKADEMY_IMAGE=local/koakademy-custom:v1.30.0-frankenBackups and recovery
Section titled “Backups and recovery”Back up and restore-test all of these:
- PostgreSQL custom dumps in
/opt/koakademy/backups - External upload and private-library buckets, including their retention/versioning policy
- Docker Swarm manager state, which protects installer-created secrets
The Redis volume is operational state, not the system of record. Losing APP_KEY can make encrypted application data unreadable.
Legacy Swarm migration
Section titled “Legacy Swarm migration”The new command refuses any host containing legacy koakademy-app, koakademy-postgres, koakademy-redis, koakademy-gotenberg, or koakademy-rustfs services. It exits before creating, changing, or deleting anything.
Migrate deliberately:
- Schedule a maintenance window and stop writes to the old deployment.
- Back up and restore-test PostgreSQL, uploads/object storage, and the old
APP_KEY. - Provision a fresh VPS or remove the legacy stack only after its backup is verified.
- Run the new installer, restore data according to the target release’s migration instructions, and configure external providers through
koakademy configure. - Verify login, uploads, queues, PDF generation, mail, and the public health endpoint before DNS cutover.
Never point both stacks at the same PostgreSQL database, Redis data, or storage volume.
Manual Compose
Section titled “Manual Compose”compose.production.yaml remains for operators who own their own edge proxy. It binds the application to 127.0.0.1:8000, so the proxy must preserve Host, X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto. Use an exact stable image tag, protected .env, external S3-compatible storage, explicit migrations, and an application restart after configuration changes.
docker compose --env-file .env -f compose.production.yaml pull app horizon schedulerdocker compose --env-file .env -f compose.production.yaml run --rm app php artisan migrate --force --no-interactiondocker compose --env-file .env -f compose.production.yaml up -d app horizon schedulercurl --fail --silent --show-error http://127.0.0.1:8000/up