I have this working. All you need is the share the same consul key. In my case my case I used my FrontEnd app as the shared key. But I have that app setup to not be promoted. Ever. It is a read only instance.
The Backend App, is setup to be the primary and can be promoted.
FrontEnd App - litefs.yml
lease:
type: "consul"
advertise-url: "http://${FLY_ALLOC_ID}.vm.${FLY_APP_NAME}.internal:20202"
candidate: false
promote: false
consul:
url: "${FLY_CONSUL_URL}"
key: "litefs/${FLY_APP_NAME}"
Backend App - fly.toml
I set this to match the FLY_APP_NAME
from the first app, what I consider my only a reader app.
[env]
SHARED_APP_NAME = "PRIMARY_APP_NAME"
Backend App - litefs.yml
lease:
type: "consul"
advertise-url: "http://${FLY_ALLOC_ID}.vm.${FLY_APP_NAME}.internal:20202"
candidate: ${FLY_REGION == PRIMARY_REGION}
promote: true
consul:
url: "${FLY_CONSUL_URL}"
key: "litefs/${SHARED_APP_NAME}"
Thank you to @deano-fury for reminding me.
Add the secret called FLY_CONSUL_URL
, that has the URL from app you reference in SHARED_APP_NAME
.
If you don’t have this handy, you can use -
Use the fly ssh console
cli command in your primary app to open a console to fly for one of the machines that is deployed. You can then echo $FLY_CONSUL_URL
to get that secret.
You can then use fly secrets set FLY_CONSUL_URL=<URL VALUE>
cli command in your secondary apps to setup that in your other applications.
You will need to redeploy, as it will have staged this secret. So deploying will make it active.