services:
  # PostgreSQL база данных
  db:
    image: postgres:15-alpine
    container_name: mix_postgres
    restart: unless-stopped
    env_file:
      - /Volume1/DockerAppsData/mixapp/app/myproject/docker/.env.docker
    volumes:
      - /Volume1/DockerAppsData/mixapp/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-postgres} -d ${DB_NAME:-inventory_db}"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s
    networks:
      - mix_network

  # Redis для кеша и Celery брокера
  redis:
    image: redis:7-alpine
    container_name: mix_redis
    restart: unless-stopped
    command: redis-server --appendonly yes
    volumes:
      - /Volume1/DockerAppsData/mixapp/redis:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - mix_network

  # Django Web приложение
  web:
    build:
      context: /Volume1/DockerAppsData/mixapp/app/myproject
      dockerfile: docker/Dockerfile
    image: mix_web:latest
    container_name: mix_web
    restart: unless-stopped
    command: web
    env_file:
      - /Volume1/DockerAppsData/mixapp/app/myproject/docker/.env.docker
    volumes:
      # ВАЖНО: монтируем именно папку проекта в /myproject, чтобы /app/manage.py существовал
      - /Volume1/DockerAppsData/mixapp/app/myproject:/app
      # Медиа и статика (как ожидает Django)
      - /Volume1/DockerAppsData/mixapp/media:/app/myproject/media
      - /Volume1/DockerAppsData/mixapp/static:/app/myproject/staticfiles
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - mix_network
      - proxy-net

  # Celery Worker
  celery-worker:
    build:
      context: /Volume1/DockerAppsData/mixapp/app/myproject
      dockerfile: docker/Dockerfile
    image: mix_celery:latest
    container_name: mix_celery_worker
    restart: unless-stopped
    command: celery-worker
    env_file:
      - /Volume1/DockerAppsData/mixapp/app/myproject/docker/.env.docker
    volumes:
      - /Volume1/DockerAppsData/mixapp/app/myproject:/app
      - /Volume1/DockerAppsData/mixapp/media:/app/myproject/media
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - mix_network

  # Celery Beat
  celery-beat:
    build:
      context: /Volume1/DockerAppsData/mixapp/app/myproject
      dockerfile: docker/Dockerfile
    image: mix_celery:latest
    container_name: mix_celery_beat
    restart: unless-stopped
    command: celery-beat
    env_file:
      - /Volume1/DockerAppsData/mixapp/app/myproject/docker/.env.docker
    volumes:
      - /Volume1/DockerAppsData/mixapp/app/myproject:/app
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - mix_network

networks:
  mix_network:
    driver: bridge

  proxy-net:
    external: true
    name: proxy-net