From 317a1282aebda8f3a5276bfe25e3b1fed4f522d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Fri, 21 Apr 2017 18:49:53 +0300 Subject: [PATCH] Updating configuration to use environment variable BSFLASK_ENV instead of command line arguments --- README.md | 2 +- src/application.py | 7 ++++--- src/gconfig.py | 22 +++++++++++++++++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e1e9da9..9fa7375 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/application.py b/src/application.py index 1b2a3bf..68cc8bf 100644 --- a/src/application.py +++ b/src/application.py @@ -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') diff --git a/src/gconfig.py b/src/gconfig.py index 4ba4946..b5012cd 100644 --- a/src/gconfig.py +++ b/src/gconfig.py @@ -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" \ No newline at end of file +# Allow access to name and group. +umask = 0x007