Unit Tests / test (push) Successful in 3s
## Summary - Dockerize SCHA Wheaton (uv packaging, Dockerfile, compose, entrypoint) and move secrets/DB config to env-driven `scha/settings/`. - Add Gitea Actions: unit tests on push/PR to `master`, auto-deploy on green master push via `server-infra/scripts/deploy.sh --app scha --env prod`. - Prod compose uses shared external Postgres only (no bundled DB); control-node secret template at `.env.prod.example`. Closes #19 (Part A). Depends on companion server-infra PR for catalog/host_apps registration. ## Test plan - [ ] `uv sync --frozen` + `DJANGO_ENV=dev DJANGO_SECRET_KEY=test uv run python manage.py check` - [ ] `docker compose build` succeeds locally - [ ] `docker compose up` serves app against bundled Postgres - [ ] `./scripts/validate-env.sh ~/Documents/secrets/scha/scha_prod.env` passes - [ ] After merge + server-infra catalog live: push to master runs Unit Tests then Deploy Reviewed-on: #21
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
"""Environment-specific logging configuration."""
|
|
|
|
import os
|
|
|
|
|
|
def build_logging_config(level: str, environment: str) -> dict:
|
|
"""Return a Django LOGGING dict for the given level and environment name."""
|
|
return {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"formatters": {
|
|
"verbose": {
|
|
"format": (
|
|
f"{{levelname}} {{asctime}} {{name}} {{process:d}} {{thread:d}} "
|
|
f"[env={environment}] {{message}}"
|
|
),
|
|
"style": "{",
|
|
},
|
|
"simple": {
|
|
"format": f"{{levelname}} [env={environment}] {{message}}",
|
|
"style": "{",
|
|
},
|
|
},
|
|
"handlers": {
|
|
"console": {
|
|
"class": "logging.StreamHandler",
|
|
"formatter": "verbose" if environment == "dev" else "simple",
|
|
},
|
|
},
|
|
"root": {
|
|
"handlers": ["console"],
|
|
"level": level,
|
|
},
|
|
"loggers": {
|
|
"django": {
|
|
"handlers": ["console"],
|
|
"level": level,
|
|
"propagate": False,
|
|
},
|
|
"django.request": {
|
|
"handlers": ["console"],
|
|
"level": "ERROR" if environment == "prod" else level,
|
|
"propagate": False,
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
def logging_level_for_env(environment: str) -> str:
|
|
override = os.environ.get("DJANGO_LOG_LEVEL")
|
|
if override:
|
|
return override.upper()
|
|
|
|
if environment == "dev":
|
|
return "DEBUG"
|
|
if environment == "beta":
|
|
return "INFO"
|
|
return "WARNING"
|