Dev Container / GitHub Codespaces (test)¶
This guide covers running prei in a VS Code Dev Container or GitHub Codespace — the test environment.
Prerequisites¶
| Platform | Requirement |
|---|---|
| GitHub Codespaces | GitHub account, repo access |
| VS Code Dev Containers | VS Code + "Dev Containers" extension + Docker Desktop |
Quick Start¶
GitHub Codespaces (browser-based)¶
- Open the repo on GitHub
- Click Code → Codespaces → Create codespace on main
- Wait for build (~2 minutes)
- In the integrated terminal:
- Open the forwarded port 8000 (toast notification → "Open in Browser")
- Visit
http://localhost:8000
VS Code Dev Container (local)¶
- Open repo in VS Code:
code . - Command Palette (
Ctrl+Shift+P) → Dev Containers: Reopen in Container - Wait for build
- Terminal →
make dev - Open forwarded port 8000
What Happens Automatically¶
The .devcontainer/devcontainer.json configures:
- Base image: Built from root
Dockerfile(Python 3.14, non-rootappuser) - Compose file: Uses root
docker-compose.yml(SQLite, no Postgres) - Environment variables:
DATABASE_URL=sqlite:////home/vscode/db.sqlite3(absolute path — writable byvscodeuser)
DEBUG=True,ALLOWED_HOSTS=*,SECRET_KEY=dev-secret-key-change-meRUN_MIGRATIONS=1- Post-create:
pip install -r requirements.txt && python manage.py migrate --noinput - Post-start:
python manage.py check - Port forward: 8000 → labeled "Django app"
Database¶
- SQLite at
/home/vscode/db.sqlite3(inside container, not the bind-mounted workspace) - Persists across container restarts but not across Codespace rebuilds
- To reset: delete
/home/vscode/db.sqlite3and re-runmake dev
Useful Commands¶
| Command | Purpose |
|---|---|
make dev |
Run migrations + start Django runserver on 0.0.0.0:8000 |
make superuser |
Create admin user (first time only) |
make lint |
Ruff + format check |
make test |
Run pytest suite |
make check |
manage.py check + lint + tests |
Demo Login¶
| Field | Value |
|---|---|
demo@prei.dev |
|
| Password | DemoPass123! |
Created by make dev via seed_data management command.
Troubleshooting¶
Port 8000 not forwarded¶
- VS Code: Ports tab → check 8000 is listed → right-click → "Preview in Browser"
- Codespaces: Ports panel → visibility → "Public" or "Private"
"DisallowedHost" error¶
- Ensure
ALLOWED_HOSTS=*is set (it is in devcontainer.json) - If using custom domain, add to
ALLOWED_HOSTSin.env
Database "unable to open database file"¶
- Fixed in devcontainer.json:
DATABASE_URL=sqlite:////home/vscode/db.sqlite3(absolute path) - The Dev Container uses
mcr.microsoft.com/devcontainers/python(not the root Dockerfile) and runs asvscode, so/home/vscode/is the writable home directory
Changes not reflecting¶
- Dev container mounts workspace at
/workspaces/preibut Django runs from/app - Code is copied into
/appat build time (see DockerfileCOPY . .) - For live reload, use
make devwhich runs Django's runserver with auto-reload watching/app
Architecture Note¶
┌─────────────────────────────────────────────────────┐
│ GitHub Codespace / VS Code Dev Container │
│ ┌─────────────────────────────────────────────┐ │
│ │ Workspace mount: /workspaces/prei (source) │ │
│ └─────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────┐ │
│ │ Container FS: /app (Django runs here) │ │
│ │ ├── db.sqlite3 ← writable (chowned) │ │
│ │ └── ... │ │
│ └─────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘
The source is mounted at /workspaces/prei for git/editor access, but the runtime code lives at /app (copied during docker build). The Dev Container uses its own Dockerfile (.devcontainer/Dockerfile) based on mcr.microsoft.com/devcontainers/python:1-3.13-bookworm. The database goes to /home/vscode/db.sqlite3 — the vscode user's home directory — because the devcontainer runs as vscode, not app.