Spaces:
Running

backend / docker-compose.yml
paisaly's picture
Upload 2 files
0ab0f39 verified
Raw History Blame Contribute Delete
3.45 kB
services:
db:
image: "mongo:latest"
container_name: spoo_mongo
restart: always
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: mongouser
MONGO_INITDB_ROOT_PASSWORD: mongouser
volumes:
- mongo-data:/data/db
- mongo-config:/data/configdb
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
redis:
image: "redis:latest" # reccommended by offical docs
container_name: spoo_redis
restart: always
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
app:
build: .
container_name: spoo_app
command: uv run uvicorn app.main:app --host 0.0.0.0 --port 7860 --no-access-log --reload
volumes:
# This mount enables hot reloading for your application code
- .:/app
# This mount masks the host's .venv from overwriting the container's .venv
- /app/.venv
ports:
- "7860:7860"
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
env_file: .env
environment:
- MONGODB_URI=mongodb://mongouser:mongouser@db:27017
- REDIS_URI=redis://redis:6379/0
# ── Click event pipeline (opt-in) ──────────────────────────────────────
# Start with: docker compose --profile click-events up
# And set on the app: CLICK_EVENTS_SINK=stream
# CLICK_EVENTS_QUEUE_REDIS_URI=redis://redis-queue:6379/0
redis-queue:
image: "redis:8-alpine"
container_name: spoo_redis_queue
profiles: ["click-events"]
restart: always
# Queue semantics ≠ cache semantics: noeviction rejects writes instead
# of silently dropping events (the app's sink then falls back to inline
# tracking); AOF bounds crash loss to ~1s of events.
command: >
redis-server
--maxmemory 128mb
--maxmemory-policy noeviction
--appendonly yes
--appendfsync everysec
ports:
- "6380:6379"
volumes:
- redis-queue-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
click-worker:
build: .
container_name: spoo_click_worker
profiles: ["click-events"]
command: >
uv run uvicorn --factory app.workers.click_worker:create_app
--host 0.0.0.0 --port 8001 --no-access-log
ports:
- "8001:8001"
volumes:
- .:/app
- /app/.venv
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
redis-queue:
condition: service_healthy
env_file: .env
environment:
- MONGODB_URI=mongodb://mongouser:mongouser@db:27017
- REDIS_URI=redis://redis:6379/0
- CLICK_EVENTS_SINK=stream
- CLICK_EVENTS_QUEUE_REDIS_URI=redis://redis-queue:6379/0
- CLICK_EVENTS_HOTNESS_ENABLED=true
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:8001/health"]
interval: 15s
timeout: 5s
retries: 3
start_period: 15s
volumes:
mongo-data:
mongo-config:
redis-queue-data: