diff --git a/.gitignore b/.gitignore index 93594ef6..1f3ca6fc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ __pycache__/ .venv/ .vscode/ .vs/ -.env +*.env env.py *.py[cod] *.sqlite3 diff --git a/docker-compose.yml b/docker-compose.yml index 77b9c5ac..16205e70 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,18 +6,9 @@ services: volumes: - ./staticfiles/:/hackathon-app/staticfiles/ - ./data/:/hackathon-app/data/ - environment: - DEVELOPMENT: 1 - SECRET_KEY: "your_secret_key_here" - SITE_NAME: "*" - SLACK_ENABLED: "True" - SHOWCASE_SPOTLIGHT_NUMBER: 5 - SUPPORT_EMAIL: community@example.com - DBHOST: mysql - DBPORT: 3306 - DBNAME: hackathons - DBUSER: hackathon_user - DBPASS: gummyball + - ./.env:/hackathon-app/.env + environment: + - ENV_FILE=/hackathon-app/.env entrypoint: ['python3', 'manage.py', 'runserver', '0.0.0.0:8000'] ports: - "8000:8000" diff --git a/main/settings.py b/main/settings.py index a6664843..9f7f0868 100644 --- a/main/settings.py +++ b/main/settings.py @@ -1,21 +1,25 @@ import os -import dj_database_url +from django.core.management.utils import get_random_secret_key import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration -if os.path.exists(".env"): - from dotenv import load_dotenv - load_dotenv() +from dotenv import load_dotenv + +ENV_FILE = os.getenv('ENV_FILE', '.env') + +if ENV_FILE: + load_dotenv(ENV_FILE) + BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -SECRET_KEY = os.environ.get("SECRET_KEY") +SECRET_KEY = os.environ.get("SECRET_KEY", get_random_secret_key()) DEBUG = "DEVELOPMENT" in os.environ ALLOWED_HOSTS = [] -host = os.environ.get("SITE_NAME") +host = os.environ.get("SITE_NAME", '*') if host: ALLOWED_HOSTS.append(host) diff --git a/manage.py b/manage.py index 063eaccf..fada5c83 100644 --- a/manage.py +++ b/manage.py @@ -3,6 +3,13 @@ import os import sys +from dotenv import load_dotenv + +ENV_FILE = os.getenv('ENV_FILE', 'secrets.env') + +if ENV_FILE: + load_dotenv(ENV_FILE) + def main(): os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')