How to deploy Laravel on multiple Fly machines?

I followed the setup guide here but it yields a few issues:

Issue 1: persisting a volume

  1. If we persist the volume, only one machine can mount it and there doesn’t seem to be a supported way for multiple machines to safely write to the same hard disk for things like cache.
  2. If we persist a volume, there doesn’t appear to be a way to run deploy scripts since Fly start scripts don’t have volume access when they run. Any application needs to run php artisan optimize on deploy and there doesn’t appear to be a way to do this without SSHing in every time and running it manually in the console.

It seems to me that the Fly documentation for Laravel probably should say that you can only use one machine unless you use additional servers for everything else, which I’m totally fine with and it makes sense to do so. If we follow that path, it makes sense that if we stay within the Fly system, we need to create a Redis and Postgres machine, and use a 3rd party storage service like S3 or Tigris. Assuming we’ve done that and that Redis will handle queues and cache, here’s the remaining issues that I’m not confident are handled out the gates:

Issue 2: How do we persist laravel logs?
Issue 3: How do we prevent the laravel scheduler (Laravel jobs that run at the same time every day) from running multiple times on the multiple machines?
Issue 4: How does the queue work with multiple machines? Does Redis automatically distribute between the machines and there’s no risk of double-running?
Issue 5: Any other considerations or concerns that we should have running multiple machines?

Lots of good questions, and I don’t have all the answers but here’s a few.

  • Volumes are indeed local to each machine
  • Take a look at the Dockerfile and dockerfile-entrypoint in dockerfile-node/test/frameworks/next-standalone at main · fly-apps/dockerfile-node · GitHub , the ENTRYPOINT can specify a script to be run. That script has full access to volumes and secrets, and is passed the CMD as arguments so it can launch that command when done.
  • If you direct your logs to stdout/stderr, you can run a log shipper to send your log files elsewhere: Shipping Logs · The Fly Blog
  • Redis can be used as a cache or as a queue. “Automatic distribution” is more a matter of how you use Redis than a feature of Redis itself.