Makefile 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. PROJECT_ROOT := $(shell pwd)
  2. COMPOSE_DEV := docker compose -f docker-compose.dev.yml
  3. COMPOSE_PROD := docker compose -f docker-compose.prod.yml
  4. COMPOSE_DEPLOY := docker compose -f docker-compose.deploy.yml
  5. .PHONY: \
  6. dev prod deploy \
  7. build-dev build-prod \
  8. up-dev up-prod up-deploy down \
  9. infra-dev infra-prod infra-stop-dev infra-stop-prod \
  10. migrate-dev migrate-prod \
  11. alembic-upgrade alembic-downgrade alembic-revision \
  12. api frontend celery \
  13. test install clean check-env open-browser-dev open-browser-prod \
  14. logs-dev logs-prod logs-deploy status \
  15. regenerate-router
  16. ENV_DIRS := . flowsint-api flowsint-core flowsint-app
  17. check-env:
  18. @echo "Checking .env files..."
  19. @for dir in $(ENV_DIRS); do \
  20. env_file="$$dir/.env"; \
  21. env_example="$(PROJECT_ROOT)/.env.example"; \
  22. if [ ! -f "$$env_file" ]; then \
  23. cp "$$env_example" "$$env_file"; \
  24. echo "Created $$env_file"; \
  25. fi; \
  26. done
  27. dev:
  28. @echo "Starting DEV environment..."
  29. $(MAKE) check-env
  30. $(MAKE) build-dev
  31. $(MAKE) up-dev
  32. $(MAKE) open-browser-dev
  33. $(COMPOSE_DEV) logs -f
  34. build-dev:
  35. @echo "Building DEV images..."
  36. $(COMPOSE_DEV) build
  37. up-dev:
  38. $(COMPOSE_DEV) up -d
  39. infra-dev:
  40. @echo "Starting DEV infra (postgres / redis / neo4j)..."
  41. $(COMPOSE_DEV) up -d postgres redis neo4j
  42. infra-stop-dev:
  43. @echo "Stopping DEV infra..."
  44. $(COMPOSE_DEV) stop postgres redis neo4j
  45. logs-dev:
  46. $(COMPOSE_DEV) logs -f
  47. open-browser-dev:
  48. @echo "Waiting for frontend on port 5173..."
  49. @bash -c 'until curl -s http://localhost:5173 > /dev/null 2>&1; do sleep 1; done'
  50. @open http://localhost:5173 2>/dev/null || \
  51. xdg-open http://localhost:5173 2>/dev/null || \
  52. echo "Frontend ready at http://localhost:5173"
  53. prod:
  54. @echo "Starting PROD environment..."
  55. $(MAKE) check-env
  56. $(MAKE) build-prod
  57. $(MAKE) up-prod
  58. @echo ""
  59. @echo "Production started!"
  60. @echo " Frontend: http://localhost:5173"
  61. @echo " API: http://localhost:5001"
  62. build-prod:
  63. @echo "Building PROD images..."
  64. $(COMPOSE_PROD) build
  65. up-prod:
  66. $(COMPOSE_PROD) up -d
  67. infra-prod:
  68. @echo "Starting PROD infra (postgres / redis / neo4j)..."
  69. $(COMPOSE_PROD) up -d postgres redis neo4j
  70. infra-stop-prod:
  71. @echo "Stopping PROD infra..."
  72. $(COMPOSE_PROD) stop postgres redis neo4j
  73. logs-prod:
  74. $(COMPOSE_PROD) logs -f
  75. open-browser-prod:
  76. @echo "Waiting for frontend on port 80 (Traefik)..."
  77. @bash -c 'until curl -s http://localhost > /dev/null 2>&1; do sleep 2; done'
  78. @open http://localhost 2>/dev/null || \
  79. xdg-open http://localhost 2>/dev/null || \
  80. echo "Frontend ready at http://localhost"
  81. deploy:
  82. @echo "Starting DEPLOY environment (GHCR images)..."
  83. $(MAKE) check-env
  84. $(COMPOSE_DEPLOY) pull
  85. $(COMPOSE_DEPLOY) up -d
  86. @echo ""
  87. @echo "Deploy started!"
  88. @echo " Frontend: http://localhost (via Traefik)"
  89. @echo " API: http://localhost/api"
  90. up-deploy:
  91. $(COMPOSE_DEPLOY) up -d
  92. logs-deploy:
  93. $(COMPOSE_DEPLOY) logs -f
  94. migrate-dev:
  95. @echo "Running DEV migrations..."
  96. @if ! $(COMPOSE_DEV) ps -q neo4j | grep -q .; then \
  97. echo "Neo4j not running → starting DEV infra"; \
  98. $(COMPOSE_DEV) up -d --wait neo4j; \
  99. fi
  100. yarn migrate
  101. migrate-prod:
  102. @echo "⚠️ Running PROD migrations"
  103. @echo "This will ALTER production data."
  104. @read -p "Type 'prod' to continue: " confirm; \
  105. if [ "$$confirm" != "prod" ]; then \
  106. echo "Aborted."; exit 1; \
  107. fi
  108. yarn migrate
  109. alembic-upgrade:
  110. @echo "Running Alembic migrations (upgrade head)..."
  111. cd $(PROJECT_ROOT)/flowsint-api && uv run alembic upgrade head
  112. alembic-downgrade:
  113. @echo "Rolling back last Alembic migration..."
  114. cd $(PROJECT_ROOT)/flowsint-api && uv run alembic downgrade -1
  115. alembic-revision:
  116. @if [ -z "$(m)" ]; then \
  117. echo "Usage: make alembic-revision m=\"your migration message\""; exit 1; \
  118. fi
  119. @echo "Creating new Alembic migration: $(m)"
  120. cd $(PROJECT_ROOT)/flowsint-api && uv run alembic revision --autogenerate -m "$(m)"
  121. api:
  122. cd $(PROJECT_ROOT)/flowsint-api && \
  123. uv run uvicorn app.main:app --host 0.0.0.0 --port 5001 --reload
  124. frontend:
  125. cd $(PROJECT_ROOT)/flowsint-app && yarn dev
  126. celery:
  127. cd $(PROJECT_ROOT)/flowsint-api && \
  128. uv run celery -A flowsint_core.core.celery \
  129. worker --loglevel=info --pool=threads --concurrency=10
  130. test:
  131. cd flowsint-types && uv run pytest
  132. cd flowsint-core && uv run pytest
  133. cd flowsint-enrichers && uv run pytest
  134. install:
  135. $(MAKE) infra-dev
  136. uv sync
  137. cd flowsint-api && uv run alembic upgrade head
  138. status:
  139. @echo "=== DEV Containers ==="
  140. @$(COMPOSE_DEV) ps 2>/dev/null || echo "No DEV containers"
  141. @echo ""
  142. @echo "=== PROD Containers ==="
  143. @$(COMPOSE_PROD) ps 2>/dev/null || echo "No PROD containers"
  144. down:
  145. -$(COMPOSE_DEV) down
  146. -$(COMPOSE_PROD) down
  147. -$(COMPOSE_DEPLOY) down
  148. clean:
  149. @echo "This will remove ALL Docker data. Continue? [y/N]"
  150. @read confirm; \
  151. if [ "$$confirm" != "y" ]; then exit 1; fi
  152. -$(COMPOSE_DEV) down -v --rmi all --remove-orphans
  153. -$(COMPOSE_PROD) down -v --rmi all --remove-orphans
  154. -$(COMPOSE_DEPLOY) down -v --rmi all --remove-orphans
  155. rm -rf flowsint-app/node_modules
  156. rm -rf .venv
  157. regenerate-router:
  158. @echo "Regenerating flowsint-app/src/routeTree.gen.ts"
  159. cd $(PROJECT_ROOT)/flowsint-app && npx tsr generate
  160. help:
  161. @echo "Flowsint Makefile"
  162. @echo ""
  163. @echo "Development:"
  164. @echo " make dev - Start DEV environment (local build, hot-reload)"
  165. @echo " make build-dev - Build DEV images"
  166. @echo " make up-dev - Start DEV containers"
  167. @echo " make logs-dev - Follow DEV logs"
  168. @echo " make infra-dev - Start only infra (postgres/redis/neo4j)"
  169. @echo ""
  170. @echo "Production (local build):"
  171. @echo " make prod - Start PROD environment (local build + Traefik)"
  172. @echo " make build-prod - Build PROD images"
  173. @echo " make up-prod - Start PROD containers"
  174. @echo " make logs-prod - Follow PROD logs"
  175. @echo ""
  176. @echo "Deploy (GHCR images):"
  177. @echo " make deploy - Start with GHCR images (no build)"
  178. @echo " make up-deploy - Start DEPLOY containers"
  179. @echo " make logs-deploy - Follow DEPLOY logs"
  180. @echo ""
  181. @echo "Local (no Docker):"
  182. @echo " make api - Run API locally"
  183. @echo " make frontend - Run frontend locally"
  184. @echo " make celery - Run Celery worker locally"
  185. @echo ""
  186. @echo "Migrations:"
  187. @echo " make migrate-dev - Run Neo4j DEV migrations"
  188. @echo " make migrate-prod - Run Neo4j PROD migrations"
  189. @echo " make alembic-upgrade - Run Alembic migrations (upgrade head)"
  190. @echo " make alembic-downgrade - Rollback last Alembic migration"
  191. @echo " make alembic-revision m=.. - Create new Alembic migration"
  192. @echo ""
  193. @echo "Utilities:"
  194. @echo " make status - Show container status"
  195. @echo " make down - Stop all containers"
  196. @echo " make clean - Remove all Docker data"
  197. @echo " make install - Install dependencies locally"
  198. @echo " make test - Run tests"