services:
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: boleto-inter-pro-app
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - ./:/var/www/html
      - ./docker/php/php.ini:/usr/local/etc/php/conf.d/custom.ini
    networks:
      - boleto-network
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started
    env_file:
      - .env
    environment:
      - DB_HOST=mysql
      - DB_PORT=3306
      - REDIS_HOST=redis
      - REDIS_PORT=6379

  nginx:
    build:
      context: .
      dockerfile: docker/nginx/Dockerfile
    container_name: boleto-inter-pro-nginx
    restart: unless-stopped
    ports:
      - "8080:80"
      - "8443:443"
    volumes:
      - ./:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - boleto-network
    depends_on:
      - app

  mysql:
    image: mysql:5.7
    container_name: boleto-inter-pro-mysql
    restart: unless-stopped
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-boleto_inter_pro}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root}
      MYSQL_USER: ${DB_USERNAME:-boleto_user}
      MYSQL_PASSWORD: ${DB_PASSWORD:-boleto_pass}
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - boleto-network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_PASSWORD:-root}"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: boleto-inter-pro-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - boleto-network
    command: redis-server --appendonly yes

networks:
  boleto-network:
    driver: bridge

volumes:
  mysql_data:
  redis_data:
