register and sign in pages

This commit is contained in:
2026-09-22 00:50:30 +05:00
parent f313867653
commit 78d04f75d1
96 changed files with 6383 additions and 109 deletions
+38 -47
View File
@@ -1,79 +1,70 @@
# Production deployment
Unified build for the SAR Link portal monorepo. One `compose.yml` builds all
services from the repo root, wiring together the two submodules:
One `compose.yml` builds every service from the repo root:
- **`backend/`** — Django API (gunicorn on `:5000`, static via WhiteNoise)
- **`frontend/`** — Next.js portal (standalone server on `:3000`)
A single **nginx** container is the only published entrypoint. The browser only
ever talks to Next.js; Next.js reaches Django **server-side** over the compose
network (`SARLINK_API_BASE_URL=http://backend:5000`). nginx only exposes
Django's browser-facing surface — the admin, its static assets, and media.
- **`backend/`** — Django API on gunicorn `:5000`, static via WhiteNoise
- **`frontend/`** — Vite SPA, built to static files at image build time
- **`web`** — the only published container: nginx serving the SPA and reverse
proxying the API. No node or bun at runtime.
```
host.com/ -> frontend (Next.js) # incl. its own /api/* route handlers
host.com/admin/ -> backend (Django admin)
host.com/static/ -> backend (WhiteNoise)
host.com/media/ -> nginx (shared `media` volume)
host.com/ -> nginx (SPA, history fallback to index.html)
host.com/api/ -> backend (Django REST API)
host.com/admin/ -> backend (Django admin)
host.com/static/ -> backend (WhiteNoise: admin/DRF assets)
host.com/media/ -> nginx (shared `media` volume)
```
> `/api/` is **not** proxied to Django — it belongs to Next.js (NextAuth etc.).
> Django's own `/api/...` is reached only internally via `SARLINK_API_BASE_URL`.
Because nginx fronts both, the browser sees one origin and there is no CORS in
production.
## Files
| File | Purpose |
| -------------------- | --------------------------------------------------- |
| `compose.yml` | postgres + backend + frontend + nginx |
| `api.Dockerfile` | Django image (collectstatic at build) |
| `frontend.Dockerfile`| Next.js standalone image |
| `nginx.Dockerfile` | nginx + `nginx.conf` |
| `entrypoint.sh` | backend: wait for postgres, `migrate`, then gunicorn|
| `nginx.conf` | front reverse proxy |
| File | Purpose |
| ----------------- | -------------------------------------------------------- |
| `compose.yml` | database + backend + worker + web |
| `api.Dockerfile` | Django image (collectstatic at build) |
| `web.Dockerfile` | node builds `frontend/dist`, nginx serves it |
| `nginx.conf` | SPA + API/admin/static/media routing, asset cache headers |
| `entrypoint.sh` | backend: wait for postgres, `migrate`, then gunicorn |
## Configure
Fill each submodule's `.env` (copy from its `.env.example`); compose reads
`backend/.env` and `frontend/.env`. For the compose network set:
Fill `backend/.env` (copy from `backend/.env.example`). For the compose network:
**`backend/.env`**
```
DJANGO_DEBUG=False
SECRET_KEY=<generate one>
POSTGRES_HOST=database
POSTGRES_PORT=5432
POSTGRES_DATABASE=sarlink
POSTGRES_USER=sarlink
POSTGRES_PASSWORD=changeme
ALLOWED_HOSTS=localhost,127.0.0.1,backend # + your public host
CSRF_TRUSTED_ORIGINS=https://portal.example.com
POSTGRES_PASSWORD=<strong>
ALLOWED_HOSTS=localhost,127.0.0.1,backend,portal.sarlink.net
CSRF_TRUSTED_ORIGINS=https://portal.sarlink.net
FRONTEND_URL=https://portal.sarlink.net
SMS_API_URL=...
SMS_API_KEY=...
```
**`frontend/.env`**
```
SARLINK_API_BASE_URL=http://backend:5000
NEXTAUTH_URL=https://portal.example.com
NEXTAUTH_SECRET=...
```
The `POSTGRES_*` values also feed the `database` service through compose
defaults, so keep them in sync or export them before `up`.
The `POSTGRES_*` values also feed the `database` service (via compose defaults),
so keep them in sync — or export them in the shell before `up`.
The frontend needs no runtime configuration: it calls a relative `/api/...`
which nginx routes to the backend.
## Build & run
```sh
docker compose -f .build/prod/compose.yml up -d --build
```
The published site is on `http://localhost:8080` (remap the `nginx` port in
`compose.yml` behind your TLS terminator). The backend runs migrations on
startup; create an admin user once with:
```sh
docker compose -f .build/prod/compose.yml exec backend python manage.py createsuperuser
```
The site is on `http://localhost:8080`; remap the `web` port behind your TLS
terminator. Migrations run on backend startup.
## Running from published images
The build pushes to `git.shihaam.dev/sarlink/sarlinkportal/{backend,frontend,nginx}`.
To deploy without building, replace each service's `build:` block with its
`image:` and keep the `database`, volumes, `env_file`, and `nginx` port mapping.
The build pushes `git.shihaam.dev/sarlink/sarlinkportal/{backend,web}`. To deploy
without building, replace each service's `build:` block with its `image:` and
keep `database`, the volumes, `env_file` and the `web` port mapping.