feat: add Coolify deployment proxy

Route the Coolify HTTPS domain through an internal Nginx proxy to Next.js and Socket.IO. Keep app/backing services private, preserve local development socket URLs, and document Coolify Compose setup.
This commit is contained in:
i vib committed 2026-10-23 20:53:34 -07:00
1 parent fcc4f4db2d
commit e52e25e990
6 files changed
+92 -21

No files matched your search

+9 -10
View File
@@ -48,17 +48,16 @@ npm run server
## Production Containers ## Production Containers
Docker Compose builds the standalone Next.js web image and the separate Socket.IO ingestion image. Docker Engine with the Compose plugin is required. ## Coolify Deployment
1. Copy `.env.example` to `.env` and set unique values for `DATASTACK_JWT_SECRET`, `DATASTACK_ADMIN_SESSION_SECRET`, `DATASTACK_ADMIN_EMAIL`, `DATASTACK_ADMIN_PASSWORD`, `DATABASE_URL`, and `POSTGRES_PASSWORD`. Keep `.env` private and out of source control. The repository includes a Docker Compose stack for a Coolify Git-based Docker Compose application. Coolify must be installed on a VPS with a domain and HTTPS configured.
`DATABASE_URL` must use the `postgres` service host and a password matching `POSTGRES_PASSWORD`.
2. From the repository root, validate and start the stack:
```powershell 1. In Coolify, add a Docker Compose application from `https://gitlab.com/ivibtools/datastack.git`, branch `main`.
docker compose --env-file .env -f docker/docker-compose.yml config 2. Set Base Directory to `/` and Docker Compose Location to `docker/docker-compose.yml`.
docker compose --env-file .env -f docker/docker-compose.yml up --build -d 3. Add the required variables in the Coolify application's Environment Variables: `DATASTACK_JWT_SECRET`, `DATASTACK_ADMIN_SESSION_SECRET`, `DATASTACK_ADMIN_EMAIL`, `DATASTACK_ADMIN_PASSWORD`, `DATABASE_URL`, and `POSTGRES_PASSWORD`. Use unique secrets; `DATABASE_URL` must use host `postgres`, database `datastack_db`, user `datastack`, and a password matching `POSTGRES_PASSWORD`.
``` 4. In Domains, add the public HTTPS domain to service `proxy` on internal port `80`. Do not expose `web`, `ingestion`, Redis, or PostgreSQL directly. Coolify supplies proxy labels for the selected service.
5. Deploy and check service health and runtime logs in Coolify.
The web console is published on port 3000 and the ingestion service on port 4000. Redis and PostgreSQL are private to the Compose network. CSV files written by the ingestion container persist in the `datastack-data` named volume; PostgreSQL metadata persists in `pgdata`. The proxy sends `/` to Next.js and `/socket.io/` to the Socket.IO service over the private Compose network. The Settings page uses the current origin for a deployed WebSocket URL; local development on port 3000 still displays port 4000.
The current web process still has a separate in-memory buffer and container-local storage view. Redis and Prisma/PostgreSQL are not yet used by application code, and the web process does not yet read the ingestion volume. Cross-process event visibility and shared storage are Phase P4 work; metadata persistence is Phase P5 work. Do not treat this Compose stack as production-ready until those phases and runtime checks are complete. The `datastack-data` named volume persists CSVs written by ingestion. The web process does not yet read that volume; Redis and Prisma/PostgreSQL are not yet used by application code. Cross-process event visibility/shared storage remains Phase P4 work and metadata persistence remains Phase P5 work. Coolify deployment does not resolve those production-readiness gaps, and this stack has not yet been built or deployed on a Coolify VPS from this environment.
+6 -1
View File
@@ -58,7 +58,12 @@ export function SettingsWorkspace() {
useEffect(() => { useEffect(() => {
setBaseUrl(window.location.origin); setBaseUrl(window.location.origin);
setWebSocketUrl(`${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.hostname}:4000`); const isLocalDev = window.location.port === '3000';
const socketProtocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
const socketHost = isLocalDev
? `${window.location.hostname}:4000`
: window.location.host;
setWebSocketUrl(`${socketProtocol}://${socketHost}`);
Promise.all([ Promise.all([
fetch('/api/settings').then(async (response) => { fetch('/api/settings').then(async (response) => {
+3
View File
@@ -0,0 +1,3 @@
FROM nginx:stable-alpine
COPY docker/coolify-nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
+42
View File
@@ -0,0 +1,42 @@
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream nextjs_upstream {
server web:3000;
}
upstream socketio_upstream {
server ingestion:4000;
}
server {
listen 80;
server_name _;
client_max_body_size 50M;
location /socket.io/ {
proxy_pass http://socketio_upstream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
proxy_buffering off;
}
location / {
proxy_pass http://nextjs_upstream;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
}
}
+24 -4
View File
@@ -4,8 +4,8 @@ services:
build: build:
context: .. context: ..
dockerfile: docker/Dockerfile.web dockerfile: docker/Dockerfile.web
ports: expose:
- "3000:3000" - "3000"
environment: environment:
NODE_ENV: production NODE_ENV: production
PORT: "3000" PORT: "3000"
@@ -33,8 +33,8 @@ services:
build: build:
context: .. context: ..
dockerfile: docker/Dockerfile.server dockerfile: docker/Dockerfile.server
ports: expose:
- "4000:4000" - "4000"
volumes: volumes:
- datastack-data:/app/storage - datastack-data:/app/storage
environment: environment:
@@ -55,6 +55,26 @@ services:
retries: 3 retries: 3
start_period: 10s start_period: 10s
# Coolify routes the public domain to this service on its internal port 80.
proxy:
build:
context: ..
dockerfile: docker/Dockerfile.proxy
expose:
- "80"
depends_on:
web:
condition: service_healthy
ingestion:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1/ || exit 1"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
# Reserved for the planned shared buffer integration; not consumed by the current runtime. # Reserved for the planned shared buffer integration; not consumed by the current runtime.
redis: redis:
image: redis:7-alpine image: redis:7-alpine
+8 -6
View File
@@ -6,15 +6,17 @@ Production container definitions for the split architecture:
- `web`: standalone Next.js frontend and admin console on port 3000, running as a non-root user. - `web`: standalone Next.js frontend and admin console on port 3000, running as a non-root user.
- `ingestion`: Express + Socket.IO process on port 4000, running as a non-root user. - `ingestion`: Express + Socket.IO process on port 4000, running as a non-root user.
- `proxy`: Nginx reverse proxy on internal port 80. Coolify routes the public domain to this service; `/socket.io/` is forwarded to ingestion and other paths to web.
- `redis`: private Compose service reserved for the planned shared-buffer integration; current application code does not consume it. - `redis`: private Compose service reserved for the planned shared-buffer integration; current application code does not consume it.
- `postgres`: private Compose service reserved for metadata integration; current application code does not use Prisma at runtime. Collected events must remain in CSV files. - `postgres`: private Compose service reserved for metadata integration; current application code does not use Prisma at runtime. Collected events must remain in CSV files.
## Build and Run ## Coolify Compose Deployment
- Run from the repository root with Docker Engine and the Compose plugin installed. - Create a Git-based Docker Compose application from branch `main`.
- Copy `.env.example` to `.env` and provide non-empty deployment values; Compose deliberately has no committed secret defaults. - Set Base Directory to repository root `/` and Compose Location to `docker/docker-compose.yml`.
- Validate and start with `docker compose --env-file .env -f docker/docker-compose.yml config` and `docker compose --env-file .env -f docker/docker-compose.yml up --build -d`. - Set every required interpolated variable in Coolify: JWT/admin secrets and credentials, `DATABASE_URL`, and `POSTGRES_PASSWORD`.
- Only the web and ingestion ports are published. PostgreSQL and Redis remain private to the Compose network. - Add the public domain to service `proxy` at internal port `80`. Coolify manages proxy labels in its normal Compose mode; do not enable Raw Compose mode or add direct host port mappings.
- The `web`, `ingestion`, Redis, and PostgreSQL services are private on the Compose network. Only the proxy is exposed to Coolify's domain proxy.
- The `datastack-data` named volume persists ingestion CSVs; `pgdata` persists PostgreSQL files. - The `datastack-data` named volume persists ingestion CSVs; `pgdata` persists PostgreSQL files.
- The web container does not yet share/read `datastack-data`, and neither Redis nor PostgreSQL is wired into runtime code. Those are later roadmap phases, so cross-process reads and metadata durability are not established by these images. - The web container does not yet share/read `datastack-data`, and neither Redis nor PostgreSQL is wired into runtime code. Those are later roadmap phases, so cross-process reads and metadata durability are not established by these images.
- Health checks probe the public landing route, ingestion `/health`, Redis ping, and PostgreSQL readiness. These checks do not establish application-level shared-storage readiness. - Health checks probe the web landing route, ingestion `/health`, proxy route, Redis ping, and PostgreSQL readiness. These checks do not establish application-level shared-storage readiness.