Fix DB issue

This commit is contained in:
Stephan Porada 2020-07-28 16:31:14 +02:00
parent d1e82baa1c
commit 7cda95b9b5
5 changed files with 24 additions and 38 deletions

9
.env.tpl Normal file
View File

@ -0,0 +1,9 @@
### These are examples do not use in production! ###
### Django settings ###
SECRET_KEY=secretkey
### Postgress DB ###
POSTGRES_PASSWORD=password
POSTGRES_USER=bundesdata_app_user
POSTGRES_DB_NAME=bundesdata_db

3
.gitignore vendored
View File

@ -15,5 +15,4 @@ static_volume
!**/.gitkeep
**/secrets.json
secrets.json
.env

View File

@ -10,30 +10,11 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import json
import os
from django.core.exceptions import ImproperlyConfigured
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Loads json files with secrets. Follow this example to create your own secrets
# file with SECRET_KEY and other information.
# Example https://stackoverflow.com/a/42077576
with open(os.path.join(BASE_DIR, 'secrets.json')) as secrets_file:
secrets = json.load(secrets_file)
def get_secret(setting, secrets=secrets):
"""Get secret setting or fail with ImproperlyConfigured"""
try:
return secrets[setting]
except KeyError:
raise ImproperlyConfigured("Set the {} setting".format(setting))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
@ -41,7 +22,7 @@ def get_secret(setting, secrets=secrets):
# This is just some random genearted key to test the App. If you want to set up
# your own running public version of this app replace this key with an new one
# that you will keep secret!
SECRET_KEY = get_secret("SECRET_KEY")
SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
@ -106,12 +87,13 @@ WSGI_APPLICATION = 'bundesdata_app.wsgi.application'
# Change NAME, USER and PASSWORD details before deploying your own public
# version of this app. Or use your onw secrets.json file. Explanation found can
# be foudn here: https://stackoverflow.com/a/42077576
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': get_secret("DB_NAME"),
'USER': get_secret("DB_USER"),
'PASSWORD': get_secret("DB_PASSWORD"),
'NAME': os.environ.get("POSTGRES_DB_NAME"),
'USER': os.environ.get("POSTGRES_USER"),
'PASSWORD': os.environ.get("POSTGRES_PASSWORD"),
'HOST': 'db',
'PORT': '5432',
}

View File

@ -1,7 +0,0 @@
{
"_comment": "DO not use these values in production! This is an example for development!",
"SECRET_KEY": "=7n(1!he%todz-)jo))$upf0(vor9v9ke5rn&fli%6l562!_=0",
"DB_PASSWORD": "v3ry53cr3t",
"DB_USER": "bundesdata_app_user",
"DB_NAME": "bundesdata_db"
}

View File

@ -9,10 +9,18 @@ services:
- ./static_volume:/usr/src/app/staticfiles
expose:
- 8000
env_file: .env
depends_on:
- db
command: bash -c /wait-for-it/wait-for-it.sh db:5432 --strict --timeout=0
db:
env_file: .env
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_DB_NAME: ${POSTGRES_DB_NAME}
expose:
- 5432
image: postgres:11.2
volumes:
- ./postgres_data:/var/lib/postgresql/data/
@ -23,9 +31,4 @@ services:
ports:
- 8000:80
depends_on:
- web
volumes:
postgres_data:
static_volume:
input_volume:
- web