├── media ├── .gitkeep └── banner.jpg ├── backend ├── assignments │ ├── __init__.py │ ├── migrations │ │ ├── __init__.py │ │ └── 0001_initial.py │ ├── admin.py │ ├── tests.py │ ├── apps.py │ ├── urls.py │ ├── serializers.py │ ├── tasks.py │ ├── models.py │ └── views.py ├── backend │ ├── __init__.py │ ├── celery.py │ ├── asgi.py │ ├── wsgi.py │ ├── urls.py │ └── settings.py └── manage.py ├── requirements.txt ├── docker ├── backend │ ├── worker-entrypoint.sh │ ├── Dockerfile │ └── server-entrypoint.sh └── nginx │ └── default.conf ├── README.md ├── LICENSE ├── docker-compose.yml └── .gitignore /media/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /backend/assignments/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/assignments/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/assignments/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /backend/assignments/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /backend/backend/__init__.py: -------------------------------------------------------------------------------- 1 | from .celery import app as celery_app 2 | 3 | __all__ = ("celery_app",) 4 | -------------------------------------------------------------------------------- /media/banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saasitive/docker-compose-django-celery-redis-postgres/HEAD/media/banner.jpg -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | django 2 | 3 | djangorestframework 4 | markdown 5 | django-filter 6 | 7 | celery[redis] 8 | 9 | psycopg2-binary 10 | -------------------------------------------------------------------------------- /backend/assignments/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AssignmentsConfig(AppConfig): 5 | default_auto_field = "django.db.models.BigAutoField" 6 | name = "assignments" 7 | -------------------------------------------------------------------------------- /docker/backend/worker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | until cd /app/backend 4 | do 5 | echo "Waiting for server volume..." 6 | done 7 | 8 | # run a worker :) 9 | celery -A backend worker --loglevel=info --concurrency 1 -E -------------------------------------------------------------------------------- /backend/assignments/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import re_path 2 | from rest_framework.routers import DefaultRouter 3 | 4 | from assignments.views import AssignmentViewSet 5 | 6 | router = DefaultRouter() 7 | router.register(r"assignments", AssignmentViewSet, basename="assignments") 8 | assignments_urlpatterns = router.urls 9 | -------------------------------------------------------------------------------- /backend/assignments/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | 3 | from assignments.models import Assignment 4 | 5 | 6 | class AssignmentSerializer(serializers.ModelSerializer): 7 | class Meta: 8 | model = Assignment 9 | read_only_fields = ("id", "sum") 10 | fields = ("id", "first_term", "second_term", "sum") 11 | -------------------------------------------------------------------------------- /backend/assignments/tasks.py: -------------------------------------------------------------------------------- 1 | from celery import shared_task 2 | 3 | from assignments.models import Assignment 4 | 5 | 6 | @shared_task() 7 | def task_execute(job_params): 8 | 9 | assignment = Assignment.objects.get(pk=job_params["db_id"]) 10 | 11 | assignment.sum = assignment.first_term + assignment.second_term 12 | 13 | assignment.save() 14 | -------------------------------------------------------------------------------- /backend/backend/celery.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from celery import Celery 4 | from django.conf import settings 5 | 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") 7 | 8 | # celery -A backend worker --loglevel=info -P gevent --concurrency 1 -E 9 | app = Celery("backend") 10 | 11 | app.config_from_object("django.conf:settings", namespace="CELERY") 12 | 13 | app.autodiscover_tasks() 14 | -------------------------------------------------------------------------------- /backend/backend/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for backend project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /backend/backend/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for backend project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /docker/backend/Dockerfile: -------------------------------------------------------------------------------- 1 | # pull official base image 2 | FROM python:3.8.15-alpine 3 | 4 | RUN apk update && apk add python3-dev gcc libc-dev 5 | 6 | WORKDIR /app 7 | 8 | RUN pip install --upgrade pip 9 | RUN pip install gunicorn 10 | ADD ./requirements.txt /app/ 11 | RUN pip install -r requirements.txt 12 | 13 | ADD ./backend /app/backend 14 | ADD ./docker /app/docker 15 | 16 | RUN chmod +x /app/docker/backend/server-entrypoint.sh 17 | RUN chmod +x /app/docker/backend/worker-entrypoint.sh 18 | -------------------------------------------------------------------------------- /docker/backend/server-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | until cd /app/backend 4 | do 5 | echo "Waiting for server volume..." 6 | done 7 | 8 | 9 | until python manage.py migrate 10 | do 11 | echo "Waiting for db to be ready..." 12 | sleep 2 13 | done 14 | 15 | 16 | python manage.py collectstatic --noinput 17 | 18 | # python manage.py createsuperuser --noinput 19 | 20 | gunicorn backend.wsgi --bind 0.0.0.0:8000 --workers 4 --threads 4 21 | 22 | # for debug 23 | #python manage.py runserver 0.0.0.0:8000 -------------------------------------------------------------------------------- /backend/assignments/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Assignment(models.Model): 5 | 6 | first_term = models.DecimalField( 7 | max_digits=5, decimal_places=2, null=False, blank=False 8 | ) 9 | 10 | second_term = models.DecimalField( 11 | max_digits=5, decimal_places=2, null=False, blank=False 12 | ) 13 | 14 | # sum should be equal to first_term + second_term 15 | # its value will be computed in Celery 16 | sum = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True) 17 | -------------------------------------------------------------------------------- /docker/nginx/default.conf: -------------------------------------------------------------------------------- 1 | 2 | server { 3 | listen 80; 4 | server_name _; 5 | server_tokens off; 6 | 7 | client_max_body_size 20M; 8 | 9 | location / { 10 | try_files $uri @proxy_api; 11 | } 12 | 13 | location /admin { 14 | try_files $uri @proxy_api; 15 | } 16 | 17 | location @proxy_api { 18 | proxy_set_header Host $http_host; 19 | proxy_redirect off; 20 | proxy_pass http://server:8000; 21 | } 22 | 23 | location /django_static/ { 24 | autoindex on; 25 | alias /app/backend/django_static/; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://raw.githubusercontent.com/saasitive/docker-compose-django-celery-redis-postgres/main/media/banner.jpg) 2 | 3 | # Docker Compose for Django, Celery, Redis, and Postgres 4 | 5 | Article with implemenation details: [Docker compose with Django 4, Celery, Redis and Postgres](https://saasitive.com/tutorial/django-celery-redis-postgres-docker-compose/) 6 | 7 | #### Build docker 8 | 9 | ``` 10 | sudo docker-compose build 11 | ``` 12 | 13 | #### Start docker 14 | 15 | ``` 16 | sudo docker-compose up 17 | ``` 18 | 19 | #### Build and run in detached mode 20 | 21 | ``` 22 | sudo docker-compose up --build -d 23 | ``` 24 | 25 | ### Stop docker-compose 26 | 27 | ``` 28 | sudo docker-compose down 29 | ``` 30 | -------------------------------------------------------------------------------- /backend/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == "__main__": 22 | main() 23 | -------------------------------------------------------------------------------- /backend/backend/urls.py: -------------------------------------------------------------------------------- 1 | """backend URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | from assignments.urls import assignments_urlpatterns 19 | 20 | urlpatterns = [ 21 | path("admin/", admin.site.urls), 22 | ] 23 | 24 | urlpatterns += assignments_urlpatterns 25 | -------------------------------------------------------------------------------- /backend/assignments/views.py: -------------------------------------------------------------------------------- 1 | from django.db import transaction 2 | 3 | from rest_framework import viewsets 4 | from rest_framework.exceptions import APIException 5 | 6 | from assignments.models import Assignment 7 | from assignments.serializers import AssignmentSerializer 8 | from assignments.tasks import task_execute 9 | 10 | 11 | class AssignmentViewSet(viewsets.ModelViewSet): 12 | 13 | serializer_class = AssignmentSerializer 14 | queryset = Assignment.objects.all() 15 | 16 | def perform_create(self, serializer): 17 | try: 18 | with transaction.atomic(): 19 | # save instance 20 | instance = serializer.save() 21 | instance.save() 22 | 23 | # create task params 24 | job_params = {"db_id": instance.id} 25 | 26 | # submit task for background execution 27 | transaction.on_commit(lambda: task_execute.delay(job_params)) 28 | 29 | except Exception as e: 30 | raise APIException(str(e)) 31 | 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 SaaSitive 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /backend/assignments/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.1.3 on 2022-11-16 11:31 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name="Assignment", 15 | fields=[ 16 | ( 17 | "id", 18 | models.BigAutoField( 19 | auto_created=True, 20 | primary_key=True, 21 | serialize=False, 22 | verbose_name="ID", 23 | ), 24 | ), 25 | ("first_term", models.DecimalField(decimal_places=2, max_digits=5)), 26 | ("second_term", models.DecimalField(decimal_places=2, max_digits=5)), 27 | ( 28 | "sum", 29 | models.DecimalField( 30 | blank=True, decimal_places=2, max_digits=5, null=True 31 | ), 32 | ), 33 | ], 34 | ), 35 | ] 36 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | nginx: 5 | restart: always 6 | image: nginx:1.23-alpine 7 | ports: 8 | - 80:80 9 | volumes: 10 | - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf 11 | - static_volume:/app/backend/django_static 12 | server: 13 | restart: unless-stopped 14 | build: 15 | context: . 16 | dockerfile: ./docker/backend/Dockerfile 17 | entrypoint: /app/docker/backend/server-entrypoint.sh 18 | volumes: 19 | - static_volume:/app/backend/django_static 20 | expose: 21 | - 8000 22 | environment: 23 | DEBUG: "True" 24 | CELERY_BROKER_URL: "redis://redis:6379/0" 25 | CELERY_RESULT_BACKEND: "redis://redis:6379/0" 26 | DJANGO_DB: postgresql 27 | POSTGRES_HOST: db 28 | POSTGRES_NAME: postgres 29 | POSTGRES_USER: postgres 30 | POSTGRES_PASSWORD: postgres 31 | POSTGRES_PORT: 5432 32 | worker: 33 | restart: unless-stopped 34 | build: 35 | context: . 36 | dockerfile: ./docker/backend/Dockerfile 37 | entrypoint: /app/docker/backend/worker-entrypoint.sh 38 | volumes: 39 | - static_volume:/app/backend/django_static 40 | environment: 41 | DEBUG: "True" 42 | CELERY_BROKER_URL: "redis://redis:6379/0" 43 | CELERY_RESULT_BACKEND: "redis://redis:6379/0" 44 | DJANGO_DB: postgresql 45 | POSTGRES_HOST: db 46 | POSTGRES_NAME: postgres 47 | POSTGRES_USER: postgres 48 | POSTGRES_PASSWORD: postgres 49 | POSTGRES_PORT: 5432 50 | depends_on: 51 | - server 52 | - redis 53 | redis: 54 | restart: unless-stopped 55 | image: redis:7.0.5-alpine 56 | expose: 57 | - 6379 58 | db: 59 | image: postgres:13.0-alpine 60 | restart: unless-stopped 61 | volumes: 62 | - postgres_data:/var/lib/postgresql/data/ 63 | environment: 64 | POSTGRES_DB: postgres 65 | POSTGRES_USER: postgres 66 | POSTGRES_PASSWORD: postgres 67 | expose: 68 | - 5432 69 | 70 | 71 | volumes: 72 | static_volume: {} 73 | postgres_data: {} 74 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /backend/backend/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for backend project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.1.3. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.1/ref/settings/ 11 | """ 12 | import os 13 | 14 | from pathlib import Path 15 | 16 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 17 | BASE_DIR = Path(__file__).resolve().parent.parent 18 | 19 | 20 | # Quick-start development settings - unsuitable for production 21 | # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ 22 | 23 | # SECURITY WARNING: keep the secret key used in production secret! 24 | SECRET_KEY = os.environ.get( 25 | "SECRET_KEY", "django-insecure-6hdy-)5o6k6it_6x%s#u0#guc3(au!=v%%qb674(upu6rrht7b" 26 | ) 27 | 28 | # SECURITY WARNING: don't run with debug turned on in production! 29 | DEBUG = os.environ.get("DEBUG", True) 30 | 31 | ALLOWED_HOSTS = ["127.0.0.1", "0.0.0.0"] 32 | 33 | if os.environ.get("ALLOWED_HOSTS") is not None: 34 | try: 35 | ALLOWED_HOSTS += os.environ.get("ALLOWED_HOSTS").split(",") 36 | except Exception as e: 37 | print("Cant set ALLOWED_HOSTS, using default instead") 38 | 39 | # Application definition 40 | 41 | INSTALLED_APPS = [ 42 | "django.contrib.admin", 43 | "django.contrib.auth", 44 | "django.contrib.contenttypes", 45 | "django.contrib.sessions", 46 | "django.contrib.messages", 47 | "django.contrib.staticfiles", 48 | "rest_framework", 49 | "assignments", 50 | ] 51 | 52 | MIDDLEWARE = [ 53 | "django.middleware.security.SecurityMiddleware", 54 | "django.contrib.sessions.middleware.SessionMiddleware", 55 | "django.middleware.common.CommonMiddleware", 56 | "django.middleware.csrf.CsrfViewMiddleware", 57 | "django.contrib.auth.middleware.AuthenticationMiddleware", 58 | "django.contrib.messages.middleware.MessageMiddleware", 59 | "django.middleware.clickjacking.XFrameOptionsMiddleware", 60 | ] 61 | 62 | ROOT_URLCONF = "backend.urls" 63 | 64 | TEMPLATES = [ 65 | { 66 | "BACKEND": "django.template.backends.django.DjangoTemplates", 67 | "DIRS": [], 68 | "APP_DIRS": True, 69 | "OPTIONS": { 70 | "context_processors": [ 71 | "django.template.context_processors.debug", 72 | "django.template.context_processors.request", 73 | "django.contrib.auth.context_processors.auth", 74 | "django.contrib.messages.context_processors.messages", 75 | ], 76 | }, 77 | }, 78 | ] 79 | 80 | WSGI_APPLICATION = "backend.wsgi.application" 81 | 82 | 83 | # Database 84 | # https://docs.djangoproject.com/en/4.1/ref/settings/#databases 85 | 86 | DB_SQLITE = "sqlite" 87 | DB_POSTGRESQL = "postgresql" 88 | 89 | DATABASES_ALL = { 90 | DB_SQLITE: { 91 | "ENGINE": "django.db.backends.sqlite3", 92 | "NAME": BASE_DIR / "db.sqlite3", 93 | }, 94 | DB_POSTGRESQL: { 95 | "ENGINE": "django.db.backends.postgresql", 96 | "HOST": os.environ.get("POSTGRES_HOST", "localhost"), 97 | "NAME": os.environ.get("POSTGRES_NAME", "postgres"), 98 | "USER": os.environ.get("POSTGRES_USER", "postgres"), 99 | "PASSWORD": os.environ.get("POSTGRES_PASSWORD", "postgres"), 100 | "PORT": int(os.environ.get("POSTGRES_PORT", "5432")), 101 | }, 102 | } 103 | 104 | DATABASES = {"default": DATABASES_ALL[os.environ.get("DJANGO_DB", DB_SQLITE)]} 105 | 106 | 107 | # Password validation 108 | # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators 109 | 110 | AUTH_PASSWORD_VALIDATORS = [ 111 | { 112 | "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", 113 | }, 114 | { 115 | "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", 116 | }, 117 | { 118 | "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", 119 | }, 120 | { 121 | "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", 122 | }, 123 | ] 124 | 125 | 126 | # Internationalization 127 | # https://docs.djangoproject.com/en/4.1/topics/i18n/ 128 | 129 | LANGUAGE_CODE = "en-us" 130 | 131 | TIME_ZONE = "UTC" 132 | 133 | USE_I18N = True 134 | 135 | USE_TZ = True 136 | 137 | 138 | # Static files (CSS, JavaScript, Images) 139 | # https://docs.djangoproject.com/en/4.1/howto/static-files/ 140 | 141 | STATIC_URL = "/django_static/" 142 | STATIC_ROOT = BASE_DIR / "django_static" 143 | 144 | 145 | # Default primary key field type 146 | # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field 147 | 148 | DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" 149 | 150 | # celery broker and result 151 | CELERY_BROKER_URL = os.environ.get("BROKER_URL", "redis://localhost:6379/0") 152 | CELERY_RESULT_BACKEND = os.environ.get("RESULT_BACKEND", "redis://localhost:6379/0") 153 | --------------------------------------------------------------------------------