diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 7272d56..79f9759 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -10,6 +10,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.1/ref/settings/ """ +import os from pathlib import Path # 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 # 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! -DEBUG = True +DEBUG = bool(os.environ.get('DEBUG')) -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split(',') # Application definition @@ -87,23 +89,22 @@ WSGI_APPLICATION = 'backend.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'bullish', - 'USER': 'bullish', - 'PASSWORD': 'password', - 'HOST': 'db', - 'PORT': '5432', + 'NAME': os.environ.get("POSTGRES_DB"), + 'USER': os.environ.get("POSTGRES_USER"), + 'PASSWORD': os.environ.get("POSTGRES_PASSWORD"), + 'HOST': os.environ.get("POSTGRES_SERVER"), + 'PORT': os.environ.get("POSTGRES_PORT"), } } CACHES = { 'default': { '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': { 'CLIENT_CLASS': 'django_redis.client.DefaultClient', "REDIS_CLIENT_CLASS": "redis.client.StrictRedis", "REDIS_CLIENT_KWARGS": {"decode_responses": True}, - # Custom serializer "SERIALIZER": "app.redis.JSONSerializer", }, }, @@ -142,16 +143,13 @@ USE_L10N = True USE_TZ = True # TODO: fix hardcoded cross allowed origins -CORS_ALLOWED_ORIGINS = [ - "http://localhost:8080", - "http://127.0.0.1:8080", -] +CORS_ALLOWED_ORIGINS = os.environ.get('CORS_ALLOWED_ORIGINS').split(',') RQ_QUEUES = { 'default': { - 'HOST': 'redis', - 'PORT': 6379, - 'DB': 0, + 'HOST': os.environ.get("REDIS_HOST"), + 'PORT': os.environ.get("REDIS_PORT"), + 'DB': os.environ.get("REDIS_QUEUE_DB"), 'DEFAULT_TIMEOUT': 360, }, } diff --git a/dev.env b/dev.env new file mode 100644 index 0000000..6e247f7 --- /dev/null +++ b/dev.env @@ -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 + diff --git a/docker-compose.yml b/docker-compose.yml index b2c8f5a..ff7aaa5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,8 @@ services: context: ./backend volumes: - ./backend:/code + env_file: + - dev.env depends_on: - db - rqworker @@ -35,6 +37,8 @@ services: image: codingcoffee/bullish-backend build: context: ./backend + env_file: + - dev.env volumes: - ./backend:/code command: python manage.py rqworker default @@ -45,6 +49,8 @@ services: image: codingcoffee/bullish-backend build: context: ./backend + env_file: + - dev.env volumes: - ./backend:/code command: python manage.py rqscheduler @@ -57,12 +63,8 @@ services: volumes: - bullish-db-data:/var/lib/postgresql/data/pgdata # TODO: remove pass - environment: - - PGDATA=/var/lib/postgresql/data/pgdata - - POSTGRES_SERVER=db - - POSTGRES_USER=bullish - - POSTGRES_PASSWORD=password - - POSTGRES_DB=bullish + env_file: + - dev.env # ports: # - 5432:5432