peregrine/Makefile
pyr0ball 78917c8460 feat: startup preflight — port collision avoidance + resource checks
scripts/preflight.py (stdlib-only, no psutil):
- Port probing: owned services auto-reassign to next free port; external
  services (Ollama) show ✓ reachable / ⚠ not responding
- System resources: CPU cores, RAM (total + available), GPU VRAM via
  nvidia-smi; works on Linux + macOS
- Profile recommendation: remote / cpu / single-gpu / dual-gpu
- vLLM KV cache offload: calculates CPU_OFFLOAD_GB when VRAM < 10 GB
  free and RAM headroom > 4 GB (uses up to 25% of available headroom)
- Writes resolved values to .env for docker compose; single-service mode
  (--service streamlit) for scripted port queries
- Exit 0 unless an owned port genuinely can't be resolved

scripts/manage-ui.sh:
- Calls preflight.py --service streamlit before bind; falls back to
  pure-bash port scan if Python/yaml unavailable

compose.yml:
- vllm command: adds --cpu-offload-gb ${CPU_OFFLOAD_GB:-0}

Makefile:
- start / restart depend on preflight target
- PYTHON variable for env portability
- test target uses PYTHON variable
2026-02-24 20:36:16 -08:00

37 lines
1.2 KiB
Makefile

# Makefile — Peregrine convenience targets
# Usage: make <target>
.PHONY: setup preflight start stop restart logs test clean help
PROFILE ?= remote
PYTHON ?= python3
setup: ## Install dependencies (Docker, NVIDIA toolkit)
@bash setup.sh
preflight: ## Check ports + system resources; write .env
@$(PYTHON) scripts/preflight.py
start: preflight ## Preflight check then start Peregrine (PROFILE=remote|cpu|single-gpu|dual-gpu)
docker compose --profile $(PROFILE) up -d
stop: ## Stop all Peregrine services
docker compose down
restart: preflight ## Preflight check then restart all services
docker compose down && docker compose --profile $(PROFILE) up -d
logs: ## Tail app logs
docker compose logs -f app
test: ## Run the test suite
$(PYTHON) -m pytest tests/ -v
clean: ## Remove containers, images, and data volumes (DESTRUCTIVE)
@echo "WARNING: This will delete all Peregrine containers and data."
@read -p "Type 'yes' to confirm: " confirm && [ "$$confirm" = "yes" ]
docker compose down --rmi local --volumes
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'