recipes/laravel_rust
Experimental
This recipe is experimental, and Laravel Rust is in beta: options, defaults and behavior may change in a minor release. Report issues and feedback on GitHub.
import '@catapultjs/deploy/recipes/laravel_rust'See the example Laravel Rust project for a complete setup, or go directly to deploy.ts and its systemd units.
This recipe deploys a Laravel Rust application. Laravel Rust compiles to a binary with its migrations built in, and reads its views from resources/views/ at runtime: Catapult builds the binary for the platform of the server, delivers it with the views and the frontend assets, runs the migrations and publishes the release. It shares its pipeline and options with laravel_go: this page focuses on what differs.
| 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, only when it runs the server platform | nothing |
remote | On the server, from the delivered source code (default) | Rust 1.99+, a C compiler, Node.js |
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_rust'
import '@catapultjs/deploy/recipes/systemd'
set('build', { location: 'container' })
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 },
},
],
})The units are the same as for laravel_go, with the binary named after your package: ExecStart=/srv/myapp/current/example-app and example-app queue:work for the worker. shared/.env also sets DB_CONNECTION (postgres, mysql or sqlite).
Add /.catapult to your .gitignore.
Differences with Laravel Go
- Binary name: read from
Cargo.toml, the first[[bin]]target, else the package name. Setlaravel_rust_binto choose another one. - Delivered files: the binary,
public/andresources/views/(the root view is read at runtime), plusbootstrap/ssr/when it exists. - Local builds run only on a Linux machine of the server architecture, such as a CI runner: crates with C code (
ring,mimalloc, SQLite) cannot be cross-compiled without a C toolchain for the target. Catapult refuses other local builds before building anything: usecontainerfrom macOS. - Workers: Laravel Rust has no
queue:restart. Restart the worker units after each deployment, whichsystemd:restartdoes. - First build: several hundred crates compile on the first build. Later builds reuse the caches and take seconds.
Build locations
container runs cargo build --release --locked in rust:1.99-bookworm for the platform of the server. The Cargo registry, git checkouts, build directory and target/ are kept in volumes, outside your project: your own target/ is not touched. Catapult refuses an image whose glibc is newer than the server's: pick another image with build.image.
remote builds in the release on the server, with CARGO_TARGET_DIR kept in shared/.cache/cargo-target. Rust, a C compiler (build-essential on Debian and Ubuntu), Node.js and npm are required on the server. On a small server, build with one job:
set('build', { location: 'remote', env: { CARGO_BUILD_JOBS: '1' } })Cargo.lock must be committed: builds use --locked.
Configuration
| Key | Type | Default | Description |
|---|---|---|---|
build | { location, image?, engine?, env? } | remote | Where and how the binary is built |
laravel_rust_bin | string | Cargo.toml | Name of the binary to build and run |
All keys are available in JSON configurations with "recipes": ["laravel_rust", "systemd"].
Pipeline, tasks, assets, processes, scheduler and rollback work as for laravel_go. To deploy the application as a container image instead, see Laravel Go and Rust in containers.