|
| 1 | +# KernelCI Dashboard — Deployment Guide |
| 2 | + |
| 3 | +This guide covers three deployment scenarios: **development**, **production**, and **staging**. |
| 4 | + |
| 5 | +## Quick Reference |
| 6 | + |
| 7 | +| Scenario | Compose File | Database | Profiles | |
| 8 | +|----------|-------------|----------|----------| |
| 9 | +| Development | `docker-compose.yml` | Local (always on) | `with_commands` for ingester | |
| 10 | +| Production | `docker-compose-next.yml` | External PostgreSQL | none (or `with_commands`) | |
| 11 | +| Staging | `docker-compose-next.yml` | Local via profile | `local-db` (+ `with_commands`) | |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## 1. Development (`docker-compose.yml`) |
| 16 | + |
| 17 | +The development setup builds images locally and uses per-service `.env` files. |
| 18 | + |
| 19 | +### Setup |
| 20 | + |
| 21 | +```bash |
| 22 | +# Copy all example env files |
| 23 | +cp .env.example .env |
| 24 | +cp .env.backend.example .env.backend |
| 25 | +cp .env.db.example .env.db |
| 26 | +cp .env.proxy.example .env.proxy |
| 27 | +cp .env.ingester.example .env.ingester |
| 28 | +cp .env.pending_aggregations.example .env.pending_aggregations |
| 29 | + |
| 30 | +# Start all core services (builds images from source) |
| 31 | +docker compose up --build -d |
| 32 | + |
| 33 | +# Include ingester and aggregation processor |
| 34 | +docker compose --profile=with_commands up --build -d |
| 35 | +``` |
| 36 | + |
| 37 | +### Rebuilding after code changes |
| 38 | + |
| 39 | +```bash |
| 40 | +# Rebuild and restart just the backend |
| 41 | +docker compose up --build -d backend |
| 42 | + |
| 43 | +# Rebuild everything |
| 44 | +docker compose up --build -d |
| 45 | +``` |
| 46 | + |
| 47 | +### Frontend development |
| 48 | + |
| 49 | +For active frontend work, run the Vite dev server directly: |
| 50 | + |
| 51 | +```bash |
| 52 | +cd dashboard |
| 53 | +pnpm install |
| 54 | +# Copy the example env file and verify VITE_API_BASE_URL |
| 55 | +cp .env.example .env |
| 56 | +pnpm dev |
| 57 | +``` |
| 58 | + |
| 59 | +The frontend connects to the backend API via the `VITE_API_BASE_URL` defined in `dashboard/.env` (defaults to `http://localhost:8000`). |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## 2. Production (`docker-compose-next.yml`, external PostgreSQL) |
| 64 | + |
| 65 | +Uses pre-built images from GHCR and connects to an external PostgreSQL instance. |
| 66 | + |
| 67 | +### Setup |
| 68 | + |
| 69 | +```bash |
| 70 | +# 1. Create .env from the template |
| 71 | +cp .env.example .env |
| 72 | + |
| 73 | +# 2. Edit .env — at minimum, set these: |
| 74 | +# DB_HOST → your PostgreSQL host |
| 75 | +# DB_PORT → your PostgreSQL port (default: 5432) |
| 76 | +# DB_PASSWORD → your PostgreSQL password |
| 77 | +# DJANGO_SECRET_KEY → a strong random string |
| 78 | +# ALLOWED_HOSTS → e.g. ["backend", "your-domain.com"] |
| 79 | +# CORS_ALLOWED_ORIGINS → e.g. ["https://your-domain.com"] |
| 80 | + |
| 81 | +# 3. Start services |
| 82 | +docker compose -f docker-compose-next.yml up -d |
| 83 | + |
| 84 | +# 4. Verify |
| 85 | +curl http://localhost/api/ |
| 86 | + |
| 87 | +# 5. Run database migrations (first deploy or after updates) |
| 88 | +docker compose -f docker-compose-next.yml run --rm backend \ |
| 89 | + sh -c "chmod +x ./migrate-app-db.sh && ./migrate-app-db.sh" |
| 90 | +``` |
| 91 | + |
| 92 | +### With ingester and aggregation processor |
| 93 | + |
| 94 | +```bash |
| 95 | +# Set INGESTER_SPOOL_DIR in .env to the host path where submissions arrive |
| 96 | +docker compose -f docker-compose-next.yml --profile=with_commands up -d |
| 97 | +``` |
| 98 | + |
| 99 | +### Updating to a new version |
| 100 | + |
| 101 | +```bash |
| 102 | +# Pull latest images and restart |
| 103 | +docker compose -f docker-compose-next.yml pull |
| 104 | +docker compose -f docker-compose-next.yml up -d |
| 105 | + |
| 106 | +# Run migrations if needed |
| 107 | +docker compose -f docker-compose-next.yml run --rm backend \ |
| 108 | + sh -c "chmod +x ./migrate-app-db.sh && ./migrate-app-db.sh" |
| 109 | +``` |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +## 3. Staging (`docker-compose-next.yml`, local PostgreSQL) |
| 114 | + |
| 115 | +Uses pre-built images with a local PostgreSQL container via the `local-db` profile. |
| 116 | + |
| 117 | +### Setup |
| 118 | + |
| 119 | +```bash |
| 120 | +# 1. Create .env from the template |
| 121 | +cp .env.example .env |
| 122 | + |
| 123 | +# 2. Edit .env — at minimum, set these: |
| 124 | +# DB_PASSWORD → choose a password for the local postgres |
| 125 | +# DJANGO_SECRET_KEY → a random string (can be less strict for staging) |
| 126 | +# Keep DB_HOST=dashboard_db (the default) |
| 127 | + |
| 128 | +# 3. Start the database first (wait for it to be ready) |
| 129 | +docker compose -f docker-compose-next.yml --profile=local-db up -d dashboard_db |
| 130 | +docker compose -f docker-compose-next.yml exec dashboard_db pg_isready -U admin |
| 131 | + |
| 132 | +# 4. Start remaining services |
| 133 | +docker compose -f docker-compose-next.yml --profile=local-db up -d |
| 134 | + |
| 135 | +# 5. Verify |
| 136 | +curl http://localhost:8000/api/ |
| 137 | +curl http://localhost/ |
| 138 | +``` |
| 139 | + |
| 140 | +### With all optional services |
| 141 | + |
| 142 | +```bash |
| 143 | +docker compose -f docker-compose-next.yml --profile=local-db --profile=with_commands up -d |
| 144 | +``` |
| 145 | + |
| 146 | +### Tear down (including database volume) |
| 147 | + |
| 148 | +```bash |
| 149 | +docker compose -f docker-compose-next.yml --profile=local-db down -v |
| 150 | +``` |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +## Profile Reference |
| 155 | + |
| 156 | +| Command | Services | |
| 157 | +|---------|----------| |
| 158 | +| `docker compose -f docker-compose-next.yml up -d` | redis, backend, dashboard, proxy | |
| 159 | +| `... --profile=local-db up -d` | + dashboard_db | |
| 160 | +| `... --profile=with_commands up -d` | + ingester, pending_aggregations_processor | |
| 161 | +| `... --profile=local-db --profile=with_commands up -d` | All services | |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Docker Secrets Support |
| 166 | + |
| 167 | +The backend entrypoint supports Docker secrets for `DB_PASSWORD`. Instead of setting the password directly in `.env`, you can use: |
| 168 | + |
| 169 | +```bash |
| 170 | +# Create a secrets file |
| 171 | +echo "my-secret-password" > backend/runtime/secrets/postgres_password_secret |
| 172 | + |
| 173 | +# Set in .env or environment: |
| 174 | +DB_PASSWORD_FILE=/run/secrets/postgres_password_secret |
| 175 | +``` |
| 176 | + |
| 177 | +The entrypoint's `file_env` function reads the file and exports `DB_PASSWORD`. You cannot set both `DB_PASSWORD` and `DB_PASSWORD_FILE` — the entrypoint will error if both are present. |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +## Migration Notes |
| 182 | + |
| 183 | +### From `DB_DEFAULT_*` to `DB_*` variables |
| 184 | + |
| 185 | +Previous versions used `DB_DEFAULT_*` prefixed variables (e.g., `DB_DEFAULT_PASSWORD`, `DB_DEFAULT_HOST`). These have been replaced with `DB_*` variables (e.g., `DB_PASSWORD`, `DB_HOST`). |
| 186 | + |
| 187 | +**If upgrading from a previous deployment:** |
| 188 | + |
| 189 | +1. Rename variables in your `.env` / environment: |
| 190 | + - `DB_DEFAULT_PASSWORD` → `DB_PASSWORD` |
| 191 | + - `DB_DEFAULT_HOST` → `DB_HOST` |
| 192 | + - `DB_DEFAULT_PORT` → `DB_PORT` |
| 193 | + - `DB_DEFAULT_NAME` → `DB_NAME` |
| 194 | + - `DB_DEFAULT_USER` → `DB_USER` |
| 195 | + - `DB_DEFAULT_ENGINE` → `DB_ENGINE` |
| 196 | + |
| 197 | +2. If using Docker secrets: rename `DB_DEFAULT_PASSWORD_FILE` → `DB_PASSWORD_FILE`. |
| 198 | + |
| 199 | +3. The `DB_DEFAULT` JSON blob environment variable is no longer generated — `settings.py` reads individual `DB_*` variables directly. |
| 200 | + |
| 201 | +--- |
| 202 | + |
| 203 | +## Related Documentation |
| 204 | + |
| 205 | +- [Monitoring Setup](docs/monitoring.md) — Prometheus metrics configuration |
| 206 | +- [Notifications](docs/notifications.md) — Email and Discord notification setup |
0 commit comments