Dominion/COOLIFY.md

71 lines
3.4 KiB
Markdown
Raw Normal View History

2026-08-07 09:38:37 +00:00
# Coolify & PostgreSQL Deployment Guide
2026-08-07 09:28:35 +00:00
2026-08-07 09:38:37 +00:00
This application consists of:
2026-08-07 10:35:45 +00:00
1. **Server Side**: Node.js + Express backend (`server.ts`) serving REST APIs, managing authentication, ledger reconciliation, audit logs, FX rates, SMTP dispatching, and financial reports.
2026-08-07 09:48:18 +00:00
2. **Database**: PostgreSQL (via `pg` connection pool) with automatic JSON fallback backup.
2026-08-07 09:38:37 +00:00
3. **Frontend**: React SPA served directly via Express in production.
2026-08-07 09:28:35 +00:00
---
2026-08-07 09:38:37 +00:00
## 1. Quick Coolify Deployment Options
2026-08-07 09:28:35 +00:00
2026-08-07 09:38:37 +00:00
### Option A: Docker Compose Deployment (Application + PostgreSQL in One Stack)
2026-08-07 09:28:35 +00:00
2026-08-07 09:38:37 +00:00
1. **In Coolify Dashboard**:
- Click **+ Add Resource** -> **Docker Compose**.
- Point to your Git Repository or paste the contents of `docker-compose.yml`.
2. **Environment Variables**:
Add the following in Coolify:
```env
NODE_ENV=production
PORT=3000
POSTGRES_PASSWORD=your_custom_secure_password
2026-08-07 10:35:45 +00:00
# SMTP Email Dispatch Settings
SMTP_HOST=smtp.your-server.com
SMTP_PORT=587
SMTP_USER=alerts@networkbank.com
SMTP_PASS=your_smtp_password
SMTP_FROM="Balance Sheet Portal <noreply@networkbank.com>"
SMTP_USE_TLS=true
2026-08-07 09:38:37 +00:00
```
3. **Deploy**:
2026-08-07 13:58:55 +00:00
- Coolify will build the app container and spin up a dedicated `postgres:16-alpine` database container with health checks and persistent volume storage (`balance_sheet_postgres_data`). The application uses `expose: "3000"` to avoid host port binding conflicts while allowing Coolify's reverse proxy (Traefik/Nginx) to route external web traffic.
2026-08-07 09:28:35 +00:00
---
2026-08-07 09:38:37 +00:00
### Option B: Coolify Managed PostgreSQL + Standalone App Container
2026-08-07 09:28:35 +00:00
2026-08-07 09:38:37 +00:00
If you prefer using Coolify's built-in managed PostgreSQL database resource:
1. **Create Database in Coolify**:
- Click **+ Add Resource** -> **PostgreSQL**.
- Coolify will provide an internal database connection URL (e.g., `postgresql://postgres:pass@coolify-postgres-host:5432/balance_sheet_db`).
2. **Deploy App Service**:
- Add your Git repo as a **Dockerfile** application.
- Set environment variable in Coolify UI:
2026-08-07 09:28:35 +00:00
```env
2026-08-07 09:38:37 +00:00
DATABASE_URL=postgresql://postgres:pass@coolify-postgres-host:5432/balance_sheet_db
2026-08-07 09:28:35 +00:00
PORT=3000
2026-08-07 10:35:45 +00:00
# SMTP Email Settings
SMTP_HOST=smtp.your-server.com
SMTP_PORT=587
SMTP_USER=alerts@networkbank.com
SMTP_PASS=your_smtp_password
2026-08-07 09:28:35 +00:00
```
2026-08-07 09:38:37 +00:00
3. **Deploy**:
- The Express server will automatically connect to the PostgreSQL database, create the necessary table structures on boot, and store all portal state in PostgreSQL.
2026-08-07 09:28:35 +00:00
---
2026-08-07 10:35:45 +00:00
## 2. Server-Side Architecture & Configuration
2026-08-07 09:28:35 +00:00
2026-08-07 13:58:55 +00:00
- **Internal Container Port**: Application listens on `3000` inside the container (`EXPOSE 3000`).
- **Conflict Prevention**: Uses Docker Compose `expose` (`3000` for app, `5432` for postgres) instead of direct host port bindings to eliminate host interface port allocation conflicts.
2026-08-07 10:35:45 +00:00
- **SMTP Environment Overrides**: SMTP configuration (`SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASS`, `SMTP_FROM`, `SMTP_USE_TLS`) is fully managed via environment variables.
2026-08-07 09:38:37 +00:00
- **Automatic Table Creation**: On server boot, the backend runs `initPgDatabase()` to verify/create `app_portal_state`.
2026-08-07 09:48:18 +00:00
- **Automatic State Recovery**: If PostgreSQL contains existing data, portal state is loaded directly from PostgreSQL.
2026-08-07 09:38:37 +00:00
- **Resilient Fallback**: If `DATABASE_URL` is omitted, the app gracefully operates using persistent JSON storage (`/app/data/portal-data.json`).
- **Health Check**: Express exposes `GET /api/health` for Docker container monitoring.