Skip to content

Commit ca7a542

Browse files
Cleanup and adjustment for test in docker stack.
1 parent 2b4b57c commit ca7a542

14 files changed

+97
-246
lines changed

django/Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ RUN ./install_dependencies.sh -e docker
1919
# install gunicorn and whitenoise (if not already installed via dependencies script)
2020
RUN pip install --no-cache-dir gunicorn whitenoise
2121
# optional gunicorn tuning vars
22-
ENV GUNICORN_WORKERS=2 \
23-
GUNICORN_BIND=0.0.0.0:8000 \
24-
GUNICORN_TIMEOUT=120 \
25-
DJANGO_DEBUG=1
22+
ENV GUNICORN_WORKERS=2
23+
ENV GUNICORN_BIND=0.0.0.0:8000
24+
ENV GUNICORN_LOG_LEVEL=info
25+
#ENV GUNICORN_TIMEOUT=120
26+
#ENV DJANGO_DEBUG=1
2627
EXPOSE 8000
2728

2829
FROM cohiva-platform-django AS cohiva-platform-app
@@ -43,4 +44,6 @@ COPY docker-entrypoint.sh /usr/local/bin/
4344
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
4445

4546
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
46-
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--log-level", "info", "cohiva.wsgi:application"]
47+
#ENV GUNICORN_CMD_ARGS="--workers ${GUNICORN_WORKERS} --bind ${GUNICORN_BIND} --timeout ${GUNICORN_TIMEOUT}"
48+
ENV GUNICORN_CMD_ARGS="--workers ${GUNICORN_WORKERS} --bind ${GUNICORN_BIND} --log-level ${GUNICORN_LOG_LEVEL}}"
49+
CMD ["gunicorn", "cohiva.wsgi:application"]

django/cohiva/base_config_example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# Container IP address, if you run Cohiva in Docker (optional, comment out to disable).
1616
DOCKER_IP = "172.20.42.100"
1717

18+
# Use Whitenoise to serve static files in production (https://whitenoise.readthedocs.io/en/stable/django.html)
19+
USE_WHITENOISE = False
20+
1821
SITE_NAME = "Genossenschaft Musterweg"
1922
SITE_NICKNAME = "Musterweg"
2023
SITE_SECRET = "<SECRET>"
@@ -37,9 +40,9 @@
3740
FEATURES = [
3841
"api",
3942
"portal",
40-
"reservation",
43+
"reservation", # currently required by api
4144
"report",
42-
"credit_accounting",
45+
"credit_accounting", # currently required by geno
4346
"website",
44-
"cms",
47+
"cms", # currently required by portal
4548
]

django/cohiva/middleware.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
logger = logging.getLogger(__name__)
44

5+
56
class RequestDebugMiddleware:
67
def __init__(self, get_response):
78
self.get_response = get_response
@@ -11,8 +12,8 @@ def __call__(self, request):
1112
logger.error(f"HOST: {request.META.get('HTTP_HOST', 'NO_HOST')}")
1213
logger.error(f"USER_AGENT: {request.META.get('HTTP_USER_AGENT', 'NO_UA')}")
1314
logger.error(f"REMOTE_ADDR: {request.META.get('REMOTE_ADDR', 'NO_ADDR')}")
14-
15+
1516
response = self.get_response(request)
16-
17+
1718
logger.error(f"RESPONSE: {response.status_code}")
1819
return response

django/cohiva/settings_defaults.py

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
"""
2-
Django default settings for Cohiva.
2+
Django default base settings for Cohiva.
33
44
To change settings, overwrite them in settings.py or settings_production.py
5+
6+
NOTE: Settings are cascaded in the following order (settings in the later files override/extend
7+
settings in the earlier files):
8+
9+
1. settings_defaults.py (default base settings)
10+
2. settings.py (custom base settings)
11+
3. settings_production_defaults.py (default production settings)
12+
4. settings_production.py (custom production settings)
513
"""
614

715
import datetime
816
import locale
9-
import os
1017
from pathlib import Path
1118
from urllib.parse import quote
1219

