Skip to content

Commit

Permalink
Loading env vars from .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
stefdworschak committed Aug 20, 2021
1 parent 387a458 commit b2f3538
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ __pycache__/
.venv/
.vscode/
.vs/
.env
*.env
env.py
*.py[cod]
*.sqlite3
Expand Down
15 changes: 3 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
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"
Expand Down
16 changes: 10 additions & 6 deletions main/settings.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
7 changes: 7 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit b2f3538

Please sign in to comment.