Use production config in production and dev config in dev.
This commit is contained in:
parent
25c4054c19
commit
67147240b6
4 changed files with 28 additions and 8 deletions
|
@ -36,3 +36,5 @@ container_commands:
|
|||
option_settings:
|
||||
"aws:elasticbeanstalk:container:python:staticfiles":
|
||||
"/static": "static/"
|
||||
"aws:elasticbeanstalk:application:environment":
|
||||
"STACK": "prod"
|
||||
|
|
8
app.py
8
app.py
|
@ -1,13 +1,17 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
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
|
||||
from config import ProductionConfig, DebugConfig
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(ProductionConfig())
|
||||
|
||||
is_prod = os.environ.get('STACK', '').strip().lower().startswith('prod')
|
||||
config_object = ProductionConfig() if is_prod else DebugConfig()
|
||||
app.config.from_object(config_object)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -11,9 +11,7 @@ import endpoints.registry
|
|||
# Remove this for prod config
|
||||
application.debug = True
|
||||
|
||||
if __name__ == '__main__':
|
||||
FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - ' + \
|
||||
'%(funcName)s - %(message)s'
|
||||
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
|
||||
logging.basicConfig(**application.config['LOGGING_CONFIG'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
application.run(port=5001, debug=True)
|
||||
|
|
18
config.py
18
config.py
|
@ -1,5 +1,12 @@
|
|||
import logging
|
||||
|
||||
from peewee import MySQLDatabase, SqliteDatabase
|
||||
|
||||
|
||||
LOG_FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - ' + \
|
||||
'%(funcName)s - %(message)s'
|
||||
|
||||
|
||||
class FlaskConfig(object):
|
||||
SECRET_KEY = '1cb18882-6d12-440d-a4cc-b7430fb5f884'
|
||||
|
||||
|
@ -29,7 +36,7 @@ class RDSMySQL(object):
|
|||
'host': 'fluxmonkeylogin.cb0vumcygprn.us-east-1.rds.amazonaws.com',
|
||||
'user': 'fluxmonkey',
|
||||
'passwd': '8eifM#uoZ85xqC^',
|
||||
'threadlocals': True
|
||||
'threadlocals': True,
|
||||
}
|
||||
DB_DRIVER = MySQLDatabase
|
||||
|
||||
|
@ -48,7 +55,16 @@ class LocalStorage(object):
|
|||
|
||||
class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB):
|
||||
REGISTRY_SERVER = 'localhost:5000'
|
||||
LOGGING_CONFIG = {
|
||||
'level': logging.DEBUG,
|
||||
'format': LOG_FORMAT
|
||||
}
|
||||
|
||||
|
||||
class ProductionConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL):
|
||||
REGISTRY_SERVER = 'quay.io'
|
||||
LOGGING_CONFIG = {
|
||||
'filename': '/opt/python/log/application.log',
|
||||
'level': logging.DEBUG,
|
||||
'format': LOG_FORMAT,
|
||||
}
|
||||
|
|
Reference in a new issue