-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
283 lines (246 loc) · 11.6 KB
/
Copy pathMakefile
File metadata and controls
283 lines (246 loc) · 11.6 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
.PHONY: help build db-up db-down db-reset db-migrate oidc-dev-keys keycloak-up keycloak-down keycloak-logs keycloak-reset test test-unit test-unit-db test-contract test-integration test-integration-sqlite test-integration-mode1 test-integration-mode2 test-integration-all test-e2e test-e2e-ui test-e2e-headed test-e2e-debug test-e2e-report test-all ci-test test-integration-setup test-integration-teardown test-clean clean
help: ## Display available targets
@echo "Grid Terraform State Management - Makefile"
@echo ""
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
GRID_DATABASE_URL ?= postgres://grid:gridpass@localhost:5432/grid?sslmode=disable
GRID_SERVER_URL ?= http://localhost:8080
GRIDAPI_SRCS := $(shell find cmd/gridapi -name '*.go' -o -name '*.sql' -o -name 'model.conf')
bin/gridapi: $(GRIDAPI_SRCS)
@echo "Building gridapi..."
@cd cmd/gridapi && go build -o ../../bin/gridapi .
GRIDCTL_SRCS := $(shell find cmd/gridctl -name '*.go' -o -name '*.tmpl')
bin/gridctl: $(GRIDCTL_SRCS)
@echo "Building gridctl..."
@cd cmd/gridctl && go build -o ../../bin/gridctl .
JS_SDK_SRCS := $(shell find js/sdk \( -path '*/node_modules' -o -path '*/dist' -o -path '*/build' -o -path '*/lib' \) -prune -o \( -name '*.ts' \) -print)
js/sdk/lib: $(JS_SDK_SRCS)
@cd js/sdk && pnpm run build
build: ## Build gridapi and gridctl to bin/ directory
@$(MAKE) bin/gridapi
@$(MAKE) bin/gridctl
db-up: ## Start PostgreSQL via docker compose up -d
@echo "Starting PostgreSQL..."
@docker compose up -d postgres
@echo "Waiting for PostgreSQL to be healthy..."
@docker compose ps postgres
db-down: ## Stop PostgreSQL via docker compose down
@echo "Stopping PostgreSQL..."
@docker compose down
db-reset: ## Fresh database (docker compose down -v && docker compose up -d)
@echo "Resetting database (removing volumes)..."
@docker compose down -v
@echo "Starting fresh PostgreSQL..."
@docker compose up -d postgres
@echo "Waiting for PostgreSQL to be healthy..."
@sleep 2
@docker compose ps postgres
db-migrate: build ## Run database migrations
@echo "Initializing migration tables..."
@GRID_DATABASE_URL="$(GRID_DATABASE_URL)" GRID_SERVER_URL="$(GRID_SERVER_URL)" bin/gridapi db init
@echo "Running migrations..."
@GRID_DATABASE_URL="$(GRID_DATABASE_URL)" GRID_SERVER_URL="$(GRID_SERVER_URL)" bin/gridapi db migrate
oidc-dev-keys: ## Generate OIDC signing keys for local development (FR-110)
@echo "Generating OIDC development signing keys..."
@mkdir -p cmd/gridapi/internal/auth/keys
@./scripts/dev/generate-oidc-keys.sh
@echo "✓ Keys generated in cmd/gridapi/internal/auth/keys/"
@echo " Note: These are for local development only. Production must use secure key vault."
keycloak-up: ## Start Keycloak via docker compose (FR-111)
@echo "Starting Keycloak..."
@docker compose up -d keycloak
@echo "Waiting for Keycloak to be healthy..."
@sleep 5
@docker compose ps keycloak
@echo "✓ Keycloak available at http://localhost:8443"
@echo " Admin credentials: admin/admin"
keycloak-down: ## Stop Keycloak via docker compose (FR-111)
@echo "Stopping Keycloak..."
@docker compose stop keycloak
keycloak-logs: ## Show Keycloak logs (FR-111)
@docker compose logs -f keycloak
keycloak-reset: ## Reset Keycloak environment (stop, prune volumes, restart) (FR-112)
@echo "Resetting Keycloak environment..."
@./scripts/dev/keycloak-reset.sh
test: test-all ## Run all tests (alias for test-all)
test-unit: ## Run unit tests (no external dependencies)
@echo "Running unit tests..."
@go test -v -short -race \
./cmd/gridapi/internal/config/... \
./cmd/gridapi/internal/server/... \
./cmd/gridapi/internal/services/state/... \
./cmd/gridapi/internal/services/tfstate/... \
./cmd/gridapi/internal/services/graph/... \
./cmd/gridapi/internal/services/dependency/... \
./cmd/gridapi/internal/services/iam/... \
./pkg/sdk/... \
./cmd/gridctl/...
test-unit-db: ## Run repository unit tests (requires database)
@echo "Running repository unit tests..."
@echo "Ensuring database is running..."
@docker compose up -d postgres
@sleep 2
@go test -v -race ./cmd/gridapi/internal/repository/...
test-contract: ## Run contract tests (requires server) - WIP: Tests are placeholder TODOs
@echo "Contract tests are currently TODO placeholders (all skipped)"
@echo "To implement: Add gridapi service to docker-compose.yml or use TestMain pattern"
@echo "Skipping contract tests..."
@# TODO: Uncomment when contract tests are implemented
@# docker compose up -d
@# sleep 3
@# ./scripts/wait-for-health.sh
@# go test -v -race ./tests/contract/...
test-integration: ## Run integration tests (no OIDC - automated setup via TestMain) - excludes Mode 1/Mode 2
@echo "Running integration tests with automated setup..."
@echo "Ensuring database is running..."
@docker compose up -d postgres
@sleep 2
@cd tests/integration && go test -v -race -timeout 5m -skip "TestMode1|TestMode2"
test-integration-sqlite: build ## Run integration tests with SQLite (no PostgreSQL required)
@echo "Running integration tests with SQLite..."
@echo "Using SQLite in-memory database (no external dependencies)"
@cd tests/integration && \
GRID_DATABASE_URL=":memory:" \
GRID_SERVER_URL="$(GRID_SERVER_URL)" \
go test -v -race -timeout 5m -skip "TestMode1|TestMode2"
test-integration-mode1: build ## Run Mode 1 (External IdP) integration tests with Keycloak
@echo "Running Mode 1 (External IdP) integration tests..."
@echo "Ensuring database and Keycloak are running..."
@docker compose up -d postgres keycloak
@sleep 5
@echo "Extracting client credentials from realm-export.json..."
$(eval GRIDAPI_SECRET := $(shell jq -r '.clients[] | select(.clientId=="grid-api") | .secret' tests/fixtures/realm-export.json))
$(eval INTEGRATION_TESTS_SECRET := $(shell jq -r '.clients[] | select(.clientId=="integration-tests") | .secret' tests/fixtures/realm-export.json))
@echo "✓ Credentials extracted: grid-api (gridapi server), integration-tests (test client)"
@echo "Running tests with Mode 1 environment..."
@cd tests/integration && \
GRID_DATABASE_URL="$(GRID_DATABASE_URL)" \
GRID_SERVER_URL="$(GRID_SERVER_URL)" \
GRID_OIDC_EXTERNAL_IDP_ISSUER="http://localhost:8443/realms/grid" \
GRID_OIDC_EXTERNAL_IDP_CLIENT_ID="grid-api" \
GRID_OIDC_EXTERNAL_IDP_CLIENT_SECRET="$(GRIDAPI_SECRET)" \
GRID_OIDC_EXTERNAL_IDP_REDIRECT_URI="http://localhost:8080/auth/sso/callback" \
MODE1_TEST_CLIENT_ID="integration-tests" \
MODE1_TEST_CLIENT_SECRET="$(INTEGRATION_TESTS_SECRET)" \
go test -v -race -timeout 10m -run "TestMode1"
test-integration-mode2: build ## Run Mode 2 (Internal IdP) integration tests
@echo "Running Mode 2 (Internal IdP) integration tests..."
@echo "Ensuring database is running..."
@docker compose up -d postgres
@sleep 2
@echo "Running tests with Mode 2 environment..."
@cd tests/integration && \
GRID_DATABASE_URL="$(GRID_DATABASE_URL)" \
GRID_SERVER_URL="$(GRID_SERVER_URL)" \
GRID_OIDC_ISSUER="http://localhost:8080" \
GRID_OIDC_CLIENT_ID="gridapi" \
GRID_OIDC_SIGNING_KEY_PATH="tmp/keys/signing-key.pem" \
go test -v -race -timeout 5m -run "TestMode2"
test-integration-all: build ## Run full integration suite (Mode 1 + Mode 2 with db resets)
@echo "=========================================="
@echo "Full Integration Test Suite"
@echo "=========================================="
@echo ""
@echo "Phase 1: Mode 1 (External IdP with Keycloak)"
@echo "------------------------------------------"
@$(MAKE) db-reset
@$(MAKE) db-migrate
@docker compose up -d postgres keycloak
@sleep 5
@echo "Extracting client credentials from realm-export.json..."
$(eval GRIDAPI_SECRET := $(shell jq -r '.clients[] | select(.clientId=="grid-api") | .secret' tests/fixtures/realm-export.json))
$(eval INTEGRATION_TESTS_SECRET := $(shell jq -r '.clients[] | select(.clientId=="integration-tests") | .secret' tests/fixtures/realm-export.json))
@echo "✓ Credentials extracted: grid-api (gridapi server), integration-tests (test client)"
@cd tests/integration && \
GRID_DATABASE_URL="$(GRID_DATABASE_URL)" \
GRID_SERVER_URL="$(GRID_SERVER_URL)" \
GRID_OIDC_EXTERNAL_IDP_ISSUER="http://localhost:8443/realms/grid" \
GRID_OIDC_EXTERNAL_IDP_CLIENT_ID="grid-api" \
GRID_OIDC_EXTERNAL_IDP_CLIENT_SECRET="$(GRIDAPI_SECRET)" \
GRID_OIDC_EXTERNAL_IDP_REDIRECT_URI="http://localhost:8080/auth/sso/callback" \
MODE1_TEST_CLIENT_ID="integration-tests" \
MODE1_TEST_CLIENT_SECRET="$(INTEGRATION_TESTS_SECRET)" \
go test -v -race -timeout 10m -run "TestMode1" || { echo "❌ Mode 1 tests failed"; exit 1; }
@echo "✓ Mode 1 tests passed"
@echo ""
@echo "Phase 2: Mode 2 (Internal IdP)"
@echo "------------------------------------------"
@$(MAKE) db-reset
@docker compose up -d postgres
@sleep 2
@cd tests/integration && \
GRID_DATABASE_URL="$(GRID_DATABASE_URL)" \
GRID_SERVER_URL="$(GRID_SERVER_URL)" \
GRID_OIDC_ISSUER="http://localhost:8080" \
GRID_OIDC_CLIENT_ID="gridapi" \
GRID_OIDC_SIGNING_KEY_PATH="tmp/keys/signing-key.pem" \
go test -v -race -timeout 5m -run "TestMode2" || { echo "❌ Mode 2 tests failed"; exit 1; }
@echo "✓ Mode 2 tests passed"
@echo ""
@echo "=========================================="
@echo "✓ Full integration suite completed!"
@echo "=========================================="
test-e2e: build js/sdk/lib ## Run E2E tests for no-auth mode
@echo "Running No-Auth E2E tests..."
@pnpm test:e2e:no-auth
test-e2e-ui: build js/sdk/lib ## Run E2E tests for no-auth mode
@echo "Running No-Auth E2E tests..."
@pnpm test:e2e:no-auth:ui
test-e2e-auth: build js/sdk/lib ## Run E2E tests (webapp authentication flows with Playwright)
@echo "Running E2E tests..."
@echo "Note: This will start all required services (postgres, keycloak, gridapi, webapp)"
@pnpm test:e2e:auth
test-e2e-auth-ui: build js/sdk/lib ## Run E2E tests in interactive UI mode
@echo "Starting E2E tests in UI mode..."
@pnpm test:e2e:auth:ui
test-e2e-auth-headed: build js/sdk/lib ## Run E2E tests in headed mode (visible browser)
@echo "Running E2E tests in headed mode..."
@pnpm test:e2e:auth:headed
test-e2e-auth-debug: build js/sdk/lib ## Run E2E tests in debug mode
@echo "Running E2E tests in debug mode..."
@pnpm test:e2e:auth:debug
test-e2e-auth-report: ## Show E2E test report
@echo "Opening E2E test report..."
@pnpm test:e2e:auth:report
test-all: ## Run all test suites
@echo "Running all test suites..."
$(MAKE) test-unit
$(MAKE) test-unit-db
$(MAKE) test-contract
$(MAKE) test-integration-all
@echo "✓ All test suites passed"
ci-test: ## Run CI test pipeline
@echo "Running CI test pipeline..."
@docker compose up -d
@sleep 3
@./scripts/wait-for-health.sh
$(MAKE) test-unit
$(MAKE) test-unit-db
$(MAKE) test-contract
$(MAKE) test-integration
@docker compose down
@echo "✓ CI pipeline completed"
test-integration-setup: ## Start gridapi server for manual testing
@echo "Starting gridapi server for manual testing..."
@docker compose up -d
@sleep 2
@GRID_SERVER_URL="$(GRID_SERVER_URL)" ./bin/gridapi serve --server-addr :8080 --db-url "$(GRID_DATABASE_URL)" --server-url "$(GRID_SERVER_URL)" &
@echo "Server starting... waiting for health check"
@./scripts/wait-for-health.sh
@echo "Server ready at http://localhost:8080"
test-integration-teardown: ## Stop gridapi server
@echo "Stopping gridapi server..."
@pkill -TERM gridapi || true
@sleep 1
test-clean: ## Clean test artifacts and test data
@echo "Cleaning test artifacts..."
@rm -rf tests/integration/tmp_*
@rm -f tests/**/*.test
@./scripts/test-cleanup.sh
clean: ## Remove bin/ directory and test artifacts
@echo "Cleaning build artifacts..."
@rm -rf bin/
@echo "Cleaning test artifacts..."
@go clean -testcache
@echo "Clean complete"