Files
food-ai/backend/docker-compose.yml
dbastrikin 1aaf20619d refactor: split worker into paid/free via WORKER_PLAN env var
Replace dual-consumer priority WorkerPool with a single consumer per
worker process. WORKER_PLAN=paid|free selects the Kafka topic and
consumer group ID (dish-recognition-paid / dish-recognition-free).

docker-compose now runs worker-paid and worker-free as separate services
for independent scaling. Makefile dev target launches both workers locally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 12:11:14 +02:00

106 lines
3.2 KiB
YAML

services:
kafka:
image: confluentinc/cp-kafka:7.6.0
environment:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_LISTENERS: PLAINTEXT://:9092,EXTERNAL://:9093,CONTROLLER://:9094
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://localhost:9093
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9094
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
CLUSTER_ID: "MkU3OEVBNTcwNTJENDM2Qg"
ports:
- "9092:9092"
- "9093:9093"
healthcheck:
test: ["CMD-SHELL", "kafka-topics --bootstrap-server localhost:9092 --list || exit 1"]
interval: 10s
timeout: 10s
retries: 10
kafka-init:
image: confluentinc/cp-kafka:7.6.0
depends_on:
kafka:
condition: service_healthy
entrypoint: ["/bin/sh", "-c"]
command: |
"kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic ai.recognize.paid --partitions 3 --replication-factor 1 &&
kafka-topics --bootstrap-server kafka:9092 --create --if-not-exists --topic ai.recognize.free --partitions 1 --replication-factor 1"
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: food_ai
POSTGRES_USER: food_ai
POSTGRES_PASSWORD: food_ai_local
ports:
- "5433:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U food_ai -d food_ai"]
interval: 5s
timeout: 5s
retries: 10
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "9090:8080"
environment:
DATABASE_URL: postgres://food_ai:food_ai_local@postgres:5432/food_ai?sslmode=disable
FIREBASE_CREDENTIALS_FILE: /app/firebase-credentials.json
JWT_SECRET: local-dev-secret-change-in-prod
ALLOWED_ORIGINS: http://localhost:3000,http://localhost:9090
KAFKA_BROKERS: kafka:9092
depends_on:
postgres:
condition: service_healthy
kafka:
condition: service_healthy
volumes:
- ./firebase-credentials.json:/app/firebase-credentials.json:ro
worker-paid:
build:
context: .
dockerfile: Dockerfile
command: ["./worker"]
environment:
DATABASE_URL: postgres://food_ai:food_ai_local@postgres:5432/food_ai?sslmode=disable
OPENAI_API_KEY: ${OPENAI_API_KEY}
KAFKA_BROKERS: kafka:9092
WORKER_PLAN: paid
depends_on:
postgres:
condition: service_healthy
kafka-init:
condition: service_completed_successfully
worker-free:
build:
context: .
dockerfile: Dockerfile
command: ["./worker"]
environment:
DATABASE_URL: postgres://food_ai:food_ai_local@postgres:5432/food_ai?sslmode=disable
OPENAI_API_KEY: ${OPENAI_API_KEY}
KAFKA_BROKERS: kafka:9092
WORKER_PLAN: free
depends_on:
postgres:
condition: service_healthy
kafka-init:
condition: service_completed_successfully
volumes:
pgdata: