services:
  bukidapp:
    build:
      context: .
      dockerfile: Dockerfile.php
    expose:
      - 9501
    environment:
      - APP_NAME=${APP_NAME}
      - APP_ENV=${APP_ENV:-production}
      - APP_KEY=${APP_KEY}
      - APP_DEBUG=${APP_DEBUG:-false}
      - APP_URL=${APP_URL}
      - DB_CONNECTION=${DB_CONNECTION:-mysql}
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PORT:-3306}
      - DB_DATABASE=${DB_DATABASE}
      - DB_USERNAME=${DB_USERNAME}
      - DB_PASSWORD=${DB_PASSWORD}
      - REDIS_HOST=dragonfly
      - REDIS_PORT=6379
      - REDIS_PASSWORD=${REDIS_PASSWORD:-}
      - REDIS_AUTH=${REDIS_AUTH:-}
      - REDIS_DB=${REDIS_DB:-0}
      - CACHE_DRIVER=${CACHE_DRIVER:-redis}
      - SESSION_DRIVER=${SESSION_DRIVER:-file}
      - QUEUE_CONNECTION=${QUEUE_CONNECTION:-sync}
      - PERF_API_TOKEN=${PERF_API_TOKEN:-}
      - PERF_ACTOR_HASH=${PERF_ACTOR_HASH:-}
    depends_on:
      - dragonfly
    command: ["sh", "-c", "php artisan app:check-connections --detail && cp -r /var/app/public/. /var/app/public-shared/ && exec php artisan serve"]
    volumes:
      - public_build:/var/app/public-shared
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://127.0.0.1:9501/health || exit 1"]
      interval: 30s
      timeout: 20s
      retries: 10
      start_period: 300s
    networks:
      dokploy-network:
      app-internal:
        aliases:
          - swoole-upstream

  dragonfly:
    image: docker.dragonflydb.io/dragonflydb/dragonfly
    expose:
      - 6379
    ulimits:
      memlock: -1
    networks:
      - app-internal

  nginx:
    image: nginx:alpine
    ports:
      - 80
    volumes:
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
      - public_build:/var/app/public
    networks:
      - dokploy-network
      - app-internal
    depends_on:
      bukidapp:
        condition: service_healthy

networks:
  dokploy-network:
    external: true
  app-internal:
    driver: bridge

volumes:
  public_build:
