services:
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: quiniela-app
    restart: unless-stopped
    working_dir: /var/www/html
    environment:
      APP_ENV: local
      APP_DEBUG: "true"
      APP_URL: http://localhost:8080
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: be
      DB_USERNAME: be
      DB_PASSWORD: be
      CACHE_STORE: redis
      REDIS_CLIENT: phpredis
      REDIS_HOST: redis
      REDIS_PORT: 6379
    volumes:
      - ./:/var/www/html
      - ./docker/php/conf.d/local.ini:/usr/local/etc/php/conf.d/local.ini:ro
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - quiniela

  nginx:
    image: nginx:1.27-alpine
    container_name: quiniela-nginx
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./:/var/www/html:ro
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
      - ./docker/nginx/logs:/var/log/nginx
    depends_on:
      - app
    networks:
      - quiniela

  mysql:
    image: mysql:8.4
    container_name: quiniela-mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: be
      MYSQL_USER: be
      MYSQL_PASSWORD: be
      MYSQL_ROOT_PASSWORD: root
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    volumes:
      - ./docker/mysql/data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 20s
    networks:
      - quiniela

  redis:
    image: redis:7-alpine
    container_name: quiniela-redis
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - ./docker/redis/data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 10
    networks:
      - quiniela

networks:
  quiniela:
    driver: bridge
