feat: add Django backend foundation and Docker runtime
Add a Django admin-backed management layer for pobsync configs, runs, snapshots, and schedules. Keep the existing CLI engine as the execution source of truth, add import/run management commands, and provide SQLite default plus optional MariaDB Docker Compose support.
This commit is contained in:
1
src/pobsync_server/__init__.py
Normal file
1
src/pobsync_server/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
10
src/pobsync_server/asgi.py
Normal file
10
src/pobsync_server/asgi.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pobsync_server.settings")
|
||||
|
||||
application = get_asgi_application()
|
||||
91
src/pobsync_server/settings.py
Normal file
91
src/pobsync_server/settings.py
Normal file
@@ -0,0 +1,91 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parents[2]
|
||||
|
||||
SECRET_KEY = os.getenv("POBSYNC_DJANGO_SECRET_KEY", "dev-only-change-me")
|
||||
DEBUG = os.getenv("POBSYNC_DJANGO_DEBUG", "0").lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
_allowed_hosts = os.getenv("POBSYNC_DJANGO_ALLOWED_HOSTS", "localhost,127.0.0.1")
|
||||
ALLOWED_HOSTS = [host.strip() for host in _allowed_hosts.split(",") if host.strip()]
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"pobsync_backend.apps.PobsyncBackendConfig",
|
||||
]
|
||||
|
||||
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 = "pobsync_server.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = "pobsync_server.wsgi.application"
|
||||
|
||||
|
||||
def _database_config() -> dict[str, object]:
|
||||
engine = os.getenv("POBSYNC_DB_ENGINE", "sqlite").strip().lower()
|
||||
if engine in {"mariadb", "mysql"}:
|
||||
return {
|
||||
"ENGINE": "django.db.backends.mysql",
|
||||
"NAME": os.getenv("POBSYNC_DB_NAME", "pobsync"),
|
||||
"USER": os.getenv("POBSYNC_DB_USER", "pobsync"),
|
||||
"PASSWORD": os.getenv("POBSYNC_DB_PASSWORD", "pobsync"),
|
||||
"HOST": os.getenv("POBSYNC_DB_HOST", "db"),
|
||||
"PORT": os.getenv("POBSYNC_DB_PORT", "3306"),
|
||||
"OPTIONS": {
|
||||
"charset": "utf8mb4",
|
||||
},
|
||||
}
|
||||
|
||||
sqlite_path = os.getenv("POBSYNC_SQLITE_PATH", str(BASE_DIR / "var" / "pobsync.sqlite3"))
|
||||
return {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": sqlite_path,
|
||||
}
|
||||
|
||||
|
||||
DATABASES = {
|
||||
"default": _database_config(),
|
||||
}
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
TIME_ZONE = os.getenv("POBSYNC_TIME_ZONE", "UTC")
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
|
||||
STATIC_URL = "static/"
|
||||
STATIC_ROOT = os.getenv("POBSYNC_STATIC_ROOT", str(BASE_DIR / "var" / "static"))
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
POBSYNC_HOME = os.getenv("POBSYNC_HOME", "/opt/pobsync")
|
||||
9
src/pobsync_server/urls.py
Normal file
9
src/pobsync_server/urls.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
]
|
||||
10
src/pobsync_server/wsgi.py
Normal file
10
src/pobsync_server/wsgi.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pobsync_server.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user