Browse Source

Split settings.py

pull/1684/head
Hironsan 2 years ago
parent
commit
810b9c325e
14 changed files with 28 additions and 33 deletions
  1. 1
      Dockerfile
  2. 13
      app.json
  3. 3
      backend/api/tests/test_config.py
  4. 2
      backend/cli.py
  5. 2
      backend/config/celery.py
  6. 0
      backend/config/settings/__init__.py
  7. 20
      backend/config/settings/base.py
  8. 4
      backend/config/settings/development.py
  9. 5
      backend/config/settings/heroku.py
  10. 3
      backend/config/settings/production.py
  11. 2
      backend/config/wsgi.py
  12. 2
      backend/manage.py
  13. 2
      docker-compose.dev.yml
  14. 2
      docker-compose.prod.yml

1
Dockerfile

@ -72,6 +72,7 @@ ENV WORKERS="2"
ENV CELERY_WORKERS="2"
ENV GOOGLE_TRACKING_ID=""
ENV AZURE_APPINSIGHTS_IKEY=""
ENV DJANGO_SETTINGS_MODULE="config.settings.production"
USER doccano
EXPOSE ${PORT}

13
app.json

@ -25,15 +25,10 @@
"required": false,
"value": ""
},
"DEBUG": {
"description": "Debug mode or not.",
"required": false,
"value": "False"
},
"ALLOW_SIGNUP": {
"description": "Allow users to signup themselves or not",
"required": false,
"value": "True"
"DJANGO_SETTINGS_MODULE": {
"description": "Django Settings Module. You don't have to change this.",
"required": true,
"value": "config.settings.production"
}
},
"stack": "container",

3
backend/api/tests/test_config.py

@ -2,10 +2,9 @@ from contextlib import contextmanager
from importlib import reload
from os import environ
from config.settings import base as settings
from django.test import TestCase
from config import settings
class TestDatabaseUrl(TestCase):
def test_sslmode_defaults_to_required(self):

2
backend/cli.py

@ -7,8 +7,8 @@ import sys
from .config.celery import app
os.environ["DEBUG"] = "False"
os.environ["STANDALONE"] = "True"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
base = os.path.abspath(os.path.dirname(__file__))
sys.path.append(base)
manage_path = os.path.join(base, "manage.py")

2
backend/config/celery.py

@ -2,7 +2,7 @@ import os
from celery import Celery
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.development")
app = Celery("config")

0
backend/config/settings/__init__.py

backend/config/settings.py → backend/config/settings/base.py

@ -10,8 +10,6 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
Any setting that is configured via an environment variable may
also be set in a `.env` file in the project base directory.
"""
import importlib.util
import sys
from os import path
import dj_database_url
@ -19,7 +17,7 @@ from environs import Env, EnvError
from furl import furl
# Build paths inside the project like this: path.join(BASE_DIR, ...)
BASE_DIR = path.dirname(path.dirname(path.abspath(__file__)))
BASE_DIR = path.dirname(path.dirname(path.dirname(path.abspath(__file__))))
env = Env()
env.read_env(path.join(BASE_DIR, ".env"), recurse=False)
@ -80,8 +78,7 @@ MIDDLEWARE = [
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"corsheaders.middleware.CorsMiddleware",
]
if DEBUG:
MIDDLEWARE.append("api.middleware.RangesMiddleware")
ROOT_URLCONF = "config.urls"
WSGI_APPLICATION = "config.wsgi.application"
@ -184,16 +181,6 @@ LOGIN_URL = "/login/"
LOGIN_REDIRECT_URL = "/projects/"
LOGOUT_REDIRECT_URL = "/"
# dynamic import to avoid installing psycopg2 on pip installation.
name = "django_heroku"
spec = importlib.util.find_spec(name)
if spec is not None:
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)
module.settings(locals(), test_runner=False)
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
@ -250,9 +237,6 @@ if not EMAIL_HOST:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
if DEBUG:
CORS_ORIGIN_WHITELIST = ("http://127.0.0.1:3000", "http://0.0.0.0:3000", "http://localhost:3000")
# User media files
MEDIA_ROOT = path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"

4
backend/config/settings/development.py

@ -0,0 +1,4 @@
from .base import * # noqa: F403
MIDDLEWARE.append("api.middleware.RangesMiddleware") # noqa: F405
CORS_ORIGIN_WHITELIST = ("http://127.0.0.1:3000", "http://0.0.0.0:3000", "http://localhost:3000")

5
backend/config/settings/heroku.py

@ -0,0 +1,5 @@
import django_heroku
from .base import * # noqa: F401,F403
django_heroku.settings(locals(), test_runner=False)

3
backend/config/settings/production.py

@ -0,0 +1,3 @@
from .base import * # noqa: F401,F403
DEBUG = False

2
backend/config/wsgi.py

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
application = get_wsgi_application()

2
backend/manage.py

@ -3,7 +3,7 @@ import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.development")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:

2
docker-compose.dev.yml

@ -17,6 +17,7 @@ services:
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable"
ALLOW_SIGNUP: "False"
DEBUG: "True"
DJANGO_SETTINGS_MODULE: "config.settings.development"
ports:
- 8000:8000
depends_on:
@ -38,6 +39,7 @@ services:
PYTHONUNBUFFERED: "1"
CELERY_BROKER_URL: "amqp://${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}@rabbitmq"
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable"
DJANGO_SETTINGS_MODULE: "config.settings.development"
depends_on:
- postgres
- rabbitmq

2
docker-compose.prod.yml

@ -17,6 +17,7 @@ services:
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable"
ALLOW_SIGNUP: "False"
DEBUG: "False"
DJANGO_SETTINGS_MODULE: "config.settings.production"
depends_on:
- postgres
networks:
@ -35,6 +36,7 @@ services:
PYTHONUNBUFFERED: "1"
CELERY_BROKER_URL: "amqp://${RABBITMQ_DEFAULT_USER}:${RABBITMQ_DEFAULT_PASS}@rabbitmq"
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable"
DJANGO_SETTINGS_MODULE: "config.settings.production"
depends_on:
- postgres
- rabbitmq

Loading…
Cancel
Save