From 27113a625aea7a8af01ee66b08e4171e74f560a7 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 15 Dec 2025 15:10:20 -0600 Subject: [PATCH] Support multiple instances (prod/dev) on same server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add COMPOSE_PROJECT_NAME for unique container names - Add BACKEND_PORT for configurable port mapping - Update deploy.sh to export variables for docker compose - Update health checks to use configured port Allows running prod and dev instances simultaneously by cloning the repo twice with different .env.deploy configurations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .env.deploy.example | 16 +++++++++++++++- deploy.sh | 14 ++++++++++---- docker-compose.yml | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.env.deploy.example b/.env.deploy.example index d4a9f4a..408da9c 100644 --- a/.env.deploy.example +++ b/.env.deploy.example @@ -1,11 +1,25 @@ # ModComms Deployment Configuration # Copy this file to .env.deploy and update with your server values +# +# For running prod and dev on the same server, clone the repo twice: +# /opt/modcomms-prod/ - production (main branch) +# /opt/modcomms-dev/ - development (develop branch) +# Then configure each .env.deploy with different values below. + +# Docker project name (creates unique container names) +# Examples: modcomms-prod, modcomms-dev +COMPOSE_PROJECT_NAME=modcomms-prod + +# Backend port (must be unique per instance) +# Examples: 8000 for prod, 8001 for dev +BACKEND_PORT=8000 # Frontend deployment directory (Apache document root) +# Examples: /var/www/modcomms-prod, /var/www/modcomms-dev FRONTEND_DEPLOY_DIR=/var/www/html/modcomms # Backend URLs (used during frontend build) -# These should match your production domain +# These should match your domain/vhost configuration VITE_BACKEND_WS_URL=wss://your-domain.com/ws/analyze VITE_BACKEND_URL=https://your-domain.com diff --git a/deploy.sh b/deploy.sh index e606826..e3632c7 100755 --- a/deploy.sh +++ b/deploy.sh @@ -43,6 +43,11 @@ if [ -z "$FRONTEND_DEPLOY_DIR" ]; then exit 1 fi +# Export variables for docker compose +export COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-modcomms}" +export BACKEND_PORT="${BACKEND_PORT:-8000}" +echo " Environment: ${COMPOSE_PROJECT_NAME} (port ${BACKEND_PORT})" + # --- Check backend/.env exists (required for GEMINI_API_KEY) --- if [ ! -f backend/.env ]; then if [ -f backend/.env.example ]; then @@ -134,7 +139,7 @@ docker compose up -d # Wait for health check echo " Waiting for backend to be healthy..." for i in {1..30}; do - if curl -sf http://localhost:8000/health > /dev/null 2>&1; then + if curl -sf "http://localhost:${BACKEND_PORT}/health" > /dev/null 2>&1; then echo " ✓ Backend is healthy" break fi @@ -150,10 +155,11 @@ echo "=========================================" echo " Deployment Complete!" echo "=========================================" echo "" -echo "Frontend: ${FRONTEND_DEPLOY_DIR}" -echo "Backend: http://localhost:8000" +echo "Environment: ${COMPOSE_PROJECT_NAME}" +echo "Frontend: ${FRONTEND_DEPLOY_DIR}" +echo "Backend: http://localhost:${BACKEND_PORT}" echo "" docker compose ps --format "table {{.Name}}\t{{.Status}}\t{{.Ports}}" echo "" echo "Health check:" -curl -s http://localhost:8000/health && echo "" || echo "Warning: Backend not responding" +curl -s "http://localhost:${BACKEND_PORT}/health" && echo "" || echo "Warning: Backend not responding" diff --git a/docker-compose.yml b/docker-compose.yml index b72f100..7321ecd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: context: . dockerfile: backend/Dockerfile ports: - - "8000:8000" + - "${BACKEND_PORT:-8000}:8000" env_file: - backend/.env environment: