2026-06-03 23:51:59 +00:00
|
|
|
# =============================================================================
|
|
|
|
|
# docker-compose.yml — CRM System v1.0 (local testing with PostgreSQL)
|
|
|
|
|
#
|
|
|
|
|
# Use this file to run a full Postgres + crm-app stack locally, e.g. for
|
|
|
|
|
# smoke-testing the Docker image or running the backend against a real
|
|
|
|
|
# PostgreSQL instance before deploying to Coolify.
|
|
|
|
|
#
|
|
|
|
|
# Production deploys in Coolify use COOLIFY_SETUP.md (single-container app +
|
|
|
|
|
# a Coolify-managed Postgres database), NOT this file.
|
|
|
|
|
#
|
|
|
|
|
# Usage:
|
|
|
|
|
# cp .env.docker.example .env.docker
|
|
|
|
|
# $EDITOR .env.docker # fill AUTH_SECRET, POSTGRES_PASSWORD, ...
|
|
|
|
|
# docker compose --env-file .env.docker up --build
|
|
|
|
|
# curl http://localhost:8000/health
|
|
|
|
|
# =============================================================================
|
|
|
|
|
|
|
|
|
|
services:
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
# PostgreSQL 16 (Alpine) — local Postgres for development / smoke tests.
|
|
|
|
|
# Coolify will provision its own managed Postgres database in production.
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
postgres:
|
|
|
|
|
image: postgres:16-alpine
|
|
|
|
|
container_name: crm-postgres
|
|
|
|
|
restart: unless-stopped
|
|
|
|
|
environment:
|
|
|
|
|
POSTGRES_USER: ${POSTGRES_USER:-crm_user}
|
|
|
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}
|
|
|
|
|
POSTGRES_DB: ${POSTGRES_DB:-crm_db}
|
|
|
|
|
PGDATA: /var/lib/postgresql/data/pgdata
|
|
|
|
|
volumes:
|
|
|
|
|
- pgdata:/var/lib/postgresql/data
|
|
|
|
|
ports:
|
|
|
|
|
- "5432:5432" # local-only convenience; remove for CI / prod-like runs
|
|
|
|
|
healthcheck:
|
|
|
|
|
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-crm_user} -d ${POSTGRES_DB:-crm_db}"]
|
|
|
|
|
interval: 10s
|
|
|
|
|
timeout: 5s
|
|
|
|
|
retries: 5
|
|
|
|
|
start_period: 10s
|
|
|
|
|
networks:
|
|
|
|
|
- crm-net
|
|
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
# CRM App — built from the local Dockerfile.
|
|
|
|
|
# NOTE: no `image:` directive — we build from source on `docker compose up`.
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
crm-app:
|
|
|
|
|
build:
|
|
|
|
|
context: .
|
|
|
|
|
dockerfile: Dockerfile
|
|
|
|
|
container_name: crm-app
|
|
|
|
|
restart: unless-stopped
|
|
|
|
|
depends_on:
|
|
|
|
|
postgres:
|
|
|
|
|
condition: service_healthy
|
2026-07-25 21:03:46 +02:00
|
|
|
redis:
|
|
|
|
|
condition: service_healthy
|
2026-06-03 23:51:59 +00:00
|
|
|
environment:
|
|
|
|
|
# Use the internal docker-compose DNS name "postgres" (NOT localhost)
|
|
|
|
|
DATABASE_URL: ${DATABASE_URL:?DATABASE_URL is required}
|
2026-07-25 21:03:46 +02:00
|
|
|
REDIS_URL: ${REDIS_URL:-redis://:${REDIS_PASSWORD:-changeme}@redis:6379/0}
|
|
|
|
|
SECRET_KEY: ${SECRET_KEY:?SECRET_KEY is required (min 32 chars)}
|
2026-06-03 23:51:59 +00:00
|
|
|
# Frontend served from same origin in production; allow local dev hosts too
|
|
|
|
|
CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost:8000,http://localhost:5173}
|
|
|
|
|
ENVIRONMENT: ${ENVIRONMENT:-production}
|
|
|
|
|
LOG_LEVEL: ${LOG_LEVEL:-INFO}
|
2026-07-25 21:03:46 +02:00
|
|
|
SESSION_COOKIE_SECURE: ${SESSION_COOKIE_SECURE:-true}
|
|
|
|
|
STORAGE_PATH: ${STORAGE_PATH:-/data/storage}
|
2026-06-03 23:51:59 +00:00
|
|
|
BCRYPT_ROUNDS: ${BCRYPT_ROUNDS:-12}
|
|
|
|
|
ports:
|
|
|
|
|
- "8000:8000"
|
2026-07-25 21:03:46 +02:00
|
|
|
volumes:
|
|
|
|
|
- storage:/data/storage
|
|
|
|
|
healthcheck:
|
|
|
|
|
test: ["CMD", "curl", "-fsS", "http://localhost:8000/api/v1/health"]
|
|
|
|
|
interval: 30s
|
|
|
|
|
timeout: 10s
|
|
|
|
|
retries: 3
|
|
|
|
|
start_period: 15s
|
|
|
|
|
networks:
|
|
|
|
|
- crm-net
|
|
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
# CRM Worker — ARQ background worker (same image, different entrypoint).
|
|
|
|
|
# Runs migrations? No — the API container handles migrations.
|
|
|
|
|
# Scale with `docker compose up --scale crm-worker=N`.
|
|
|
|
|
# Cron jobs use a Redis-based distributed lock so only one replica fires.
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
crm-worker:
|
|
|
|
|
build:
|
|
|
|
|
context: .
|
|
|
|
|
dockerfile: Dockerfile
|
|
|
|
|
container_name: crm-worker
|
|
|
|
|
restart: unless-stopped
|
|
|
|
|
entrypoint: ["/app/worker.sh"]
|
|
|
|
|
depends_on:
|
|
|
|
|
postgres:
|
|
|
|
|
condition: service_healthy
|
|
|
|
|
redis:
|
|
|
|
|
condition: service_healthy
|
|
|
|
|
environment:
|
|
|
|
|
DATABASE_URL: ${DATABASE_URL:?DATABASE_URL is required}
|
|
|
|
|
REDIS_URL: ${REDIS_URL:-redis://:${REDIS_PASSWORD:-changeme}@redis:6379/0}
|
|
|
|
|
SECRET_KEY: ${SECRET_KEY:?SECRET_KEY is required (min 32 chars)}
|
|
|
|
|
ENVIRONMENT: ${ENVIRONMENT:-production}
|
|
|
|
|
LOG_LEVEL: ${LOG_LEVEL:-INFO}
|
|
|
|
|
STORAGE_PATH: ${STORAGE_PATH:-/data/storage}
|
|
|
|
|
BCRYPT_ROUNDS: ${BCRYPT_ROUNDS:-12}
|
|
|
|
|
volumes:
|
|
|
|
|
- storage:/data/storage
|
2026-06-03 23:51:59 +00:00
|
|
|
healthcheck:
|
2026-07-25 21:03:46 +02:00
|
|
|
# Check if the ARQ worker process is alive
|
|
|
|
|
test: ["CMD-SHELL", "pgrep -f \"arq app.core.worker.WorkerSettings\" || exit 1"]
|
2026-06-03 23:51:59 +00:00
|
|
|
interval: 30s
|
|
|
|
|
timeout: 10s
|
|
|
|
|
retries: 3
|
|
|
|
|
start_period: 15s
|
|
|
|
|
networks:
|
|
|
|
|
- crm-net
|
|
|
|
|
|
2026-07-25 21:03:46 +02:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
# Redis 7 (Alpine) — sessions, rate limiting, ARQ queue.
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
redis:
|
|
|
|
|
image: redis:7-alpine
|
|
|
|
|
container_name: crm-redis
|
|
|
|
|
restart: unless-stopped
|
|
|
|
|
command: redis-server --requirepass ${REDIS_PASSWORD:-changeme}
|
|
|
|
|
volumes:
|
|
|
|
|
- redisdata:/data
|
|
|
|
|
ports:
|
|
|
|
|
- "6379:6379" # local-only convenience; remove for prod-like runs
|
|
|
|
|
healthcheck:
|
|
|
|
|
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD:-changeme}", "ping"]
|
|
|
|
|
interval: 10s
|
|
|
|
|
timeout: 5s
|
|
|
|
|
retries: 5
|
|
|
|
|
networks:
|
|
|
|
|
- crm-net
|
|
|
|
|
|
2026-06-03 23:51:59 +00:00
|
|
|
volumes:
|
|
|
|
|
pgdata:
|
|
|
|
|
name: crm_pgdata
|
2026-07-25 21:03:46 +02:00
|
|
|
redisdata:
|
|
|
|
|
name: crm_redisdata
|
|
|
|
|
storage:
|
|
|
|
|
name: crm_storage
|
2026-06-03 23:51:59 +00:00
|
|
|
|
|
|
|
|
networks:
|
|
|
|
|
crm-net:
|
|
|
|
|
name: crm-net
|
|
|
|
|
driver: bridge
|