Use production config in production and dev config in dev.

This commit is contained in:
yackob03 2013-09-30 23:54:12 -04:00
parent 25c4054c19
commit 67147240b6
4 changed files with 28 additions and 8 deletions

View file

@ -35,4 +35,6 @@ container_commands:
option_settings:
"aws:elasticbeanstalk:container:python:staticfiles":
"/static": "static/"
"/static": "static/"
"aws:elasticbeanstalk:application:environment":
"STACK": "prod"

8
app.py
View file

@ -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__)

View file

@ -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)

View file

@ -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,
}