I just deployed a website to production and a bizarre thing happened.
In my development machine, I had a .env file with environment variables that were being loaded into my python-flask program using python's load_dotenv module.
Naturally the .env file is in my .gitignore and therefore wasn't uploaded to github and, as such, was not pulled to my server.
As can be seen in the config.py of my flask app, there is absolutelly no way for the app to run correctly without any environment vars set:
import os
import datetime
from dotenv import load_dotenv
load_dotenv()
from celery.schedules import crontab
# Find the absolute file path to the top level project directory
basedir = os.path.abspath(os.path.dirname(__file__))
class Config:
"""
Base configuration class. Contains default configuration settings + configuration settings applicable to all environments.
"""
# Default settings
FLASK_ENV = 'development'
DEBUG = False
TESTING = False
WTF_CSRF_ENABLED = True
BABEL_DEFAULT_LOCALE = 'en'
LANGUAGES = ['pt-BR', 'en']
# Settings applicable to all environments
SECRET_KEY = os.getenv('SECRET_KEY', default='A very terrible secret key.')
MAIL_SERVER = 'smtp.XXX.com'
MAIL_PORT = 465
MAIL_USE_SSL = True
MAIL_USERNAME = 'noreply@app.com'
MAIL_PASSWORD = 'XXX'
MAIL_DEFAULT_SENDER = 'noreply@app.com'
MAIL_SUPPRESS_SEND = False
SQLALCHEMY_TRACK_MODIFICATIONS = False
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL')
RESULT_BACKEND = os.getenv('RESULT_BACKEND')
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI')
MONGODB_SETTINGS = {"host" : os.getenv('MONGODB_SETTINGS'), "connect": False}
class TestingConfig(Config):
TESTING = True
WTF_CSRF_ENABLED = False
MAIL_SUPPRESS_SEND = True
SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI')
MONGODB_SETTINGS = {"host" : os.getenv('MONGODB_SETTINGS'), "connect": False}
class ProductionConfig(Config):
FLASK_ENV = 'production'
SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI')
MONGODB_SETTINGS = {"host" : os.getenv('MONGODB_SETTINGS'), "connect": False}
Yet, once I set up everything in the server, the web app is running perfectly with development configs and saving all data to a cloud db, whose connection string was an environment variable.
I already checked all the files in the server and there is absolutely no .env file anywhere...
Does anyone have any idea how this might happen?
PS. I opted not to print all folder structure information to avoid making this post too long, if anyone believes that to be important I'll be happy to include the information.