recipes/laravel_go
Experimental
This recipe is experimental, and Laravel Go is in beta: options, defaults and behavior may change in a minor release. Report issues and feedback on GitHub.
import '@catapultjs/deploy/recipes/laravel_go'See the example Laravel Go project for a complete setup, or go directly to deploy.ts and its systemd units.
This recipe deploys a Laravel Go application. Laravel Go compiles to a single binary with its views and migrations built in: Catapult builds it for the platform of the server, delivers it with the frontend assets, runs the migrations and publishes the release. The recipe owns its pipeline: do not combine it with an application recipe.
The binary is built in one of three places, set with build.location:
| Location | Where the binary is built | Server needs |
|---|---|---|
container | In a local Docker or Podman container of the server platform | nothing |
local | On this machine, cross-compiled without cgo | nothing |
remote | On the server, from the delivered source code (default) | Go 1.27+, Node.js, npm |
See Container builds for engine and image settings, custom tasks, and cross-architecture builds.
Quick start
// deploy.ts
import { after, before, defineConfig, set } from '@catapultjs/deploy'
import '@catapultjs/deploy/recipes/laravel_go'
import '@catapultjs/deploy/recipes/systemd'
set('build', { location: 'container' })
// The recipe chooses no process manager: install and restart the systemd units.
set('systemd_services', ['myapp-server', 'myapp-worker'])
set('systemd_unit_files', ['deploy/myapp-server.service', 'deploy/myapp-worker.service'])
before('deploy:publish', 'systemd:install')
after('deploy:publish', 'systemd:restart')
export default defineConfig({
hosts: [
{
name: 'production',
ssh: 'deploy@example.com',
deployPath: '/srv/myapp',
healthcheck: { url: 'http://127.0.0.1:8000/up', retries: 10 },
},
],
})# deploy/myapp-server.service
[Unit]
Description=myapp server
After=network.target
[Service]
User=deploy
WorkingDirectory=/srv/myapp/current
ExecStart=/srv/myapp/current/app
Restart=always
TimeoutStopSec=25
[Install]
WantedBy=multi-user.target# deploy/myapp-worker.service: same unit, running the queue worker
ExecStart=/srv/myapp/current/app queue:workRun npx cata deploy:setup, create shared/.env on the server with the production settings, then run npx cata deploy:
# /srv/myapp/shared/.env
APP_ENV=production
APP_DEBUG=false
APP_KEY=base64:... # ./app key:generate --show
APP_URL=https://example.com
DATABASE_URL=postgres://user:password@127.0.0.1/myapp
SERVER_PORT=8000Add /.catapult to your .gitignore: local and container builds write the binaries there.
How it works
native:checkreads the platform of the server: architecture and glibc version.laravel:checkrequiresshared/.envwithAPP_KEY, and warns whenAPP_ENVis notproduction.- With
remote, the source code is delivered to the release as usual (core upload by default, or thegitandrsyncrecipes). laravel:assetsbuilds the frontend (npm ci && npm run build): once on this machine, or in the release withremote.native:buildbuilds the binary, andnative:uploaddelivers it withpublic/to the release. Views and migrations are embedded in the binary.laravel:migrateruns./app migrate --forcein the new release, before publication: a failed migration stops the deployment.currentswitches to the release, then your process manager restarts the application.
shared_files: ['.env'] and shared_dirs: ['storage'] are set by default. Units run from current, where the binary finds public/ and storage/; Laravel Go stops gracefully on SIGTERM and leaves requests SERVER_SHUTDOWN_TIMEOUT seconds (20 by default) to finish.
Pipeline
deploy:lock → native:check → laravel:check → deploy:release → laravel:code → deploy:shared → laravel:assets → deploy:prepare_build → native:build → native:upload → laravel:migrate → deploy:publish → deploy:log_revision → deploy:healthcheck → deploy:cleanup → deploy:unlock
Tasks
| Task | Inserted | Description |
|---|---|---|
native:check | yes | Reads the server platform, checks the toolchain or engine |
laravel:check | yes | Checks shared/.env |
laravel:code | yes | Delivers the source code, with remote only |
laravel:assets | yes | Builds the frontend assets |
native:build | yes | Builds the binary for the server platform |
native:upload | yes | Delivers the binary and public/, with local and container |
laravel:migrate | yes | Runs the migrations before publication |
Build locations
container builds in golang:1.27-bookworm for the platform of the server (--platform linux/arm64 for example), with the Go module and build caches kept in volumes: later builds take a few seconds. Docker or Podman must be installed locally. Catapult refuses an image whose glibc is newer than the server's, which would produce a binary that does not start: use an older image with build.image (for example golang:1.27-bullseye).
For container builds, the default pipeline opens the build container after laravel:assets and before native:build. Use container() or the JSON container step for additional tasks before compilation or between native:build and native:upload. Commands start at the project root inside the container. The compiled binary is available in $CATAPULT_OUT, and the upload includes the configured project files from the same workspace.
local runs go build on this machine with CGO_ENABLED=0 GOOS=linux GOARCH=<server architecture>: a static binary for the server, from macOS as well. Set laravel_go_cgo: true when a dependency requires cgo; cross-compilation then needs a C toolchain for the target, so prefer container.
remote builds in the release on the server, with GOCACHE and GOMODCACHE kept in shared/.cache/. Go, Node.js and npm are required on the server. Compiling needs memory: on a small server, limit the parallelism with build.env:
set('build', { location: 'remote', env: { GOFLAGS: '-p=1' } })build.env passes variables to the build in every location, for example GOPRIVATE for private modules.
Before delivery, Catapult checks that the built file is a Linux binary of the server architecture. A deployment targets one architecture: hosts of different architectures each get their own build.
Assets
Assets are built with the configured package manager. With local and container, they are built once on this machine and delivered with public/: Vite output is the same for every platform. With remote, they are built in the release: the lockfile must install on the server platform, as npm ci refuses a package-lock.json missing the optional dependencies of Linux when it was generated on macOS.
Remove laravel:assets from the pipeline for an application without a frontend. Remove laravel:migrate when migrations are managed separately. For example, to skip both in JSON:
{ "remove": ["laravel:assets", "laravel:migrate"] }In TypeScript, import remove from @catapultjs/deploy and call remove('laravel:assets') or remove('laravel:migrate') after loading the recipe. A migration restricted to one host needs a custom task that checks the task context's host.name.
Processes
The recipe does not choose a process manager. With systemd, install the units from the project with systemd:install before publication and restart them with systemd:restart after it, as in the quick start: manual and automatic rollbacks then restart them too. See recipes/systemd.
Run the scheduler every minute with cron or a systemd timer:
* * * * * cd /srv/myapp/current && ./app schedule:run >> /dev/null 2>&1With Inertia SSR, make the build script of package.json also build the SSR bundle (vp build && vp build --ssr), set INERTIA_SSR=true and add a unit running node bootstrap/ssr/app.js: Node.js is then needed on the server. Catapult delivers bootstrap/ssr/ when it exists. Reverb runs as another unit (./app reverb:start).
Configuration
| Key | Type | Default | Description |
|---|---|---|---|
build | { location, image?, engine?, env? } | remote | Where and how the binary is built |
laravel_go_cgo | boolean | false | Enables cgo for local builds |
build.image replaces the builder image of container, build.engine forces docker or podman.
All keys are available in JSON configurations with "recipes": ["laravel_go", "systemd"].
Rollback
npx cata rollback switches current back; with systemd:restart in the pipeline, the units restart on the previous binary. Migrations are not reversed: write migrations the previous release can still run against.
Limitations
- Laravel Go is in beta: its commands and configuration may change.
- One architecture per build: hosts with different architectures are built separately.
- The application restarts in place: a short interruption happens on each deployment.
To deploy the application as a container image instead, see Laravel Go and Rust in containers.