Check for and load environment variables from a `.env` file.

This commit is contained in:
Christopher Charbonneau Wells 2017-11-30 22:54:50 -05:00
parent 9d3724138e
commit 3c5aba9ae7
6 changed files with 34 additions and 13 deletions

3
.gitignore vendored
View File

@ -5,7 +5,8 @@
# database
*.sqlite3
# docker
# enviornment
.env
docker.env
# npm folder

View File

@ -78,9 +78,8 @@ redeploy the app (e.g. if there are errors or settings are changed).
A Docker deploy requires [Docker](http://docker.com/) and
[Docker Compose](https://docs.docker.com/compose/overview/) to create two
containers - one for the database and one for the application.
Baby Buddy uses a [multi-stage build](https://docs.docker.com/engine/userguide/eng-image/multistage-build/),
containers - one for the database and one for the application. Baby Buddy uses a
[multi-stage build](https://docs.docker.com/engine/userguide/eng-image/multistage-build/),
which requires Docker version 17.05 or newer.
1. Copy the `docker.env.example` to `docker.env` and set the `ALLOWED_HOSTS` and
@ -280,7 +279,18 @@ Python 3.x, nginx, uwsgi and sqlite and should be sufficient for a few users
## Configuration
Environment variables can be used to define a number of configuration settings:
Environment variables can be used to define a number of configuration settings.
Baby Buddy will check the application directory structure for an `.env` file or
take these variables from the system environment. **System environment variables
take precedence over the contents of an `.env` file.**
- [`ALLOWED_HOSTS`](#allowed_hosts)
- [`ALLOW_UPLOADS`](#allow_uploads)
- [`DEBUG`](#debug)
- [`NAP_START_MAX`](#nap_start_max)
- [`NAP_START_MIN`](#nap_start_min)
- [`SECRET_KEY`](#secret_key)
- [`TIME_ZONE`](#time_zone)
### `ALLOWED_HOSTS`

View File

@ -1,5 +1,7 @@
import os
from dotenv import load_dotenv, find_dotenv
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(
os.path.dirname(
@ -9,6 +11,10 @@ BASE_DIR = os.path.dirname(
)
)
# Environment variables
# Check for and load environment variables from a .env file.
load_dotenv(find_dotenv())
# Required settings

View File

@ -5,7 +5,6 @@ from .base import *
SECRET_KEY = 'CHANGE ME'
DEBUG = True
TIME_ZONE = 'America/New_York'
# Database

View File

@ -1,8 +1,9 @@
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "babybuddy.settings.development")
from dotenv import load_dotenv, find_dotenv
# Environment variables
# Check for and load environment variables from a .env file.
load_dotenv(find_dotenv())
application = get_wsgi_application()

View File

@ -1,10 +1,14 @@
#!/usr/bin/env python
import os
import sys
from dotenv import load_dotenv, find_dotenv
if __name__ == "__main__":
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "babybuddy.settings.development")
# Environment variables
# Check for and load environment variables from a .env file.
load_dotenv(find_dotenv())
try:
from django.core.management import execute_from_command_line
except ImportError: