Makefile 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # ─────────────────────────────────────────────────────────────────────────────
  2. # PMDI — Pay My Damn Invoice | Developer Makefile
  3. # ─────────────────────────────────────────────────────────────────────────────
  4. # Usage:
  5. # make up — start the full Docker stack
  6. # make down — stop and remove containers
  7. # make logs — tail all container logs
  8. # make cron — trigger the billing scan manually
  9. # make migrate — run pending Alembic migrations inside the backend container
  10. # make autogen — generate a new migration from model changes
  11. # make shell-be — open a bash shell inside the backend container
  12. # make shell-db — open psql inside the db container
  13. #
  14. # Requires: docker compose, curl, jq
  15. # ─────────────────────────────────────────────────────────────────────────────
  16. .PHONY: up down restart logs cron migrate autogen shell-be shell-db help
  17. COMPOSE := docker compose
  18. BACKEND := pmdi_backend
  19. DB := pmdi_db
  20. API_BASE := http://localhost:8000/api
  21. # Load CRON_SECRET_TOKEN from .env for the manual cron trigger
  22. -include .env
  23. export
  24. # ── Stack management ───────────────────────────────────────────────────────────
  25. up:
  26. $(COMPOSE) up -d --build
  27. down:
  28. $(COMPOSE) down
  29. restart:
  30. $(COMPOSE) restart
  31. logs:
  32. $(COMPOSE) logs -f --tail=100
  33. # ── Cron manual trigger ────────────────────────────────────────────────────────
  34. # Sends a POST to /api/cron/run with the CRON_SECRET_TOKEN from .env
  35. # Pipe through jq if available, fall back to plain output.
  36. cron:
  37. @echo "▶ Triggering billing scan…"
  38. @curl -s -X POST $(API_BASE)/cron/run \
  39. -H "Authorization: Bearer $(CRON_SECRET_TOKEN)" \
  40. -H "Content-Type: application/json" \
  41. | (command -v jq > /dev/null 2>&1 && jq . || cat)
  42. @echo ""
  43. # ── Database migrations ────────────────────────────────────────────────────────
  44. migrate:
  45. @echo "▶ Running Alembic migrations…"
  46. $(COMPOSE) exec $(BACKEND) alembic upgrade head
  47. autogen:
  48. @echo "▶ Auto-generating migration from model changes…"
  49. $(COMPOSE) exec $(BACKEND) alembic revision --autogenerate -m "$(MSG)"
  50. # ── Shells ─────────────────────────────────────────────────────────────────────
  51. shell-be:
  52. $(COMPOSE) exec $(BACKEND) bash
  53. shell-db:
  54. $(COMPOSE) exec $(DB) psql -U $${POSTGRES_USER:-pmdi} -d $${POSTGRES_DB:-pmdi}
  55. # ── Help ───────────────────────────────────────────────────────────────────────
  56. help:
  57. @echo ""
  58. @echo " PMDI Developer Makefile"
  59. @echo " ──────────────────────────────────────────────────"
  60. @echo " make up Start stack (build if needed)"
  61. @echo " make down Stop and remove containers"
  62. @echo " make restart Restart all services"
  63. @echo " make logs Tail logs from all containers"
  64. @echo " make cron Manually trigger billing scan"
  65. @echo " make migrate Apply pending DB migrations"
  66. @echo " make autogen MSG='describe change' Generate migration"
  67. @echo " make shell-be Shell into backend container"
  68. @echo " make shell-db psql into PostgreSQL container"
  69. @echo ""