services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/var/www/html
    ports:
      - "8000:8000"
    command: php -S 0.0.0.0:8000 -t public
    environment:
      - DB_PATH=/var/www/html/database.sqlite
      - POCKETBASE_URL=http://pocketbase:8090
      - POCKETBASE_PUBLIC_URL=${POCKETBASE_PUBLIC_URL}
      - SITE_URL=${SITE_URL}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - pocketbase
    networks:
      - app_network

  worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: abrat_sp_worker
    volumes:
      - .:/var/www/html
    environment:
      - DB_PATH=/var/www/html/database.sqlite
      - POCKETBASE_URL=http://pocketbase:8090
    command: php scripts/worker.php
    depends_on:
      - pocketbase
    networks:
      - app_network

  pocketbase:
    image: ghcr.io/muchobien/pocketbase:latest
    container_name: pocketbase
    restart: unless-stopped
    environment:
      PB_HOST: 0.0.0.0
      PB_PORT: 8090
      PB_ADMIN_EMAIL: ${PB_ADMIN_EMAIL}
      PB_ADMIN_PASSWORD: ${PB_ADMIN_PASSWORD}
    volumes:
      - ./pb_data:/pb_data
    ports:
      - "8090:8090"
    networks:
      - app_network
    healthcheck:
      test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8090/api/health" ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

networks:
  app_network:
    driver: bridge
