oliver-sales-ops-platform/deploy/apache-osop.conf.tmpl
DJP ed0746267b deploy: auto-pick free ports + render Apache conf from template
The script bailed when 8003 was taken on the dev server. Per spec, it
should never block on a port clash — find a free port and run with it.

How it picks ports:
- Reads OSOP_DB_PORT / OSOP_REDIS_PORT / OSOP_BACKEND_PORT from .env,
  falling back to defaults 5435 / 6380 / 8003.
- For each, if the preferred port is taken on the host, scans upward in
  a sane range (5435-5499 / 6380-6399 / 8003-8099) for the next free one.
- Persists chosen ports back to .env via an idempotent KEY=VALUE upsert,
  so subsequent deploys keep using the same allocation.
- If our compose project is already running, skips the scan and reuses
  the current ports (re-deploy in place).

Compose port mappings now reference those env vars with defaults:
  127.0.0.1:${OSOP_DB_PORT:-5435}:5432, etc.

Apache config templating:
- deploy/apache-osop.conf.tmpl has __BACKEND_PORT__ placeholder.
- The script renders it to deploy/apache-osop.conf each run with the
  chosen backend port substituted in. The rendered file is gitignored
  (the template is the source of truth in git).
- If the backend port changed (or the Apache vhost doesn't yet Include
  our conf), the script tells the user to reload Apache.

This means a fresh server hits the conflict on 8003 (something else is
listening), the script picks 8004 silently, writes it to .env, renders
apache-osop.conf with 8004, brings the stack up, and tells you to
reload Apache. Re-running the script on the same server keeps 8004.
2026-04-27 16:34:05 -04:00

40 lines
1.5 KiB
Cheetah

# OLIVER Sales Ops Platform — Apache reverse-proxy block (template)
#
# This file is the template. The actual `apache-osop.conf` next to it is
# generated by `deploy/deploy.sh` on every run, with the chosen backend
# port substituted in. apache-osop.conf is gitignored.
#
# Drop into the merged optical-dev.oliver.solutions vhost via Include:
# Include /opt/oliver-sales-ops-platform/deploy/apache-osop.conf
#
# Mirrors the /gsb/ pattern on the same server:
# - Backend FastAPI runs in Docker on 127.0.0.1:__BACKEND_PORT__
# - Frontend is a Vite static build, served straight off the filesystem
# by Apache from /var/www/html/oliver-sales-ops-platform/.
#
# Public URL:
# https://optical-dev.oliver.solutions/oliver-sales-ops-platform/
ProxyTimeout 300
TimeOut 300
# Backend API
ProxyPass /oliver-sales-ops-platform/api/ http://127.0.0.1:__BACKEND_PORT__/api/ timeout=300
ProxyPassReverse /oliver-sales-ops-platform/api/ http://127.0.0.1:__BACKEND_PORT__/api/
# Frontend SPA (built artefacts)
Alias /oliver-sales-ops-platform /var/www/html/oliver-sales-ops-platform
<Directory /var/www/html/oliver-sales-ops-platform>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
# SPA fallback — anything that doesn't match a real file/dir gets index.html
# so React Router can do its thing.
RewriteEngine On
RewriteBase /oliver-sales-ops-platform/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]
</Directory>