services:
  postgres:
    image: postgres:16
    container_name: crosspost_db
    restart: unless-stopped
    env_file:
      - .env
    ports:
      - "5432:5432"
    volumes:
      - ${POSTGRES_DIR}:/var/lib/postgresql/data
      - ./server/db/schema.sql:/docker-entrypoint-initdb.d/schema.sql

  redis:
    image: redis:7
    container_name: crosspost_redis
    restart: unless-stopped
    ports:
      - "6379:6379"

  backend:
    build: .
    container_name: crosspost_flask
    volumes:
      - .:/app
      - model_cache:/models
    env_file:
      - .env
    ports:
      - "5000:5000"
    command: flask --app server.app run --host=0.0.0.0 --debug
    depends_on:
      - postgres
      - redis

  worker:
    build: .
    volumes:
      - .:/app
      - model_cache:/models
    container_name: crosspost_worker
    env_file:
      - .env
    command: >
      celery -A server.queue.celery_app.celery worker
      --loglevel=debug
      --pool=solo
    depends_on:
      - postgres
      - redis
    # deploy:
    #   resources:
    #     reservations:
    #       devices:
    #         - driver: nvidia
    #           count: 1
    #           capabilities: [gpu]

  frontend:
    build:
      context: ./frontend
    container_name: crosspost_frontend
    volumes:
      - ./frontend:/app
      - /app/node_modules
    ports:
      - "5173:5173"
    depends_on:
      - backend

volumes:
  model_cache: