Brewless Brewless Docs

Getting started

Laravel for Go

Deploy a Laravel for Go application with Brewless, from the module and brewless.yml to the build, the edge, the queue, mail and what is not there yet.

On this page

Laravel for Go compiles an application to one static binary that speaks HTTP itself. Brewless builds that binary, runs its migrations and puts it live as a serverless container in your own Scaleway project, behind bunny.net, with the same commands as Laravel for PHP. This page says what is different. Everything it does not name works as the rest of this documentation describes.

Warning

Laravel for Go is at version 0.x, and its APIs may change before 1.0. The module github.com/brewless/laravel-go follows it, so keep both up to date together.

What is supported

For a Laravel for Go application
Build, release and rollback Yes
Release commands and brewless command Yes, as commands of your own binary
Database Scaleway Serverless SQL or a Managed Database, as DATABASE_URL
Edge cache, private origin and Shield Yes
Queue and schedule Yes. Jobs on Scaleway Queues are signed and delivered as they arrive. See Queue and schedule
Bucket for files Yes, with the framework's own s3 disk. See Files
Mail Scaleway Transactional Email, through the module's smtp mailer. See Mail. Not Lettermint
Deploy on push Yes. The workflow for GitHub Actions tests with go test ./...
The deploy button Yes, for a public repository whose go.mod requires go.laravel.com

What is not there is listed under What is not there yet. Every plan includes Laravel for Go at the same price as Laravel for PHP.

What you need

  • A Laravel for Go project: a go.mod that requires go.laravel.com, and a committed go.sum.
  • The Brewless command line client at version 1.11.0 or later.
  • PHP 8.4 or newer on the machine that deploys. The client is a PHP program, also when the project is not. Your application and its container need no PHP.
  • A Scaleway account and an organisation at Brewless, as in the Quickstart. Its steps 0, 1 and 2 are the same.

Setting it up

1. Add the module

go get github.com/brewless/laravel-go

github.com/brewless/laravel-go is the Go counterpart of the Composer package brewless/laravel and the Rust crate brewless-laravel. It answers on the same paths, so Brewless can run the release commands, the schedule and the queue, and it reads the same variables. It is open source under the MIT licence.

2. Start the application through the module

In main.go, replace laravel.Run(bootstrap.Options()) with:

main.go
brewless.Run(bootstrap.Options())

This adds the module to your application's packages and starts it the way the framework does, with its console commands and its graceful shutdown. Behind the edge the container sees its own address as the host and a proxy in Scaleway's network as the peer. When a request carries the edge secret, the module takes over the host bunny.net names in Cdn-Host and the visitor's address, and routes the request once more with them. Without the valid secret, forwarded headers are not believed, and a request that names a host the application does not have is refused.

Listing brewless.New() in laravel.Options.Packages yourself works too, but then a request with a host the framework read before the module checked it is refused instead of routed again.

3. Connect the project

brewless init

init recognises the project from go.laravel.com in go.mod, creates the application and writes brewless.yml. It then asks for the environments, as described under init.

brewless.yml
organisation: acme
application: shop
framework: laravel-go

release:
  - 'migrate --force'

environments:
  production:
    edge:
      cache: 1h

There is no php line. Commit brewless.yml, go.mod and go.sum: a deploy builds what is committed.

4. Deploy

brewless deploy production

The client prints each step as it finishes. Deployments explains the steps around the build.

What the build does

The build runs as a Serverless Job in your own Scaleway project, with 2 vCPU and 4 GB of memory, and may take up to half an hour. It runs on ghcr.io/brewless/brewless-builder:go1.27, with the newest patch release of Go 1.27 and Node. There is one toolchain version for now: a toolchain line in go.mod does not make the build fetch another one (GOTOOLCHAIN=local). When a new patch release of Go comes out, Brewless builds your live commit again with it by itself, see Security updates.

  1. With a package-lock.json in the project: npm ci and npm run build. The frontend comes first, so what Vite writes is in public/ when the binary starts.
  2. go mod verify: every module the build takes, downloaded or from the cache, must have the hash go.sum names for it.
  3. go build of the package at the root of the project, which has to be package main, with CGO_ENABLED=0, -trimpath and -mod=readonly. The result is a static binary.
  4. The build commands of your brewless.yml, if any.

The binary goes into the image as .brewless/app, next to public/ and storage/. Nothing else of your project goes along, so your source is not in the image. The image is built on ghcr.io/brewless/brewless-base:go, a distroless image with certificates, time zones and a user, and nothing else. It has no C library, no shell and no package manager, and runs as www-data.

The build cache

Go's downloaded modules and its build cache are kept between builds, as one object compressed with zstd, in the bucket of your project that the source is uploaded to.

  • The job gets a link to fetch that object and a link to put it back. It never holds a key to your storage.
  • It is put back only when go.sum or the Go version changed. Your own code is compiled again on every commit anyway.
  • A cache that is missing or cannot be read never fails a build. The build then starts from nothing, as the first one did.
  • Before anything is unpacked, the build reads what the object holds. One larger than 4 GiB, or with anything outside its two folders or a link that leads out of them, is not unpacked: the build starts from nothing and keeps a new cache in its place.

Release commands

Release commands run in the release container before a release goes live, as commands of your own binary:

brewless.yml
release:
  - 'migrate --force'

Migrations are compiled into the binary and only go forward: the framework has no command to roll one back, and a change you want to undo is a new migration. brewless rollback puts the previous release back, which is its image. It does not touch the database.

brewless command runs your application's own console commands the same way:

brewless command staging "route:list"

There is no tinker for Go, so brewless tinker has nothing to run, and says so from CLI 1.11.0.

Variables your application gets

A new environment is given these, in the names Laravel for Go reads. A value you set yourself always wins. See Variables.

Variable Value
APP_NAME, APP_KEY, APP_URL As for Laravel for PHP
APP_ENV, APP_DEBUG production and false
DATABASE_URL With a database: its address as one URL, over TLS
CACHE_STORE, SESSION_DRIVER database with a database, otherwise memory and cookie
QUEUE_CONNECTION Where the jobs wait
SQS_*, AWS_ENDPOINT_URL_SQS With a queue at Scaleway Queues: its endpoint and a key of its own, which the module gives to the sqs connection alone
AWS_* With a bucket: its key, and AWS_URL with the files address
MAIL_* With mail through Scaleway: MAIL_MAILER=smtp and the same names as Laravel for PHP
BREWLESS_EDGE_SECRET, BREWLESS_DOMAINS What the module checks a request from the edge with
BREWLESS_EDGE_CACHE The seconds of edge.cache in brewless.yml

DB_CONNECTION is not given: in Laravel for Go it names one of your application's own extra connections. The database address ends in ?sslmode=require for PostgreSQL and ?tls=true for MySQL.

The edge

The module adds Cache-Control: public, max-age=0, s-maxage=<edge.cache> to an answer to a GET or HEAD that sets no cookie, carries no Cache-Control of the application's own and varies on nothing but Accept-Encoding. bunny.net keeps such a page and answers the next visitor itself, without asking your container. Every release empties the edge. A 404 is kept for a minute at most. Edge cache describes the edge itself; its sections about sessions and guests are about brewless/laravel for PHP.

A request that says who is asking is never kept: one with a cookie, with Authorization, with a header whose name holds auth, token, api-key, secret, session, signature, tenant or xsrf, or with X-Requested-With or X-Inertia.

A page that starts a session sets a cookie, and a page that sets a cookie is never kept. Keep the session off the routes of public pages you want the edge to answer. An answer that depends on something the request does not show, such as the visitor's address or Accept-Language, has to say so itself, with Cache-Control or Vary.

Queue and schedule

Nothing stays running on a serverless container, so something has to call the worker. With the module that is the queue and the schedule themselves.

Jobs on Scaleway Queues

With queue: sqs, your application changes nothing: the connection is still called sqs, and the module puts a driver of its own in its place.

  1. The module signs every job your application puts on the sqs connection, with a key derived from APP_KEY and the environment (BREWLESS_ENVIRONMENT, which Brewless gives every container). The signature is the same as the Rust crate's, and the key is derived as in the PHP package.
  2. Scaleway Queues delivers each message to the worker container as it arrives.
  3. The module checks the signature and runs that one job with the framework's own worker, so the job's tries, its backoff and the failed jobs apply as they do for queue:work.

A message that is unsigned, was changed on the way, was signed in another environment, was signed more than an hour ago or names a queue that is not this application's is dropped, with a warning in the log. So is a second delivery of a job that was handled already: a delivery is marked in your application's cache before the job runs. A job that fails for good is kept with the failed jobs, and Try failed jobs again in the console puts it back. Failed jobs need a database.

A job with a delay longer than the 15 minutes Scaleway Queues takes goes back on the queue for what is left when it arrives, signed again. A workflow that sleeps for longer works this way.

What is not signed, and so not delivered this way: a FIFO queue. With jobs in the database (queue: database) the worker is called every minute and runs queue:work --stop-when-empty --max-time=45, as described under How the worker is called.

The schedule

A Scaleway cron calls the worker container at the moments your schedule has work, and the module runs schedule:run. The Schedule tab of the console lists your tasks and those moments. A task you add or change gets its moment with the next deploy.

The framework's ticks (laravel.Options.Ticks) keep running inside the process that serves requests. They look after that process's own memory, which a container that scales to zero takes with it, so do not use a tick for work that has to happen: put that on the schedule.

Files

With a bucket, the framework's own s3 disk reads and writes it: AWS_BUCKET adds the disk, and the framework signs its requests itself. A temporary URL leads to the bucket, also for a private file.

With bunny.net in front, the bucket gets a files address, and a deploy gives it to the containers as AWS_URL once the address answers with its certificate. The edge asks the bucket without a key, so it serves only a file that is public. The framework never changes a file's permissions.

Mail

With mail: scaleway, the module adds a mailer named smtp for Scaleway Transactional Email, and Brewless sets MAIL_MAILER=smtp. It reads the same MAIL_* variables as Laravel for PHP and signs in only over TLS or STARTTLS. See Mail for the domain and its DNS records.

mail: lettermint does not work for this framework: Lettermint has no package for Go. A mailer name the framework does not have would stop the application at startup, so Brewless does not give one.

Realtime

Broadcasting works as it does for Laravel for PHP, on Brewless's realtime image. Set realtime: true on the environment in brewless.yml: for a Go application that means the Brewless image, without the closed beta Laravel for PHP needs for it. Brewless then gives your application REVERB_APP_ID, REVERB_APP_KEY, REVERB_APP_SECRET, REVERB_HOST, REVERB_PORT, REVERB_SCHEME and BROADCAST_CONNECTION=reverb, which the framework's reverb connection reads unchanged. Your build gets the VITE_REVERB_* variables for Echo. Browsers connect to the realtime container, not to your application.

  • broadcast.Send and broadcast.SendNow publish through the Pusher API of that container.
  • Echo authorises private and presence channels at your application's POST /broadcasting/auth, with the channels in routes/channels.go. The realtime server checks the signature your application gives.
  • Only pages on your own hostnames may connect (REVERB_ALLOWED_ORIGINS). Another origin is closed with Pusher code 4009.

The framework's own reverb:start is not used on Brewless, so image: app is refused when the file is checked. Sizes and the address are set as on Realtime.

Deploy on push

Deploy on push works as for any application. The workflow the console writes for GitHub Actions tests a Go application with go test ./... in the official Go image, and deploys with the command line client. Its deploy job sets PHP up for the client. See A whole workflow for GitHub Actions.

What is different from Laravel for PHP

Laravel for PHP Laravel for Go
Package composer require brewless/laravel, discovered by itself go get github.com/brewless/laravel-go and brewless.Run in main.go
In brewless.yml framework: laravel and a php version framework: laravel-go, no php line
A build Installs your Composer packages Compiles your application
The image FrankenPHP with PHP and your code Your static binary on a distroless image, without a shell and without your source
Database DB_HOST and the other parts One DATABASE_URL
A line of code in an environment brewless tinker Not there. brewless command runs your own commands
Undoing a migration migrate:rollback A new migration
Security fixes of the base image Put under the live release by Brewless Put under the live release by Brewless, without compiling
Security fixes of what you depend on Composer and npm packages: your next deploy Go modules: your next deploy. A Go patch release: Brewless builds the live commit again

What is not there yet

  • Tinker. There is none for Go.
  • Automatic updates of your modules. Brewless puts a patched base image under your live release, and builds the live commit again when Go publishes a patch release, see Security updates. A vulnerability in a module your application depends on needs you: update it and deploy. A new Go version, such as 1.28, is not taken by itself either.
  • Maintenance mode during a backup. The framework keeps maintenance mode in a file on the container's own disk, which no other container sees, so a backup of a Go application runs without it.
  • API Guardian's own OpenAPI document. Nothing writes one from this framework's routes.
  • Signed jobs on a FIFO queue or on the database queue. See Jobs on Scaleway Queues.
  • What brewless/laravel does inside a PHP application and the module does not do yet: databases per tenant, the client for Malware Protection, the client for database capacity and edge publishing.
  • More than one binary or toolchain. A project builds the one package at its root, on Go 1.27.

When something goes wrong

  • The build stops before go build. The package at the root of the project is not package main. Brewless builds that package and nothing else.
  • go mod verify fails. A module does not have the hash go.sum names. Run go mod tidy and go mod verify on your own machine, commit go.sum and deploy.
  • The application does not start. A variable names a mailer, a cache store, a disk or a queue connection your application does not have, such as a MAIL_MAILER you set yourself. Change the variable and deploy.
  • Redirects and generated URLs point at the container's address. main.go still starts the application with laravel.Run. See step 2.
  • A page is never answered by the edge. It sets a cookie. See The edge.
  • bunny.net answers 403 for a file. The file is not public in the bucket. See Files.
  • A job is dropped with "its signature does not hold". It was signed with an APP_KEY the environment no longer has, or in another environment. Put the old key in APP_PREVIOUS_KEYS while such jobs are still on the queue.
  • The first request after a quiet time is slow. A container that was scaled to zero has to start, and a Serverless SQL Database that slept makes the first query wait.