diff --git a/Dockerfile b/Dockerfile index 01db349..300b018 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,6 @@ RUN pip3 install ${RELEASE} --no-cache-dir WORKDIR ${TARGET} -COPY docker_settings.py local_settings.py RUN SECRET_KEY=_ ${TARGET}/bin/manage collectstatic --noinput VOLUME ["/var/polyphonic"] diff --git a/app/library/indexer/whoosh.py b/app/library/indexer/whoosh.py index dde065f..171fade 100644 --- a/app/library/indexer/whoosh.py +++ b/app/library/indexer/whoosh.py @@ -24,7 +24,7 @@ schema = Schema( ) -index_path = os.path.join(os.path.dirname(settings.BASE_DIR), "index") +index_path = settings.WHOOSH_INDEX def create_index() -> Index: diff --git a/app/polyphonic/default_settings.py b/app/polyphonic/default_settings.py deleted file mode 100644 index 2bc881c..0000000 --- a/app/polyphonic/default_settings.py +++ /dev/null @@ -1,136 +0,0 @@ -""" -Django settings for polyphonic project. - -Generated by 'django-admin startproject' using Django 3.1.1. - -For more information on this file, see -https://docs.djangoproject.com/en/3.1/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/3.1/ref/settings/ -""" - -from pathlib import Path -from os import environ - -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - -SECRET_KEY = environ.get("SECRET_KEY") - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ - - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False - -ALLOWED_HOSTS = ["localhost"] -INTERNAL_IPS = ["127.0.0.1"] - -# Application definition - -POLYPHONIC_MODULES = ["library"] - -INSTALLED_APPS = [ - "django.contrib.admin", - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", - "django_markdown2", - "rest_framework", - "crispy_forms", - "crispy_bulma", - "byostorage", - "interface", -] - -CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",) -CRISPY_TEMPLATE_PACK = "bulma" - -MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "django.middleware.common.CommonMiddleware", - "django.middleware.csrf.CsrfViewMiddleware", - "django.contrib.auth.middleware.AuthenticationMiddleware", - "django.contrib.messages.middleware.MessageMiddleware", - "django.middleware.clickjacking.XFrameOptionsMiddleware", -] - -ROOT_URLCONF = "polyphonic.urls" - -TEMPLATES = [ - { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], - "APP_DIRS": True, - "OPTIONS": { - "context_processors": [ - "django.template.context_processors.debug", - "django.template.context_processors.request", - "django.contrib.auth.context_processors.auth", - "django.contrib.messages.context_processors.messages", - ], - }, - }, -] - -WSGI_APPLICATION = "polyphonic.wsgi.application" - - -# Database -# https://docs.djangoproject.com/en/3.1/ref/settings/#databases - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", - } -} - -DEFAULT_AUTO_FIELD = "django.db.models.AutoField" - -# Password validation -# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", - }, -] -LOGIN_REDIRECT_URL = "/" - -# Internationalization -# https://docs.djangoproject.com/en/3.1/topics/i18n/ - -# Localisation (localization?) -LANGUAGE_CODE = "en-us" -TIME_ZONE = "Australia/Melbourne" - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.1/howto/static-files/ - -STATIC_URL = "/static/" -STATIC_ROOT = "static" - -# Need to set this -AWS_BUCKET = "" diff --git a/app/polyphonic/settings.py b/app/polyphonic/settings.py index 2b8433f..6256d05 100644 --- a/app/polyphonic/settings.py +++ b/app/polyphonic/settings.py @@ -1,11 +1,141 @@ +""" +Django settings for polyphonic project. + +Generated by 'django-admin startproject' using Django 3.1.1. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.1/ref/settings/ +""" + +from pathlib import Path import os -import sys -sys.path.insert(0, os.getcwd()) -try: - from local_settings import * # noqa -except ImportError: - from .default_settings import * # noqa +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent.parent -INSTALLED_APPS += POLYPHONIC_MODULES # type: ignore #noqa +# A place to put things +WORK_DIR = os.environ.get("WORK_DIR") or os.path.join(BASE_DIR, "data") + +# Will fail to start if not defined +SECRET_KEY = os.environ.get("SECRET_KEY") + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False + +ALLOWED_HOSTS = ["localhost"] + +# Application definition + +POLYPHONIC_MODULES = ["library"] + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "django_markdown2", + "rest_framework", + "crispy_forms", + "crispy_bulma", + "byostorage", + "interface", +] + +INSTALLED_APPS += POLYPHONIC_MODULES + +CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",) +CRISPY_TEMPLATE_PACK = "bulma" + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "polyphonic.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "polyphonic.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(WORK_DIR, "db.sqlite3"), + } +} + +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" + +# Password validation +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] +LOGIN_REDIRECT_URL = "/" + +# Internationalization +# https://docs.djangoproject.com/en/3.1/topics/i18n/ + +# Localisation (localization?) +LANGUAGE_CODE = "en-us" +TIME_ZONE = "Australia/Melbourne" + +USE_I18N = True +USE_L10N = True +USE_TZ = True + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.1/howto/static-files/ + +STATIC_URL = "/static/" +STATIC_ROOT = "static" + +# Library settings + +CACHED_STORAGE_REMOTE = "byostorage.user.BYOStorage" +CACHED_STORAGE_DIR = os.path.join(WORK_DIR, "cache") +WHOOSH_INDEX = os.path.join(WORK_DIR, "index") diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..47e751c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + polyphonic: + image: "polyphonic:latest" + build: "." + ports: + - "8000:8000" + volumes: + - "./data:/var/polyphonic" + env_file: "local.env" diff --git a/docker_settings.py b/docker_settings.py index 7730e7f..a0a2086 100644 --- a/docker_settings.py +++ b/docker_settings.py @@ -1,10 +1,8 @@ -from polyphonic.default_settings import * +from .default_settings import * import os DEBUG = bool(os.environ.get("DEBUG", False)) -CACHE_DIR = "/var/polyphonic/cache" - DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3",