Setting environment variables in fly.toml and on the CLI when deploying

If I run fly deploy, it looks like the app gets the environment variables set in fly.toml. However, if I run fly deploy --env APP_VERSION=$git_hash, the app only gets the FOO environment variable. I would like to pass in the APP_VERSION variable on the command line in our CI, and the rest in the fly.toml file because they don’t change.

I’d suggest setting this as a build argument.

Set it as an environment variable in your Dockerfile (assuming you’re using one):

# ...
# default value of "unknown"
ARG APP_VERSION=unknown
ENV APP_VERSION=$APP_VERSION
# ...

Deploy using --build-arg:

flyctl deploy --build-arg APP_VERSION=$git_hash

If you’re not using a Dockerfile, then it’s trickier.

This could be a good feature to have :thinking:.

1 Like

I need the same!! I will do this! :smiley:

But it seems like a really nice feature.

Maybe have the ability to add this type of data to the release?

❯ fly releases -a [app_name] --json
[
    {
        "ID": "ID_HERE",
        "Version": 103,
        "Stable": true,
        "InProgress": false,
        "Reason": "release",
        "Description": "Deploy image",
        "Status": "succeeded",
        "DeploymentStrategy": "",
        "Metadata": { # some new attribute like this
            "GitHash": "asdasdasdasdadsadasdasd"
        },
        "User": {
            "ID": "ID_HERE",
            "Name": "Federico Otaran",
            "Email": "otaran.federico@gmail.com"
        },
        "CreatedAt": "2021-12-01T14:56:08Z"
    },
...
]
1 Like