@@ -274,8 +281,10 @@
274281
"portal.middleware.SecondaryPortalMiddleware",
275282
"oauth2_provider.middleware.OAuth2TokenMiddleware", ## For Oauth2 token authentication
276283
)
284+
MIDDLEWARE += ("django.middleware.security.SecurityMiddleware",)
285+
if getattr(cbc, "USE_WHITENOISE", False):
286+
MIDDLEWARE += ("whitenoise.middleware.WhiteNoiseMiddleware",)
277287
MIDDLEWARE += (
278-
"django.middleware.security.SecurityMiddleware",
279288
"django.contrib.sessions.middleware.SessionMiddleware",
280289
# LocaleMiddleware MUST be after SessionMiddleware (needs session data for language preferences)
281290
# and BEFORE CommonMiddleware (needs to process language before URL resolution)
@@ -427,12 +436,10 @@
427436
},
428437
"staticfiles": {
429438
"BACKEND": "cohiva.storage.CacheBustingStaticFilesStorage",
439+
# BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
430440
},
431441
}
432442

433-
## For production, use ManifestStaticFilesStorage instead (requires collectstatic):
434-
##STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
435-
436443
# Additional locations of static files
437444
# STATICFILES_DIRS = (
438445
# BASE_DIR / 'static',
@@ -585,16 +592,18 @@
585592
## django-filer - https://django-filer.readthedocs.io/en/latest/settings.html
586593
FILER_ENABLE_PERMISSIONS = True
587594
FILER_IS_PUBLIC_DEFAULT = False
588-
FILER_SERVERS = {
589-
"private": {
590-
"main": {
591-
"ENGINE": "filer.server.backends.xsendfile.ApacheXSendfileServer",
592-
},
593-
"thumbnails": {
594-
"ENGINE": "filer.server.backends.xsendfile.ApacheXSendfileServer",
595-
},
596-
},
597-
}
595+
## Use upstream Apache to serve private files with X-Sendfile
596+
## (instead of the default filer.server.backends.default.DefaultServer backend)
597+
# FILER_SERVERS = {
598+
# "private": {
599+
# "main": {
600+
# "ENGINE": "filer.server.backends.xsendfile.ApacheXSendfileServer",
601+
# },
602+
# "thumbnails": {
603+
# "ENGINE": "filer.server.backends.xsendfile.ApacheXSendfileServer",
604+
# },
605+
# },
606+
# }
598607

599608
## Celery with redis
600609
CELERY_BROKER_URL = "redis://localhost:6379/0"
@@ -1408,23 +1417,3 @@
14081417
# Crispy Forms Configuration for Unfold
14091418
CRISPY_TEMPLATE_PACK = "unfold_crispy"
14101419
CRISPY_ALLOWED_TEMPLATE_PACKS = ["unfold_crispy"]
1411-
1412-
1413-
# Add WhiteNoise for static file serving
1414-
MIDDLEWARE = [
1415-
'whitenoise.middleware.WhiteNoiseMiddleware',
1416-
] + list(MIDDLEWARE)
1417-
1418-
# Static files configuration
1419-
STATIC_ROOT = "/tmp/static" # Temporary location for collected static files
1420-
STATIC_URL = "/static/"
1421-
1422-
# Use simpler WhiteNoise backend without compression
1423-
STORAGES = {
1424-
"default": {
1425-
"BACKEND": "django.core.files.storage.FileSystemStorage",
1426-
},
1427-
"staticfiles": {
1428-
"BACKEND": "whitenoise.storage.StaticFilesStorage",
1429-
},
1430-
}

django/cohiva/settings_docker.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

django/cohiva/settings_docker_compose.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

django/cohiva/settings_example.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
## Settings for test/development environment
2-
## For production settings use settings_production.py
1+
"""
2+
Django custom base settings for Cohiva.
3+
4+
NOTE: Settings are cascaded in the following order (settings in the later files override/extend
5+
settings in the earlier files):
6+
7+
1. settings_defaults.py (default base settings)
8+
2. settings.py (custom base settings)
9+
3. settings_production_defaults.py (default production settings)
10+
4. settings_production.py (custom production settings)
11+
"""
312

413
## Load default test settings
514
from .settings_defaults import * # noqa: F403

django/cohiva/settings_migration.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)