services:
  fastapi:
    build: .
    container_name: barterflip_prod
    restart: unless-stopped
    env_file:
      - .env.prod
    ports:
      - "8000:8000"
    volumes:
      - ./uploads:/app/uploads
      - ./logs:/app/logs
      - ./AuthKey_5B8Q95X5HY.p8:/app/AuthKey_5B8Q95X5HY.p8:ro
      - ./baterflip-d8ec5-firebase.json:/app/baterflip-d8ec5-firebase.json:ro
    networks:
      - barterflip_network
    depends_on:
      - db
    command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  db:
    image: postgres:15-alpine
    container_name: barterflip_postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: barterflip
      POSTGRES_USER: barterflip
      POSTGRES_PASSWORD: admin*123
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - barterflip_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U barterflip -d barterflip"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: barterflip_redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - barterflip_network

volumes:
  postgres_data:
  redis_data:

networks:
  barterflip_network:
    driver: bridge
