Containerize the company_site Django project so it runs in Docker with environment-specific configuration for dev, beta, and prod. Settings (especially logging and database) should be driven by environment variables rather than hardcoded values or server-local files.
Background / Current State
Single company_site/settings.py with hardcoded secrets, SQLite database, and DEBUG = True
Production uses a separate local_settings.py on the server (preserved during deploy via scripts/deploy.sh rsync excludes)
Deploy workflow (.gitea/workflows/deploy.yml) runs tests then rsyncs to a host venv + systemctl restart company
psycopg2-binary and gunicorn already in requirements.txt but Postgres is not wired in settings
No Docker or docker-compose files exist yet
Goals
Docker image for the Django app (Gunicorn WSGI)
docker-compose for local dev (app + Postgres service)
Environment levels: dev, beta, prod selectable via env var (e.g. DJANGO_ENV or APP_ENV)
Flexible settings via environment variables for secrets and config that differ per environment
Environment-specific logging (beta vs prod may differ in level, handlers, format, or destinations)
PostgreSQL as the database backend in beta/prod (SQLite acceptable for local dev if desired)
Proposed Approach
Settings refactor
Split settings into a base module plus environment overlays, or use a single settings module that reads from env vars
Move secrets out of source control: SECRET_KEY, reCAPTCHA keys, SMTP credentials, Tianji config, etc.
Use DJANGO_SETTINGS_MODULE or DJANGO_ENV to select dev/beta/prod behavior
Database config from env vars:
DATABASE_URL or DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD
Other env-driven settings: DEBUG, ALLOWED_HOSTS, TIANJI_ENABLED, static/media paths
Logging
Define LOGGING dict per environment in settings overlays
Dev: verbose console logging, DEBUG level
Beta: structured logging, INFO level, possibly file or stdout for container log aggregation
Prod: production-appropriate level (WARNING/INFO), no sensitive data in logs, stdout for container runtime
Docker
Dockerfile: Python base, install requirements, collectstatic at build or entrypoint, run Gunicorn
docker-compose.yml (dev): web service + Postgres + volume for DB persistence
.env.example documenting all required variables per environment
Entrypoint script: wait for Postgres, run migrations, start Gunicorn
Deployment integration
Update .gitea/workflows/deploy.yml and/or scripts/deploy.sh to build and run containers instead of (or alongside) venv + systemd
Document how beta and prod differ in env files or compose overrides
Acceptance Criteria
docker compose up starts app + Postgres locally with dev settings
App connects to Postgres when DATABASE_URL (or equivalent) is set
Switching DJANGO_ENV=dev|beta|prod changes DEBUG, logging, and other env-specific behavior
No secrets committed to the repo; .env.example lists required vars
Beta and prod logging configs are distinct and documented
Existing unit tests pass inside the container or CI
README or docs cover local dev, beta, and prod Docker usage
Out of Scope (for follow-up tickets)
Reverse proxy / TLS termination (nginx, Traefik)
Production orchestration (Kubernetes, Swarm)
Managed Postgres hosting specifics
Notes
Preserve current production behavior during migration; local_settings.py pattern can inform which vars prod needs
Consider django-environ or similar for env parsing (optional)
## Summary
Containerize the `company_site` Django project so it runs in Docker with environment-specific configuration for **dev**, **beta**, and **prod**. Settings (especially logging and database) should be driven by environment variables rather than hardcoded values or server-local files.
## Background / Current State
- Single `company_site/settings.py` with hardcoded secrets, SQLite database, and `DEBUG = True`
- Production uses a separate `local_settings.py` on the server (preserved during deploy via `scripts/deploy.sh` rsync excludes)
- Deploy workflow (`.gitea/workflows/deploy.yml`) runs tests then rsyncs to a host venv + `systemctl restart company`
- `psycopg2-binary` and `gunicorn` already in `requirements.txt` but Postgres is not wired in settings
- No Docker or docker-compose files exist yet
## Goals
1. **Docker image** for the Django app (Gunicorn WSGI)
2. **docker-compose** for local dev (app + Postgres service)
3. **Environment levels**: `dev`, `beta`, `prod` selectable via env var (e.g. `DJANGO_ENV` or `APP_ENV`)
4. **Flexible settings** via environment variables for secrets and config that differ per environment
5. **Environment-specific logging** (beta vs prod may differ in level, handlers, format, or destinations)
6. **PostgreSQL** as the database backend in beta/prod (SQLite acceptable for local dev if desired)
## Proposed Approach
### Settings refactor
- Split settings into a base module plus environment overlays, or use a single settings module that reads from env vars
- Move secrets out of source control: `SECRET_KEY`, reCAPTCHA keys, SMTP credentials, Tianji config, etc.
- Use `DJANGO_SETTINGS_MODULE` or `DJANGO_ENV` to select dev/beta/prod behavior
- Database config from env vars:
- `DATABASE_URL` or `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, `DB_PASSWORD`
- Other env-driven settings: `DEBUG`, `ALLOWED_HOSTS`, `TIANJI_ENABLED`, static/media paths
### Logging
- Define `LOGGING` dict per environment in settings overlays
- **Dev**: verbose console logging, DEBUG level
- **Beta**: structured logging, INFO level, possibly file or stdout for container log aggregation
- **Prod**: production-appropriate level (WARNING/INFO), no sensitive data in logs, stdout for container runtime
### Docker
- `Dockerfile`: Python base, install requirements, collectstatic at build or entrypoint, run Gunicorn
- `docker-compose.yml` (dev): web service + Postgres + volume for DB persistence
- `.env.example` documenting all required variables per environment
- Entrypoint script: wait for Postgres, run migrations, start Gunicorn
### Deployment integration
- Update `.gitea/workflows/deploy.yml` and/or `scripts/deploy.sh` to build and run containers instead of (or alongside) venv + systemd
- Document how beta and prod differ in env files or compose overrides
## Acceptance Criteria
- [ ] `docker compose up` starts app + Postgres locally with dev settings
- [ ] App connects to Postgres when `DATABASE_URL` (or equivalent) is set
- [ ] Switching `DJANGO_ENV=dev|beta|prod` changes DEBUG, logging, and other env-specific behavior
- [ ] No secrets committed to the repo; `.env.example` lists required vars
- [ ] Beta and prod logging configs are distinct and documented
- [ ] Existing unit tests pass inside the container or CI
- [ ] README or docs cover local dev, beta, and prod Docker usage
## Out of Scope (for follow-up tickets)
- Reverse proxy / TLS termination (nginx, Traefik)
- Production orchestration (Kubernetes, Swarm)
- Managed Postgres hosting specifics
## Notes
- Preserve current production behavior during migration; `local_settings.py` pattern can inform which vars prod needs
- Consider `django-environ` or similar for env parsing (optional)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Containerize the
company_siteDjango project so it runs in Docker with environment-specific configuration for dev, beta, and prod. Settings (especially logging and database) should be driven by environment variables rather than hardcoded values or server-local files.Background / Current State
company_site/settings.pywith hardcoded secrets, SQLite database, andDEBUG = Truelocal_settings.pyon the server (preserved during deploy viascripts/deploy.shrsync excludes).gitea/workflows/deploy.yml) runs tests then rsyncs to a host venv +systemctl restart companypsycopg2-binaryandgunicornalready inrequirements.txtbut Postgres is not wired in settingsGoals
dev,beta,prodselectable via env var (e.g.DJANGO_ENVorAPP_ENV)Proposed Approach
Settings refactor
SECRET_KEY, reCAPTCHA keys, SMTP credentials, Tianji config, etc.DJANGO_SETTINGS_MODULEorDJANGO_ENVto select dev/beta/prod behaviorDATABASE_URLorDB_HOST,DB_PORT,DB_NAME,DB_USER,DB_PASSWORDDEBUG,ALLOWED_HOSTS,TIANJI_ENABLED, static/media pathsLogging
LOGGINGdict per environment in settings overlaysDocker
Dockerfile: Python base, install requirements, collectstatic at build or entrypoint, run Gunicorndocker-compose.yml(dev): web service + Postgres + volume for DB persistence.env.exampledocumenting all required variables per environmentDeployment integration
.gitea/workflows/deploy.ymland/orscripts/deploy.shto build and run containers instead of (or alongside) venv + systemdAcceptance Criteria
docker compose upstarts app + Postgres locally with dev settingsDATABASE_URL(or equivalent) is setDJANGO_ENV=dev|beta|prodchanges DEBUG, logging, and other env-specific behavior.env.examplelists required varsOut of Scope (for follow-up tickets)
Notes
local_settings.pypattern can inform which vars prod needsdjango-environor similar for env parsing (optional)