View Source FLAME.FlyBackend (flame v0.5.2)
A FLAME.Backend
using Fly.io machines.
The only required configuration is telling FLAME to use the
FLAME.FlyBackend
by default and the :token
which is your Fly.io API
token. These can be set via application configuration in your config/runtime.exs
withing a :prod
block:
if config_env() == :prod do
config :flame, :backend, FLAME.FlyBackend
config :flame, FLAME.FlyBackend, token: System.fetch_env!("FLY_API_TOKEN")
...
end
To set your FLY_API_TOKEN
secret, you can run the following commands locally:
$ fly secrets set FLY_API_TOKEN="$(fly auth token)"
The following backend options are supported, and mirror the Fly.io machines create API:
:cpu_kind
- The size of the runner CPU. Defaults to"performance"
.:cpus
- The number of runner CPUs. Defaults toSystem.schedulers_online()
for the number of cores of the running parent app.:memory_mb
- The memory of the runner. Must be a 1024 multiple. Defaults to4096
.:gpu_kind
- The type of GPU reservation to make.:gpus
- The number of runner GPUs. Defaults to1
if:gpu_kind
is set.:boot_timeout
- The boot timeout. Defaults to30_000
.:app
– The name of the otp app. Defaults toSystem.get_env("FLY_APP_NAME")
,:image
– The URL of the docker image to pass to the machines create endpoint. Defaults toSystem.get_env("FLY_IMAGE_REF")
which is the image of your running app.:token
– The Fly API token. Defaults toSystem.get_env("FLY_API_TOKEN")
.:host
– The host of the Fly API. Defaults to"https://api.machines.dev"
.:init
– The init object to pass to the machines create endpoint. Defaults to%{}
. Possible values include::cmd
– list of strings for the command:entrypoint
– list strings for the entrypoint command:exec
– list of strings for the exec command:kernel_args
- list of strings:swap_size_mb
– integer value in megabytes for the swap size:tty
– boolean
:services
- The optional services to run on the machine. Defaults to[]
.:metadata
- The optional map of metadata to set for the machine. Defaults to%{}
.
Environment Variables
The FLAME Fly machines do not inherit the environment variables of the parent. You must explicit provide the environment that you would like to forward to the machine. For example, if your FLAME's are starting your Ecto repos, you can copy the env from the parent:
config :flame, FLAME.FlyBackend,
token: System.fetch_env!("FLY_API_TOKEN"),
env: %{
"DATABASE_URL" => System.fetch_env!("DATABASE_URL"),
"POOL_SIZE" => "1"
}
Or pass the env to each pool:
{FLAME.Pool,
name: MyRunner,
backend: {FLAME.FlyBackend, env: %{"DATABASE_URL" => System.fetch_env!("DATABASE_URL")}}
}