chore: pick backend settings from env vars
Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
parent
87fe9a7d18
commit
0b53c00be8
3 changed files with 38 additions and 23 deletions
|
|
@ -10,6 +10,7 @@ For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/3.1/ref/settings/
|
https://docs.djangoproject.com/en/3.1/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
|
|
@ -21,12 +22,13 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
# TODO: remove this key
|
# TODO: remove this key
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'eo$1gb^g#gx25$b$(9hp#i^av^t0e8ge#kjcr$g(=yimc#j1-l'
|
# SECRET_KEY = 'eo$1gb^g#gx25$b$(9hp#i^av^t0e8ge#kjcr$g(=yimc#j1-l'
|
||||||
|
SECRET_KEY = os.environ.get('SECRET_KEY')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = bool(os.environ.get('DEBUG'))
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split(',')
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
@ -87,23 +89,22 @@ WSGI_APPLICATION = 'backend.wsgi.application'
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.postgresql',
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
'NAME': 'bullish',
|
'NAME': os.environ.get("POSTGRES_DB"),
|
||||||
'USER': 'bullish',
|
'USER': os.environ.get("POSTGRES_USER"),
|
||||||
'PASSWORD': 'password',
|
'PASSWORD': os.environ.get("POSTGRES_PASSWORD"),
|
||||||
'HOST': 'db',
|
'HOST': os.environ.get("POSTGRES_SERVER"),
|
||||||
'PORT': '5432',
|
'PORT': os.environ.get("POSTGRES_PORT"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'django_redis.cache.RedisCache',
|
'BACKEND': 'django_redis.cache.RedisCache',
|
||||||
'LOCATION': 'redis://redis:6379/1',
|
'LOCATION': f'redis://{os.environ.get("REDIS_HOST")}:{os.environ.get("REDIS_PORT")}/{os.environ.get("REDIS_CACHE_DB")}',
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
||||||
"REDIS_CLIENT_CLASS": "redis.client.StrictRedis",
|
"REDIS_CLIENT_CLASS": "redis.client.StrictRedis",
|
||||||
"REDIS_CLIENT_KWARGS": {"decode_responses": True},
|
"REDIS_CLIENT_KWARGS": {"decode_responses": True},
|
||||||
# Custom serializer
|
|
||||||
"SERIALIZER": "app.redis.JSONSerializer",
|
"SERIALIZER": "app.redis.JSONSerializer",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -142,16 +143,13 @@ USE_L10N = True
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
# TODO: fix hardcoded cross allowed origins
|
# TODO: fix hardcoded cross allowed origins
|
||||||
CORS_ALLOWED_ORIGINS = [
|
CORS_ALLOWED_ORIGINS = os.environ.get('CORS_ALLOWED_ORIGINS').split(',')
|
||||||
"http://localhost:8080",
|
|
||||||
"http://127.0.0.1:8080",
|
|
||||||
]
|
|
||||||
|
|
||||||
RQ_QUEUES = {
|
RQ_QUEUES = {
|
||||||
'default': {
|
'default': {
|
||||||
'HOST': 'redis',
|
'HOST': os.environ.get("REDIS_HOST"),
|
||||||
'PORT': 6379,
|
'PORT': os.environ.get("REDIS_PORT"),
|
||||||
'DB': 0,
|
'DB': os.environ.get("REDIS_QUEUE_DB"),
|
||||||
'DEFAULT_TIMEOUT': 360,
|
'DEFAULT_TIMEOUT': 360,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
dev.env
Normal file
15
dev.env
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
SECRET_KEY=sample
|
||||||
|
DEBUG=true
|
||||||
|
ALLOWED_HOSTS=example.com,example.xyz,*
|
||||||
|
CORS_ALLOWED_ORIGINS=http://localhost:8080,http://127.0.0.1:8080
|
||||||
|
REDIS_HOST=redis
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_CACHE_DB=1
|
||||||
|
REDIS_QUEUE_DB=0
|
||||||
|
PGDATA=/var/lib/postgresql/data/pgdata
|
||||||
|
POSTGRES_SERVER=db
|
||||||
|
POSTGRES_USER=bullish
|
||||||
|
POSTGRES_PASSWORD=password
|
||||||
|
POSTGRES_DB=bullish
|
||||||
|
POSTGRES_PORT=5432
|
||||||
|
|
||||||
|
|
@ -9,6 +9,8 @@ services:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend:/code
|
- ./backend:/code
|
||||||
|
env_file:
|
||||||
|
- dev.env
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
- rqworker
|
- rqworker
|
||||||
|
|
@ -35,6 +37,8 @@ services:
|
||||||
image: codingcoffee/bullish-backend
|
image: codingcoffee/bullish-backend
|
||||||
build:
|
build:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
|
env_file:
|
||||||
|
- dev.env
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend:/code
|
- ./backend:/code
|
||||||
command: python manage.py rqworker default
|
command: python manage.py rqworker default
|
||||||
|
|
@ -45,6 +49,8 @@ services:
|
||||||
image: codingcoffee/bullish-backend
|
image: codingcoffee/bullish-backend
|
||||||
build:
|
build:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
|
env_file:
|
||||||
|
- dev.env
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend:/code
|
- ./backend:/code
|
||||||
command: python manage.py rqscheduler
|
command: python manage.py rqscheduler
|
||||||
|
|
@ -57,12 +63,8 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- bullish-db-data:/var/lib/postgresql/data/pgdata
|
- bullish-db-data:/var/lib/postgresql/data/pgdata
|
||||||
# TODO: remove pass
|
# TODO: remove pass
|
||||||
environment:
|
env_file:
|
||||||
- PGDATA=/var/lib/postgresql/data/pgdata
|
- dev.env
|
||||||
- POSTGRES_SERVER=db
|
|
||||||
- POSTGRES_USER=bullish
|
|
||||||
- POSTGRES_PASSWORD=password
|
|
||||||
- POSTGRES_DB=bullish
|
|
||||||
# ports:
|
# ports:
|
||||||
# - 5432:5432
|
# - 5432:5432
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue