version: "3.8"

services:
  # --- Database ---
  mysql:
    image: mysql:8.0
    container_name: kanka-mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: kanka_root_pass
      MYSQL_DATABASE: kanka
      MYSQL_USER: kanka
      MYSQL_PASSWORD: kanka_db_pass
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - kanka

  # --- Cache / Queue ---
  redis:
    image: redis:7-alpine
    container_name: kanka-redis
    restart: unless-stopped
    volumes:
      - redis_data:/data
    networks:
      - kanka

  # --- Main Application ---
  app:
    image: kankaio/kanka:latest
    container_name: kanka-app
    restart: unless-stopped
    environment:
      APP_NAME: "The Black Reach"
      APP_ENV: production
      APP_DEBUG: false
      APP_KEY: ""
      APP_URL: http://localhost:8080

      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: kanka
      DB_USERNAME: kanka
      DB_PASSWORD: kanka_db_pass

      REDIS_HOST: redis
      REDIS_PASSWORD: null
      REDIS_PORT: 6379

      QUEUE_CONNECTION: redis
      SESSION_DRIVER: redis
      CACHE_STORE: redis

      MAIL_MAILER: log
    volumes:
      - app_storage:/var/www/html/storage
      - app_public:/var/www/html/public
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - kanka

  # --- Queue Worker ---
  queue:
    image: kankaio/kanka:latest
    container_name: kanka-queue
    restart: unless-stopped
    command: ["php", "artisan", "queue:work", "--sleep=3", "--tries=3"]
    environment:
      APP_NAME: "The Black Reach"
      APP_ENV: production
      APP_DEBUG: false
      APP_KEY: ""
      APP_URL: http://localhost:8080

      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: kanka
      DB_USERNAME: kanka
      DB_PASSWORD: kanka_db_pass

      REDIS_HOST: redis
      REDIS_PASSWORD: null
      REDIS_PORT: 6379

      QUEUE_CONNECTION: redis
      SESSION_DRIVER: redis
      CACHE_STORE: redis

      MAIL_MAILER: log
    volumes:
      - app_storage:/var/www/html/storage
    depends_on:
      - mysql
      - redis
      - app
    networks:
      - kanka

  # --- Scheduler ---
  scheduler:
    image: kankaio/kanka:latest
    container_name: kanka-scheduler
    restart: unless-stopped
    command: ["php", "artisan", "schedule:work"]
    environment:
      APP_NAME: "The Black Reach"
      APP_ENV: production
      APP_DEBUG: false
      APP_KEY: ""
      APP_URL: http://localhost:8080

      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: kanka
      DB_USERNAME: kanka
      DB_PASSWORD: kanka_db_pass

      REDIS_HOST: redis
      REDIS_PASSWORD: null
      REDIS_PORT: 6379

      QUEUE_CONNECTION: redis
      SESSION_DRIVER: redis
      CACHE_STORE: redis

      MAIL_MAILER: log
    volumes:
      - app_storage:/var/www/html/storage
    depends_on:
      - mysql
      - redis
      - app
    networks:
      - kanka

  # --- Web Server ---
  nginx:
    image: nginx:alpine
    container_name: kanka-nginx
    restart: unless-stopped
    ports:
      - "127.0.0.1:8080:80"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - app_public:/var/www/html/public:ro
    depends_on:
      - app
    networks:
      - kanka

volumes:
  mysql_data:
  redis_data:
  app_storage:
  app_public:

networks:
  kanka:
    driver: bridge
