services:

  # MariaDB Service
  ogamex-db:
    image: mariadb:11.3.2-jammy
    container_name: ogamex-db
    restart: unless-stopped
    tty: true
    volumes:
     - ogame-dbdata:/var/lib/mysql
     - ./mysql/my.cnf:/etc/mysql/my.cnf
    # MariaDB port is not exposed to the host machine in production.
    environment:
      MYSQL_DATABASE: laravel
      MYSQL_ROOT_PASSWORD: toor
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks:
      app-network:
        aliases:
          - ogame-db

  # PHP Service
  ogamex-app:
    volumes:
      - ./:/var/www:cached
      - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
    build:
      context: .
      dockerfile: Dockerfile
      args:
        OPCACHE_ENABLE: "1" # Enable opcache in production
    container_name: ogamex-app
    restart: unless-stopped
    tty: true
    environment:
      CONTAINER_ROLE: app
      SERVICE_NAME: app
      SERVICE_TAGS: dev
    working_dir: /var/www
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:9000 || [ $? -eq 56 ]"]
      interval: 10s
      timeout: 6s
      retries: 60
    networks:
      - app-network
    depends_on:
      - ogamex-db

  # Nginx Service
  ogamex-webserver:
    image: nginx:alpine
    container_name: ogamex-webserver
    restart: unless-stopped
    tty: true
    volumes:
      - ./:/var/www:cached
      - ./nginx/conf.d/:/etc/nginx/conf.d/
      - ./nginx/ssl/:/etc/nginx/ssl/
    ports:
      - "80:80"
      - "443:443"
    networks:
      - app-network
    depends_on:
      ogamex-app:
        condition: service_healthy

  # Scheduler
  ogamex-scheduler:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: ogamex-scheduler
    restart: unless-stopped
    volumes:
      - .:/var/www/html
    environment:
      CONTAINER_ROLE: scheduler
    networks:
      - app-network
    depends_on:
      ogamex-app:
        condition: service_healthy

  # Queue
  ogamex-queue-worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: ogamex-queue-worker
    restart: unless-stopped
    volumes:
      - .:/var/www/html
    environment:
      CONTAINER_ROLE: queue
    networks:
      - app-network
    depends_on:
      ogamex-app:
        condition: service_healthy

  # PhpMyAdmin
  ogamex-phpmyadmin:
    image: phpmyadmin
    container_name: ogamex-phpmyadmin
    restart: always
    ports:
      - 8080:80
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=ogame-db
      - UPLOAD_LIMIT=1G
    networks:
      - app-network
    volumes:
      - ./docker/phpmyadmin/.htaccess:/var/www/html/.htaccess

# Docker Networks
networks:
  app-network:
    driver: bridge

# Volumes
volumes:
  ogame-dbdata:
    driver: local
