services:
  app:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/var/www/html
    env_file: .env
    environment:
      APP_URL: http://localhost:8000
      DB_CONNECTION: pgsql
      DB_HOST: postgres
      DB_PORT: "5432"
      DB_DATABASE: vagalumetv
      DB_USERNAME: vagalumetv
      DB_PASSWORD: secret
    command: >
      sh -c "
        composer install --no-interaction --prefer-dist &&
        php artisan config:cache &&
        php artisan migrate --force --no-interaction &&
        php artisan serve --host=0.0.0.0 --port=8000
      "
    depends_on:
      postgres:
        condition: service_healthy

  queue:
    build: .
    volumes:
      - .:/var/www/html
    env_file: .env
    environment:
      APP_URL: http://localhost:8000
      DB_CONNECTION: pgsql
      DB_HOST: postgres
      DB_PORT: "5432"
      DB_DATABASE: vagalumetv
      DB_USERNAME: vagalumetv
      DB_PASSWORD: secret
    command: php artisan queue:work --queue=default --tries=2 --timeout=7200 --sleep=3 --backoff=5
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy

  postgres:
    image: postgres:16
    environment:
      POSTGRES_DB: vagalumetv
      POSTGRES_USER: vagalumetv
      POSTGRES_PASSWORD: secret
    ports:
      - "5433:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U vagalumetv"]
      interval: 5s
      timeout: 5s
      retries: 5

  vite:
    image: node:22-alpine
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
      - node_modules:/var/www/html/node_modules
    ports:
      - "5174:5174"
    command: sh -c "npm install && npm run dev -- --host --port 5174"

volumes:
  postgres_data:
  node_modules:
