Updating configuration to use environment variable BSFLASK_ENV instead of command line arguments
This commit is contained in:
parent
6faa57737e
commit
317a1282ae
3 changed files with 22 additions and 9 deletions
|
@ -25,7 +25,7 @@ pip install -r requirements.txt
|
||||||
python setup.py install
|
python setup.py install
|
||||||
python application.py
|
python application.py
|
||||||
```
|
```
|
||||||
|
You may set BSFLASK_ENV environment variable to production, development or testing.
|
||||||
### Running Tests
|
### Running Tests
|
||||||
|
|
||||||
In the root directory, run the following command:
|
In the root directory, run the following command:
|
||||||
|
|
|
@ -24,7 +24,7 @@ from src.models import db
|
||||||
from src.views.errors import error_pages
|
from src.views.errors import error_pages
|
||||||
from src.views.scoreboard import scoreboard
|
from src.views.scoreboard import scoreboard
|
||||||
from src.resources.utilities import cache
|
from src.resources.utilities import cache
|
||||||
import sys
|
import os
|
||||||
import flask_bootstrap
|
import flask_bootstrap
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
|
@ -43,8 +43,9 @@ def create_app(config_name):
|
||||||
return app
|
return app
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("Running with configuration: " + sys.argv[1])
|
configuration = os.environ['BSFLASK_ENV']
|
||||||
app = create_app(sys.argv[1])
|
print("Running with configuration: " + configuration)
|
||||||
|
app = create_app(configuration)
|
||||||
except (IndexError, KeyError):
|
except (IndexError, KeyError):
|
||||||
print("Using default configuration.")
|
print("Using default configuration.")
|
||||||
app = create_app('default')
|
app = create_app('default')
|
||||||
|
|
|
@ -17,12 +17,24 @@
|
||||||
|
|
||||||
This the configuration file for the GUnicorn server.
|
This the configuration file for the GUnicorn server.
|
||||||
"""
|
"""
|
||||||
from src.config import ProductionConfig
|
|
||||||
import multiprocessing
|
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
|
workers = multiprocessing.cpu_count() * 2 + 1
|
||||||
reload = False
|
reload = False
|
||||||
#daemon = True
|
# Allow access to name and group.
|
||||||
#user = "denis"
|
umask = 0x007
|
||||||
#group = "www-data"
|
|
||||||
|
|
Loading…
Reference in a new issue