Updating configuration to use environment variable BSFLASK_ENV instead of command line arguments

This commit is contained in:
Denis-Cosmin Nutiu 2017-04-21 18:49:53 +03:00
parent 6faa57737e
commit 317a1282ae
3 changed files with 22 additions and 9 deletions

View file

@ -25,7 +25,7 @@ pip install -r requirements.txt
python setup.py install
python application.py
```
You may set BSFLASK_ENV environment variable to production, development or testing.
### Running Tests
In the root directory, run the following command:

View file

@ -24,7 +24,7 @@ from src.models import db
from src.views.errors import error_pages
from src.views.scoreboard import scoreboard
from src.resources.utilities import cache
import sys
import os
import flask_bootstrap
import flask
@ -43,8 +43,9 @@ def create_app(config_name):
return app
try:
print("Running with configuration: " + sys.argv[1])
app = create_app(sys.argv[1])
configuration = os.environ['BSFLASK_ENV']
print("Running with configuration: " + configuration)
app = create_app(configuration)
except (IndexError, KeyError):
print("Using default configuration.")
app = create_app('default')

View file

@ -17,12 +17,24 @@
This the configuration file for the GUnicorn server.
"""
from src.config import ProductionConfig
import multiprocessing
import os
# If BSFLASK_ENV is development or environment then gunicorn will bind to Config.APP_IP and Config.APP_PORT
# else it will create a unix socket benchmark_scoreboard.sock that may be used by Nginx
configuration = None
try:
configuration = os.environ['BSFLASK_ENV']
except KeyError:
print("Environment key BSFLASK_ENV not defined.")
if configuration is not None and configuration != 'production':
from src.config import Config
bind = "{ip}:{port}".format(ip=Config.BIND_IP, port=Config.BIND_PORT)
else:
bind = "unix:benchmark_scoreboard.sock"
bind = "{ip}:{port}".format(ip=ProductionConfig.BIND_IP, port=ProductionConfig.BIND_PORT)
workers = multiprocessing.cpu_count() * 2 + 1
reload = False
#daemon = True
#user = "denis"
#group = "www-data"
# Allow access to name and group.
umask = 0x007