force env variables

This commit is contained in:
crflynn
2018-04-22 19:27:23 -04:00
parent 5161e5cd09
commit 3f772e32c0
3 changed files with 5 additions and 21 deletions

View File

@@ -11,7 +11,7 @@ from pypistats.settings import configs
# change this for migrations
env = os.environ.get("ENV", "prod")
env = os.environ.get("ENV", "dev")
app = create_app(configs[env])
celery = create_celery(app)

View File

@@ -1,21 +1,9 @@
"""Application configuration."""
import json
import os
from celery.schedules import crontab
# For local use.
def load_env_vars(env="dev"):
"""Load environment variables."""
local_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"secret",
f"env_vars_{env}.json")
for key, value in json.load(open(local_path, "r")).items():
os.environ[key] = value
def get_db_uri(env):
"""Get the database URI."""
return \
@@ -52,8 +40,6 @@ class ProdConfig(Config):
DEBUG = False
ENV = "prod"
if os.environ.get("ENV", None) is None:
load_env_vars(ENV)
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
@@ -62,8 +48,6 @@ class DevConfig(Config):
DEBUG = True
ENV = "dev"
if os.environ.get("ENV", None) is None:
load_env_vars(ENV)
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
@@ -72,8 +56,6 @@ class TestConfig(Config):
DEBUG = True
ENV = "dev"
if os.environ.get("ENV", None) is None:
load_env_vars(ENV)
SQLALCHEMY_DATABASE_URI = get_db_uri(ENV)
TESTING = True
WTF_CSRF_ENABLED = False # Allows form testing

6
run.sh
View File

@@ -1,3 +1,5 @@
export FLASK_APP=pypistats/run.py
export FLASK_DEBUG=1
export ENV=prod
set -o allexport
source pypistats/secret/$ENV.env
set +o allexport
flask run --host=0.0.0.0