Files
crm-system/docker-compose.yml
T
CRM Bot d68d385339 feat(phase-4d): deployment (Dockerfile, compose, coolify-setup, runbook)
- Dockerfile: multi-stage build (python:3.12-slim), non-root appuser (UID 1000),
  HEALTHCHECK on /health (30s/10s/3retries/15s start-period), ENTRYPOINT
  prestart.sh runs alembic upgrade head then uvicorn (1 worker)
- prestart.sh: set -e, alembic upgrade head, exec uvicorn as PID 1
- docker-compose.yml: postgres:16-alpine + crm-app build from local Dockerfile,
  depends_on service_healthy, no 'image:' (build from source)
- .env.docker.example: template (placeholders, NOT real secrets)
- COOLIFY_SETUP.md: deployment guide, domain format https://crm.media-on.de:443
  (port is MANDATORY for Let's Encrypt + Traefik routing), AUTH_SECRET min 32 chars
- .gitignore: allow .env.docker.example template (was matched by .env.*)

118 tests still pass. No backend code touched.
2026-06-03 22:20:43 +00:00

89 lines
3.2 KiB
YAML

# =============================================================================
# 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
environment:
# Use the internal docker-compose DNS name "postgres" (NOT localhost)
DATABASE_URL: ${DATABASE_URL:?DATABASE_URL is required}
AUTH_SECRET: ${AUTH_SECRET:?AUTH_SECRET is required (min 32 chars)}
# 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}
# JWT settings — keep aligned with .env.example
JWT_ALGORITHM: ${JWT_ALGORITHM:-HS256}
JWT_EXPIRY_HOURS: ${JWT_EXPIRY_HOURS:-24}
BCRYPT_ROUNDS: ${BCRYPT_ROUNDS:-12}
ports:
- "8000:8000"
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 15s
networks:
- crm-net
volumes:
pgdata:
name: crm_pgdata
networks:
crm-net:
name: crm-net
driver: bridge