I have an app running. The App has two machines running it. At the moment when the machines are running, I check the id and manually set one of the machines env variable. How do I do this when deploying so I don’t have to manually set the env variable every single time. Just to be clear I only want the variable to be only in one of the machines, it does not matter which one).
the command I’m using is fly machines update --env
. I have to run this command after every fly deploy.
Any help is appreciated.
Hi @Haziq
Check out Fly Launch configuration (fly.toml) · Fly Docs The env variables section.
Env variable names are strictly case-sensitive and cannot begin with FLY_
(as this could clash with the runtime environment). Env values can only be strings.
Secrets take precedence over env variables with the same name.
I hope that helps,
Sergio Turpín
Hi, I did look at it, but I don’t see how I would differentiate between two machines with this. Any changes to the toml file would affect both machines at the same time. I want to set the variable on only one of the machines not both, on launch
Hi @Haziq
I believe there is currently no way to set different env vars when you have multiple instances of the same app. You’d need to run two apps in differents machines.
We are waiting in case a colleague or employee can provide more information about it
Cheers,
Sergio Turpín
What does CMD
look like in your Dockerfile?
Write a small script (in bash or your favorite language) that queries the environment and sets variables, then runs the CMD that is currently specified in your Dockerfile, and then change the CMD to run your script.
If you don’t have an ENTRYPOINT, you can do the same thing by adding an entrypoint instead of replacing the CMD, and have the script complete with (for bash):
exec "${@}"
If you run fly ssh console
, and from there env | grep FLY
you will see a number of interesting variables that you can use to determine how to set other variables. FLY_MACHINE_ID
, for example is unique to a machine.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.