Browse Source

feat(docker): make host ports configurable via env vars to avoid port collisions

master
PouyaKhajavi 7 hours ago
parent
commit
e10f3fc3f7
  1. 5
      .env.example
  2. 4
      .gitignore
  3. 9
      deploy.sh
  4. 9
      docker-compose.yml

5
.env.example

@ -1,10 +1,13 @@
# Mode Selection (DEV=true for local dev, DEV=false for live production)
DEV=false
# Server HTTP Port Configuration (Change if port 80 or 8080 is in use by another app)
HTTP_PORT=8080
# Django Settings
DJANGO_SECRET_KEY=generate-a-strong-random-secret-key-here
ALLOWED_HOSTS=localhost,127.0.0.1,YOUR_SERVER_IP
CSRF_TRUSTED_ORIGINS=http://localhost,http://127.0.0.1,http://YOUR_SERVER_IP
CSRF_TRUSTED_ORIGINS=http://localhost,http://127.0.0.1,http://YOUR_SERVER_IP,http://YOUR_SERVER_IP:8080
# Database Configuration (PostgreSQL)
POSTGRES_DB=divar_crawler

4
.gitignore

@ -51,4 +51,6 @@ next-steps.md
scratch/
*divar*.json
# Agent settings
.agents/
.agents/*

9
deploy.sh

@ -16,6 +16,13 @@ if [ ! -f .env ]; then
echo "WARNING: Please edit .env and set your OPENAI_API_KEY and passwords before running!"
fi
# Source .env if exists to read HTTP_PORT
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
PORT="${HTTP_PORT:-8080}"
echo "Pulling latest code changes..."
git pull origin master || true
@ -27,4 +34,4 @@ echo "Checking container statuses..."
docker compose ps
echo "=== Deployment Successful! ==="
echo "Access the application at http://localhost or your server's IP address."
echo "Access the application at http://localhost:${PORT} or http://YOUR_SERVER_IP:${PORT}"

9
docker-compose.yml

@ -8,7 +8,7 @@ services:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
ports:
- "5432:5432"
- "${POSTGRES_HOST_PORT:-5432}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
@ -22,7 +22,7 @@ services:
container_name: divar_redis
restart: unless-stopped
ports:
- "6379:6379"
- "${REDIS_HOST_PORT:-6379}:6379"
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 5s
@ -37,7 +37,7 @@ services:
restart: unless-stopped
command: gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 4
ports:
- "8000:8000"
- "${BACKEND_HOST_PORT:-8000}:8000"
environment:
- REDIS_URL=redis://redis:6379/0
- POSTGRES_HOST=db
@ -101,8 +101,7 @@ services:
container_name: divar_frontend
restart: unless-stopped
ports:
- "80:80"
- "5173:80"
- "${HTTP_PORT:-8080}:80"
depends_on:
- backend

Loading…
Cancel
Save