Strapi, Docker, and Fly: Managing multiple environment variables / configuration

Hello,

I’ve setup a Strapi project and have deployed with Fly.io using a Dockerfile. Have followed guidance from Fly.io Deployment - Strapi Developer Docs

With each approach there is many ways of defining environment variables used in the application and that includes:

  • Defining a .env file at the root i.e. [NAME]=[VALUE]
  • Defining in the Dockerfile i.e. `ENV [NAME]=[VALUE]
  • Defining under [env] in fly.toml

My question is how do you manage for multiple environments i.e. common, development, qa / test, production? The environment variables should be secret and should not be committed to VCS.

There is the following information on how to use environment specific Docker or toml files: Monorepo and Multi-Environment Deployments · Fly Docs

1 Like

From my personal apps that need production, staging and local environments I’ve used a simple approach:

  1. Add .env to your .dockerignore so your local env doesn’t go anywhere
  2. Create a production app and commit the fly.toml. Now you can fly deploy to production.
  3. Create another app and save the toml file with other name like fly.staging.toml. Now you can fly deploy -c fly.staging.toml to staging.
  4. Set secrets as fly secrets set SOME_ENV=supersecret for prod and fly secrets set -c fly.staging.toml SOME_ENV=supersecret for staging.
  5. Use [env] in your toml only for things that are ok to be public like NODE_ENV or TZ.

Hopefully this will be helpful :slight_smile:

1 Like