services:
  nginx:
    build: docker/nginx
    ports:
      - "80:80"
    depends_on:
      - app
    networks:
      - internal
    restart: unless-stopped
    extra_hosts:
      - "host.docker.internal:host-gateway"

  app:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    user: "1000:1000"
    command: php artisan octane:start --server=frankenphp --host=0.0.0.0 --port=80 --admin-port=2019
    volumes:
      - .:/var/www/html
    env_file: .env
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - internal
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:2019/metrics"]
      interval: 10s
      timeout: 5s
      start_period: 30s
      retries: 3

  queue:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    user: "1000:1000"
    command: php artisan queue:work --queue=high,clicks,default --tries=3 --backoff=10
    volumes:
      - .:/var/www/html
    env_file: .env
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - internal
    restart: unless-stopped
    healthcheck:
      disable: true

  scheduler:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    user: "1000:1000"
    command: php artisan schedule:work
    volumes:
      - .:/var/www/html
    env_file: .env
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - internal
    restart: unless-stopped
    healthcheck:
      disable: true

  reverb:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    user: "1000:1000"
    command: php artisan reverb:start --host=0.0.0.0 --port=8080
    ports:
      - "8080:8080"
    env_file: .env
    depends_on:
      redis:
        condition: service_healthy
    networks:
      - internal
    restart: unless-stopped
    healthcheck:
      disable: true

  mysql:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: nimuli
      MYSQL_USER: nimuli
      MYSQL_PASSWORD: nimuli
    volumes:
      - mysql-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot"]
      interval: 5s
      timeout: 5s
      retries: 10
      start_period: 30s
    networks:
      - internal
    restart: unless-stopped

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

  mailpit:
    image: axllent/mailpit:latest
    ports:
      - "8025:8025"
      - "1025:1025"
    networks:
      - internal
    restart: unless-stopped

volumes:
  mysql-data: {}
  redis-data: {}

networks:
  internal:
    driver: bridge
