-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
200 lines (160 loc) · 8.44 KB
/
Copy pathMakefile
File metadata and controls
200 lines (160 loc) · 8.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# ── opentech-db — local development setup ────────────────────────────────────
# Prerequisites: Python 3.11+, Node.js 18+, Docker Desktop
#
# Quick start:
#
# make install ← first time only: dependencies + services + secrets
# make start ← every subsequent time: services + dev servers
#
# On Windows run from PowerShell or Command Prompt.
# 'make dev' (combined server) requires Git Bash; use separate terminals otherwise.
# ─────────────────────────────────────────────────────────────────────────────
.PHONY: help install configure start supabase auth-init auth auth-check auth-reset auth-down auth-logs backend frontend stop reset lint build dev \
docker-build docker-up docker-down docker-logs
# ── Platform ─────────────────────────────────────────────────────────────────
ifeq ($(OS),Windows_NT)
PYTHON := python
VENV_BIN := .venv/Scripts
DEV_NULL := NUL
else
PYTHON := python3
VENV_BIN := .venv/bin
DEV_NULL := /dev/null
endif
PY := $(VENV_BIN)/python
PIP := $(VENV_BIN)/pip
UV := $(VENV_BIN)/uvicorn
AUTH_ENV ?= keycloak/.env.local
AUTH_COMPOSE_FILE ?= keycloak/compose.local.yml
AUTH_COMPOSE = docker compose --env-file $(AUTH_ENV) -f $(AUTH_COMPOSE_FILE)
# ── Default ───────────────────────────────────────────────────────────────────
help:
@echo.
@echo opentech-db make targets
@echo.
@echo make install one-time setup: venv, npm, services, secrets
@echo make start start all services then open both dev servers
@echo make configure regenerate local secrets
@echo make auth-init fetch the Keycloak/auth submodule at its pinned revision
@echo make auth start or rebuild Keycloak/Go-auth/Redis/Postgres
@echo make auth-check verify local credentials match the persisted auth database
@echo make auth-reset guarded reset for disposable local authentication data
@echo make auth-down stop the auth stack
@echo make auth-logs follow Keycloak and Go auth logs
@echo make backend start FastAPI on :8000
@echo make frontend start Vite on :5173
@echo make dev start both servers in one terminal (Git Bash only)
@echo make supabase start local Supabase data services
@echo make stop stop Supabase containers
@echo make reset wipe local DB and re-run migrations
@echo make lint ESLint on the frontend
@echo make build production frontend bundle
@echo make docker-build build all Docker images (backend + frontend)
@echo make docker-up start production stack in background
@echo make docker-down stop production stack
@echo make docker-logs tail logs from all containers
@echo.
# ── One-time setup ───────────────────────────────────────────────────────────
install: _check-docker _create-envs auth-init .venv frontend/node_modules _install-supabase-cli
$(MAKE) --no-print-directory supabase
$(MAKE) --no-print-directory auth
@echo.
@echo ================================================================
@echo Setup complete. Data and auth containers are running.
@echo Start the dev servers in two terminals:
@echo Terminal 1: make backend
@echo Terminal 2: make frontend
@echo ================================================================
@echo.
# Day-to-day: ensure all services are up, then open dev servers.
start: _check-docker configure
@echo Starting data services...
@supabase start >$(DEV_NULL) 2>&1 || echo Supabase already running.
$(MAKE) --no-print-directory auth
@echo.
@echo Services are up. Start dev servers:
@echo Terminal 1: make backend
@echo Terminal 2: make frontend
@echo.
# Generates independent local secrets and synchronizes AUTH_INTERNAL_SECRET.
configure: .venv
$(PY) tools/configure_env.py
# ── Prerequisites ─────────────────────────────────────────────────────────────
_check-docker:
@docker info >$(DEV_NULL) 2>&1 || (echo. && echo ERROR: Docker Desktop is not running. Please start it and try again. && exit 1)
# Use Python (always available as a prerequisite) for cross-platform file copy.
_create-envs:
@$(PYTHON) -c "import shutil, pathlib; pathlib.Path('.env').exists() or shutil.copy('.env.example', '.env')" && echo Created .env if missing.
@$(PYTHON) -c "import shutil, pathlib; pathlib.Path('frontend/.env.local').exists() or shutil.copy('frontend/.env.example', 'frontend/.env.local')" && echo Created frontend/.env.local if missing.
_install-supabase-cli:
@supabase --version >$(DEV_NULL) 2>&1 || (echo Installing Supabase CLI... && npm install -g supabase)
# Python virtualenv — only created when the directory does not exist.
.venv:
$(PYTHON) -m venv .venv
$(PIP) install --upgrade pip --quiet
$(PIP) install -r requirements.txt
# npm deps — only runs when package.json is newer than node_modules.
frontend/node_modules: frontend/package.json
cd frontend && npm install
# ── Supabase data services (GoTrue/Auth is disabled) ─────────────────────────
supabase: _check-docker _install-supabase-cli .venv
supabase start
supabase migration up --local
@echo Patching .env files with local Supabase credentials...
$(PY) tools/patch_supabase_env.py
stop:
supabase stop
reset: _check-docker
supabase db reset
# ── Authentication stack ──────────────────────────────────────────────────────
auth-init:
@git submodule sync --quiet -- keycloak
@git submodule update --init --recursive -- keycloak
@$(PYTHON) -c "import pathlib, sys; sys.exit(0 if pathlib.Path('keycloak/compose.local.yml').exists() else 'ERROR: keycloak/compose.local.yml is missing - the keycloak content is not present in this checkout.')"
auth: auth-check
$(AUTH_COMPOSE) up -d --build
auth-check: _check-docker auth-init configure
@$(PY) tools/auth_precheck.py \
"$(AUTH_ENV)" \
"$(AUTH_COMPOSE_FILE)" \
"make auth" \
"make auth-reset CONFIRM=delete-local-keycloak-data" \
"all local Keycloak realm/user data and Redis sessions"
auth-reset: _check-docker auth-init configure
@test "$(CONFIRM)" = "delete-local-keycloak-data" \
|| (echo "ERROR: this deletes all local Keycloak realms, users, and sessions." \
&& echo "Re-run with: make auth-reset CONFIRM=delete-local-keycloak-data" \
&& exit 1)
$(AUTH_COMPOSE) down -v --remove-orphans
@$(MAKE) --no-print-directory auth \
AUTH_ENV="$(AUTH_ENV)" \
AUTH_COMPOSE_FILE="$(AUTH_COMPOSE_FILE)"
auth-down: auth-init
$(AUTH_COMPOSE) down
auth-logs: auth-init
$(AUTH_COMPOSE) logs -f keycloak auth-service
# ── Dev servers ───────────────────────────────────────────────────────────────
backend:
$(UV) main:app --reload --port 8000
frontend:
cd frontend && npm run dev
# Combined launcher — requires bash (Git Bash on Windows).
# Ctrl+C stops both servers.
dev:
@trap 'kill %1 2>/dev/null; exit 0' INT TERM EXIT; \
$(UV) main:app --reload --port 8000 & \
cd frontend && npm run dev
# ── Code quality ──────────────────────────────────────────────────────────────
lint:
cd frontend && npm run lint
build:
cd frontend && npm run build
# ── Docker / Production ───────────────────────────────────────────────────────
docker-build:
docker compose build
docker-up:
docker compose up -d
docker-down:
docker compose down
docker-logs:
docker compose logs -f --tail=100