- Updated database configuration to switch from SQLite to PostgreSQL, including changes to alembic.ini, Docker Compose, and environment settings. - Refactored application code to utilize PostgreSQL database adapters, ensuring compatibility with the new database structure. - Enhanced API routes and data handling to support the new database, including adjustments in data models and query logic. - Introduced new job processing mechanisms for full synchronization of AMO CRM entities, leveraging FastStream for background tasks. - Improved logging and error handling across the application to facilitate better monitoring and debugging. - Removed obsolete SQLite adapter files and migrations, streamlining the project structure for PostgreSQL integration.
160 lines
4.3 KiB
YAML
160 lines
4.3 KiB
YAML
version: '3.8'
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
ports:
|
|
- "5432:5432"
|
|
environment:
|
|
- POSTGRES_DB=amo_data
|
|
- POSTGRES_USER=amo_user
|
|
- POSTGRES_PASSWORD=amo_password
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
restart: unless-stopped
|
|
networks:
|
|
- amo-network
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U amo_user -d amo_data"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 10s
|
|
|
|
app:
|
|
build: .
|
|
ports:
|
|
- "8000:8000"
|
|
environment:
|
|
- DATABASE_URL=postgresql://amo_user:amo_password@postgres:5432/amo_data
|
|
- REDIS_URL=redis://redis:6379/0
|
|
- AMO_CRM_DOMAIN=${AMO_CRM_DOMAIN}
|
|
- AMO_CRM_ACCESS_TOKEN=${AMO_CRM_ACCESS_TOKEN}
|
|
- GOOGLE_SERVICE_ACCOUNT_FILE=${GOOGLE_SERVICE_ACCOUNT_FILE}
|
|
- GOOGLE_SCOPES=${GOOGLE_SCOPES}
|
|
- API_V1_STR=/api/v1
|
|
- LOG_LEVEL=INFO
|
|
volumes:
|
|
- ./data:/app/data
|
|
- ./credentials:/app/credentials:ro
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
networks:
|
|
- amo-network
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import requests; requests.get('http://localhost:8000/health')"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 40s
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
ports:
|
|
- "6379:6379"
|
|
volumes:
|
|
- redis_data:/data
|
|
restart: unless-stopped
|
|
networks:
|
|
- amo-network
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 30s
|
|
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
|
|
|
|
faststream-worker:
|
|
build: .
|
|
command: uv run faststream run workers.broker:app --workers 2
|
|
environment:
|
|
- DATABASE_URL=postgresql://amo_user:amo_password@postgres:5432/amo_data
|
|
- REDIS_URL=redis://redis:6379/0
|
|
- AMO_CRM_DOMAIN=${AMO_CRM_DOMAIN}
|
|
- AMO_CRM_ACCESS_TOKEN=${AMO_CRM_ACCESS_TOKEN}
|
|
- GOOGLE_SERVICE_ACCOUNT_FILE=${GOOGLE_SERVICE_ACCOUNT_FILE}
|
|
- GOOGLE_SCOPES=${GOOGLE_SCOPES}
|
|
- API_V1_STR=/api/v1
|
|
- API_BASE_URL=http://app:8000
|
|
- LOG_LEVEL=INFO
|
|
- WORKER_ID=faststream-worker-1
|
|
volumes:
|
|
- ./data:/app/data
|
|
- ./credentials:/app/credentials:ro
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
networks:
|
|
- amo-network
|
|
healthcheck:
|
|
test: ["CMD", "sh", "-c", "pgrep -f 'faststream run' || exit 1"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 1
|
|
start_period: 10s
|
|
|
|
faststream-scheduler:
|
|
build: .
|
|
command: uv run python workers/scheduler.py
|
|
environment:
|
|
- DATABASE_URL=postgresql://amo_user:amo_password@postgres:5432/amo_data
|
|
- REDIS_URL=redis://redis:6379/0
|
|
- AMO_CRM_DOMAIN=${AMO_CRM_DOMAIN}
|
|
- AMO_CRM_ACCESS_TOKEN=${AMO_CRM_ACCESS_TOKEN}
|
|
- GOOGLE_SERVICE_ACCOUNT_FILE=${GOOGLE_SERVICE_ACCOUNT_FILE}
|
|
- GOOGLE_SCOPES=${GOOGLE_SCOPES}
|
|
- API_V1_STR=/api/v1
|
|
- API_BASE_URL=http://app:8000
|
|
- LOG_LEVEL=INFO
|
|
- WORKER_ID=faststream-scheduler-1
|
|
volumes:
|
|
- ./data:/app/data
|
|
- ./credentials:/app/credentials:ro
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
faststream-worker:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
networks:
|
|
- amo-network
|
|
healthcheck:
|
|
test: ["CMD", "sh", "-c", "pgrep -f 'python workers/scheduler.py' || exit 1"]
|
|
interval: 60s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 90s
|
|
|
|
migrations:
|
|
build: .
|
|
command: sh -c "echo 'Waiting for PostgreSQL...' && sleep 5 && echo 'Running migrations...' && uv run alembic upgrade head && echo 'Migrations completed successfully!'"
|
|
environment:
|
|
- DATABASE_URL=postgresql://amo_user:amo_password@postgres:5432/amo_data
|
|
- LOG_LEVEL=INFO
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
networks:
|
|
- amo-network
|
|
profiles:
|
|
- tools
|
|
restart: "no"
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|
|
|
|
networks:
|
|
amo-network:
|
|
driver: bridge
|