services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: prolytics_app
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    command: tail -f /dev/null
    networks:
      - prolytics_network
    environment:
      - COMPOSER_ALLOW_SUPERUSER=1
      # Database connection to local MySQL service
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=williamfebricdev
      - DB_USERNAME=williamfebricdev
      - DB_PASSWORD=sNVTTTBI(K8TMKDFktH
      - REDIS_HOST=redis
      - REDIS_PORT=6379
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started

  web:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: prolytics_web
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    ports:
      - "8000:8000"
    networks:
      - prolytics_network
    environment:
      - COMPOSER_ALLOW_SUPERUSER=1
      # Database connection to local MySQL service
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=williamfebricdev
      - DB_USERNAME=williamfebricdev
      - DB_PASSWORD=sNVTTTBI(K8TMKDFktH
      - REDIS_HOST=redis
      - REDIS_PORT=6379
    command: php artisan serve --host=0.0.0.0 --port=8000
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started

  composer:
    image: composer:latest
    container_name: prolytics_composer
    working_dir: /app
    volumes:
      - .:/app
      - composer_cache:/tmp/cache
    networks:
      - prolytics_network
    command: install --ignore-platform-reqs --no-interaction --prefer-dist

  mysql:
    image: mysql:8.0
    container_name: prolytics_mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: williamfebricdev
      MYSQL_ROOT_PASSWORD: root
      MYSQL_PASSWORD: sNVTTTBI(K8TMKDFktH
      MYSQL_USER: williamfebricdev
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - prolytics_network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot"]
      timeout: 20s
      retries: 10

  redis:
    image: redis:7-alpine
    container_name: prolytics_redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    networks:
      - prolytics_network

  mysql_sample1:
    image: mysql:8.0
    container_name: prolytics_mysql_sample1
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: sample_db_1
      MYSQL_ROOT_PASSWORD: root
      MYSQL_PASSWORD: sample123
      MYSQL_USER: sample_user1
    ports:
      - "3307:3306"
    volumes:
      - mysql_sample1_data:/var/lib/mysql
      - ./docker/mysql-init/sample1:/docker-entrypoint-initdb.d
    networks:
      - prolytics_network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot"]
      timeout: 20s
      retries: 10

  mysql_sample2:
    image: mysql:8.0
    container_name: prolytics_mysql_sample2
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: sample_db_2
      MYSQL_ROOT_PASSWORD: root
      MYSQL_PASSWORD: sample456
      MYSQL_USER: sample_user2
    ports:
      - "3308:3306"
    volumes:
      - mysql_sample2_data:/var/lib/mysql
      - ./docker/mysql-init/sample2:/docker-entrypoint-initdb.d
    networks:
      - prolytics_network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot"]
      timeout: 20s
      retries: 10

volumes:
  mysql_data:
  mysql_sample1_data:
  mysql_sample2_data:
  composer_cache:

networks:
  prolytics_network:
    driver: bridge
