version: '3.8'

services:
  # Laravel Application
  app:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    container_name: konza_waste_app
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
      - ./docker/app/php.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - konza_waste_network
    depends_on:
      - mysql
      - redis
    environment:
      - APP_ENV=local
      - APP_DEBUG=true
      - APP_URL=http://localhost:8090
      - DB_CONNECTION=mysql
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=konza_waste_db
      - DB_USERNAME=konza_user
      - DB_PASSWORD=konza_password
      - CACHE_DRIVER=redis
      - SESSION_DRIVER=redis
      - QUEUE_CONNECTION=redis
      - REDIS_HOST=redis
      - REDIS_PASSWORD=null
      - REDIS_PORT=6379

  # Nginx Web Server
  webserver:
    image: nginx:alpine
    container_name: konza_waste_webserver
    restart: unless-stopped
    ports:
      - "8090:80"
    volumes:
      - .:/var/www/html
      - ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
    networks:
      - konza_waste_network
    depends_on:
      - app

  # MySQL Database
  mysql:
    image: mysql:8.0
    container_name: konza_waste_mysql
    restart: unless-stopped
    ports:
      - "3308:3306"
    environment:
      MYSQL_DATABASE: konza_waste_db
      MYSQL_USER: konza_user
      MYSQL_PASSWORD: konza_password
      MYSQL_ROOT_PASSWORD: root_password
    volumes:
      - mysql_data:/var/lib/mysql
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
      - ./docker/mysql/init:/docker-entrypoint-initdb.d
    networks:
      - konza_waste_network
    command: --default-authentication-plugin=mysql_native_password

  # Redis Cache and Session Store
  redis:
    image: redis:7-alpine
    container_name: konza_waste_redis
    restart: unless-stopped
    ports:
      - "6381:6379"
    volumes:
      - redis_data:/data
    networks:
      - konza_waste_network
    command: redis-server --appendonly yes

  # phpMyAdmin for Database Management
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: konza_waste_phpmyadmin
    restart: unless-stopped
    ports:
      - "8091:80"
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      PMA_USER: konza_user
      PMA_PASSWORD: konza_password
      MYSQL_ROOT_PASSWORD: root_password
    networks:
      - konza_waste_network
    depends_on:
      - mysql

  # MailHog for Email Testing
  mailhog:
    image: mailhog/mailhog
    container_name: konza_waste_mailhog
    restart: unless-stopped
    ports:
      - "1026:1025"  # SMTP port
      - "8092:8025"  # Web UI port
    networks:
      - konza_waste_network

  # Queue Worker (Laravel Horizon alternative)
  queue:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    container_name: konza_waste_queue
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    networks:
      - konza_waste_network
    depends_on:
      - mysql
      - redis
    command: php artisan queue:work --verbose --tries=3 --timeout=90
    environment:
      - APP_ENV=local
      - APP_DEBUG=true
      - DB_CONNECTION=mysql
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=konza_waste_db
      - DB_USERNAME=konza_user
      - DB_PASSWORD=konza_password
      - CACHE_DRIVER=redis
      - SESSION_DRIVER=redis
      - QUEUE_CONNECTION=redis
      - REDIS_HOST=redis
      - REDIS_PASSWORD=null
      - REDIS_PORT=6379

networks:
  konza_waste_network:
    driver: bridge

volumes:
  mysql_data:
    driver: local
  redis_data:
    driver: local 