FlyCTL Deploy Cant Find Environment Variables

Project uses:

  • Django
  • Poetry
  • PostgreSQL

I’ve added all my environment variables via flyctl secrets set xx=xxx and when I check if the environment variables were successfully saved via the command flyctl config env I get the following output: (xxx’s replace the digest value)

Secrets
NAME                DIGEST           DATE    
   
DATABASE_URL        xxx              21h52m ago
DJANGO_SECRET_KEY   xxx              17m42s ago
EMAIL_BACKEND       xxx              16m59s ago
EMAIL_HOST          xxx              2h1m ago
EMAIL_HOST_PASSWORD xxx              2h1m ago
EMAIL_HOST_USER     xxx              2h1m ago
EMAIL_PORT          xxx              2h0m ago
EMAIL_USE_TLS       xxx              2h0m ago
TWILIO_ACCOUNT_SID  xxx              2h0m ago
TWILIO_AUTH_TOKEN   xxx              2h0m ago

These secrets are also visible on the fly.io dashboard for the project. The issue is that when I attempt to deploy the deploy fails due to the following error:

***long traceback up here***
ImproperlyConfigured(error_msg) from exc   
#10 0.814 django.core.exceptions.ImproperlyConfigured: Set the EMAIL_BACKEND environment variable
------
Error failed to fetch an image or build from 
source: error building: executor failed running [/bin/sh -c poetry run python manage.py collectstatic --noinput]: exit code: 1

It would appear that despite the environment variables being set, for some reason they are not being processed during the build.

Could anyone enlighten me on how to ensure that the build gets these environment variables and passes them into the application appropriately?

Builds can’t actually see secrets. They’re only available post deploy.

If Django doesn’t need the real values, but just needs them set during builds, you can try passing in stub values like this:

fly deploy -e EMAIL_BACKEND=ASDF

This may get you unstuck! I’d be surprised if your app really needs email credentials at build time.