First attempt at making config loadable through string config overrides in an env variable.
This commit is contained in:
parent
b95d3ec329
commit
e87ffa20cf
21 changed files with 367 additions and 397 deletions
39
app.py
39
app.py
|
@ -1,39 +1,32 @@
|
|||
import logging
|
||||
import os
|
||||
import stripe
|
||||
import json
|
||||
|
||||
from flask import Flask
|
||||
from flask.ext.principal import Principal
|
||||
from flask.ext.login import LoginManager
|
||||
from flask.ext.mail import Mail
|
||||
|
||||
from config import (ProductionConfig, DebugConfig, LocalHostedConfig,
|
||||
TestConfig, StagingConfig)
|
||||
from util import analytics
|
||||
from storage import Storage
|
||||
from config import DefaultConfig
|
||||
from data.userfiles import Userfiles
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.debug('Loading default config.')
|
||||
app.config.from_object(DefaultConfig())
|
||||
|
||||
stack = os.environ.get('STACK', '').strip().lower()
|
||||
if stack.startswith('prod'):
|
||||
logger.info('Running with production config.')
|
||||
config = ProductionConfig()
|
||||
elif stack.startswith('staging'):
|
||||
logger.info('Running with staging config on production data.')
|
||||
config = StagingConfig()
|
||||
elif stack.startswith('localhosted'):
|
||||
logger.info('Running with debug config on production data.')
|
||||
config = LocalHostedConfig()
|
||||
elif stack.startswith('test'):
|
||||
logger.info('Running with test config on ephemeral data.')
|
||||
config = TestConfig()
|
||||
else:
|
||||
logger.info('Running with debug config.')
|
||||
config = DebugConfig()
|
||||
if 'QUAY_CONFIG_FILE' in os.environ:
|
||||
config_filename = os.environ['QUAY_CONFIG_FILE']
|
||||
logger.debug('Applying config file: %s', config_filename)
|
||||
app.config.from_pyfile(config_filename)
|
||||
|
||||
app.config.from_object(config)
|
||||
overrides = json.loads(os.environ.get('QUAY_CONFIG', '{}'))
|
||||
logger.debug('Applying %s config overrides.', len(overrides))
|
||||
app.config.from_object(overrides)
|
||||
|
||||
Principal(app, use_sessions=False)
|
||||
|
||||
|
@ -43,6 +36,12 @@ login_manager.init_app(app)
|
|||
mail = Mail()
|
||||
mail.init_app(app)
|
||||
|
||||
storage = Storage()
|
||||
storage.init_app(app)
|
||||
|
||||
userfiles = Userfiles()
|
||||
userfiles.init_app(app)
|
||||
|
||||
stripe.api_key = app.config.get('STRIPE_SECRET_KEY', None)
|
||||
|
||||
mixpanel = app.config['ANALYTICS'].init_app(app)
|
||||
|
|
Reference in a new issue