1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
--- a/src/config/settings.py
+++ b/src/config/settings.py
@@ -21,7 +21,11 @@
REDIS_PREFIX = config("REDIS_PREFIX", default=None)
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
+
+# Arch packaging: allow writable state (db + collectstatic + media) outside the code dir.
+YAMTRACK_DATA_DIR = config("YAMTRACK_DATA_DIR", default=None)
+DATA_DIR = Path(YAMTRACK_DATA_DIR) if YAMTRACK_DATA_DIR else BASE_DIR
def secret(key, default=undefined, **kwargs):
@@ -95,6 +99,7 @@
MIDDLEWARE = [
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.security.SecurityMiddleware",
+ "whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
@@ -136,7 +141,7 @@
# https://docs.djangoproject.com/en/stable/ref/settings/#databases
# create db folder if it doesn't exist
-Path(BASE_DIR / "db").mkdir(parents=True, exist_ok=True)
+Path(DATA_DIR / "db").mkdir(parents=True, exist_ok=True)
if config("DB_HOST", default=None):
DATABASES = {
@@ -162,8 +167,8 @@
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
- "NAME": BASE_DIR / "db" / "db.sqlite3",
+ "NAME": DATA_DIR / "db" / "db.sqlite3",
"OPTIONS": {
"timeout": 10,
"transaction_mode": "IMMEDIATE",
@@ -239,10 +244,23 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/stable/howto/static-files/
-STATIC_URL = "static/"
-STATIC_ROOT = BASE_DIR / "staticfiles"
+STATIC_URL = "/static/"
+STATIC_ROOT = DATA_DIR / "staticfiles"
STATICFILES_DIRS = [BASE_DIR / "static"]
+# WhiteNoise: serve static files directly. Restoring 'default' is critical for health checks.
+STORAGES = {
+ "default": {
+ "BACKEND": "django.core.files.storage.FileSystemStorage",
+ },
+ "staticfiles": {
+ "BACKEND": "whitenoise.storage.CompressedStaticFilesStorage",
+ },
+}
+
+MEDIA_ROOT = DATA_DIR / "media"
+MEDIA_URL = "/media/"
+
if BASE_URL:
STATIC_URL = f"{BASE_URL}/static/"
|