version: '3.8'

services:
  backend:
    build: ../backend
    container_name: backend
    # Пока приложения нет, просто держим контейнер живым, чтобы зайти в консоль
    command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload
    ports:
      - "8000:8000"
    environment:
      # Параметры подключения к БД (внутри сети ticket-network)
      DATABASE_URL: postgresql+asyncpg://admin:your_strong_password@postgres:5432/ticket_db
      REDIS_URL: redis://redis:6379/0
    volumes:
      - ../backend:/app
    env_file:
      - .env
    depends_on:
      - postgres
      - redis
      - rabbitmq
    networks:
      - ticket-network

  worker:
    build: ../backend
    container_name: worker
    command: python worker.py
    env_file:
      - .env
    depends_on:
      - rabbitmq
      - minio
      - postgres
    networks:
      - ticket-network

  frontend:
    build:
      context: ../frontend-client
      dockerfile: Dockerfile
    container_name: frontend
    ports:
      - "3000:3000" # Пробиваем дыру напрямую для дебага
    volumes:
      - ../frontend-client:/app
      - /app/node_modules # Изолируем зависимости контейнера от хоста
    networks:
      - ticket-network

  traefik:
    image: traefik:v3.6
    container_name: traefik
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.httpClientTimeout=300s"
      - "--entrypoints.web.address=:80"
    ports:
      - "8081:80"
      - "8082:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - ticket-network

  postgres:
    image: postgres:15-alpine
    container_name: postgres
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: your_strong_password
      POSTGRES_DB: ticket_db
    ports:
      - "5432:5432" # <-- Добавляем вот это
    volumes:
      - ~/ticket-system/data/postgres:/var/lib/postgresql/data
    networks:
      - ticket-network

  redis:
    image: redis:7-alpine
    container_name: redis
    command: redis-server --save 60 1 --loglevel warning
    volumes:
      - ~/ticket-system/data/redis:/data
    networks:
      - ticket-network

  rabbitmq:
    image: rabbitmq:3-management-alpine
    container_name: rabbitmq
    environment:
      RABBITMQ_DEFAULT_USER: user
      RABBITMQ_DEFAULT_PASS: password
    ports:
      - "15672:15672"
    volumes:
      - ~/ticket-system/data/rabbitmq:/var/lib/rabbitmq
    networks:
      - ticket-network

  minio:
    image: quay.io/minio/minio
    container_name: minio
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadminpassword
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - ~/ticket-system/data/minio:/data
    networks:
      - ticket-network

networks:
  ticket-network:
    driver: bridge
