Skip to content

Deploy to Fly.io

Goal: run the app on a Fly machine. Hamur has no fly preset and hamur deploy does not call flyctl; Fly builds a Dockerfile, and hamur build --docker writes one. So this recipe is the Docker output with Fly's config around it.

  1. Build with --docker once, to get the Dockerfile and .dockerignore, then let Fly describe the app. fly launch --no-deploy writes fly.toml:
sh
hamur build --docker
fly launch --no-deploy
fly volumes create data --size 1
fly secrets set HAMUR_KEY="$(hamur create-key)"
fly deploy
  1. Check fly.toml. The image listens on PORT=3000, so internal_port is 3000. A volume mounted at /app/.data keeps the default SQLite file of @hamur/db and the disk files of @hamur/blob across deploys. A volume belongs to one machine, so an app that uses it runs on one machine; for more, use a hosted database and the s3 blob driver.
toml
app = "my-app"
primary_region = "ams"

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 0

[mounts]
source = "data"
destination = "/app/.data"
  1. Set HAMUR_KEY as a secret before the first deploy: a built server without it does not start. The last line of the sample is fly deploy, which builds the image on Fly.

The .dockerignore keeps .env* out of the image, so every secret has to be a Fly secret or a variable in fly.toml.

See also: Docker, Node preset, Environment.