-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
418 lines (359 loc) · 14 KB
/
Makefile
File metadata and controls
418 lines (359 loc) · 14 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
.PHONY: swagger-clean
swagger-clean:
rm -rf docs/swagger
.PHONY: install-swag
install-swag:
@which swag > /dev/null || (go install github.com/swaggo/swag/cmd/swag@latest)
.PHONY: swagger
swagger: swagger-2-0 swagger-3-0
.PHONY: swagger-2-0
swagger-2-0: install-swag
$(shell go env GOPATH)/bin/swag init \
--generalInfo cmd/server/main.go \
--dir . \
--parseDependency \
--parseInternal \
--output docs/swagger \
--generatedTime=false \
--parseDepth 1 \
--instanceName swagger \
--parseVendor \
--outputTypes go,json,yaml
@make swagger-fix-refs
.PHONY: swagger-3-0
swagger-3-0: install-swag
@echo "Converting Swagger 2.0 to OpenAPI 3.0..."
@curl -X 'POST' \
'https://converter.swagger.io/api/convert' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d @docs/swagger/swagger.json > docs/swagger/swagger-3-0.json
@echo "Conversion complete. Output saved to docs/swagger/swagger-3-0.json"
.PHONY: swagger-fix-refs
swagger-fix-refs:
@./scripts/fix_swagger_refs.sh
.PHONY: up
up:
docker compose up -d --build
.PHONY: down
down:
docker compose down
.PHONY: run-server
run-server:
go run cmd/server/main.go
.PHONY: run-server-local
run-server-local: run-server
.PHONY: run
run: run-server
.PHONY: test test-verbose test-coverage
# Run all tests
test: install-typst
go test -v -race ./internal/...
# Run tests with verbose output
test-verbose:
go test -v ./internal/...
# Run tests with coverage report
test-coverage:
go test -coverprofile=coverage.out ./internal/...
go tool cover -html=coverage.out -o coverage.html
# Database related targets
.PHONY: init-db migrate-postgres migrate-clickhouse seed-db migrate-ent
.PHONY: install-ent
install-ent:
@which ent > /dev/null || (go install entgo.io/ent/cmd/ent@latest)
.PHONY: generate-ent
generate-ent: install-ent
@echo "Generating ent code..."
@go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/execquery ./ent/schema
.PHONY: migrate-ent
migrate-ent:
@echo "Running Ent migrations..."
@go run cmd/migrate/main.go --timeout 300
@echo "Ent migrations complete"
.PHONY: migrate-ent-dry-run
migrate-ent-dry-run:
@echo "Generating SQL migration statements (dry run)..."
@go run cmd/migrate/main.go --dry-run --timeout 300
@echo "SQL migration statements generated"
.PHONY: generate-migration
generate-migration:
@echo "Generating SQL migration file..."
@mkdir -p migrations/ent
@go run cmd/migrate/main.go --dry-run --timeout 300 > migrations/ent/migration_$(shell date +%Y%m%d%H%M%S).sql
@echo "SQL migration file generated in migrations/ent/"
# Initialize databases and required topics
init-db: up migrate-postgres migrate-clickhouse generate-ent migrate-ent seed-db
@echo "Database initialization complete"
# Run postgres migrations
migrate-postgres:
@echo "Running Postgres migrations..."
@sleep 5 # Wait for postgres to be ready
@docker compose exec -T postgres psql -U flexprice -d flexprice -c "CREATE SCHEMA IF NOT EXISTS extensions;"
@docker compose exec -T postgres psql -U flexprice -d flexprice -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\" SCHEMA extensions;"
@echo "Postgres migrations complete"
# Run clickhouse migrations
migrate-clickhouse:
@echo "Running Clickhouse migrations..."
@sleep 5 # Wait for clickhouse to be ready
@for file in migrations/clickhouse/*.sql; do \
if [ -f "$$file" ]; then \
echo "Running migration: $$file"; \
docker compose exec -T clickhouse clickhouse-client --user=flexprice --password=flexprice123 --database=flexprice --multiquery < "$$file"; \
fi \
done
@echo "Clickhouse migrations complete"
# Seed initial data
seed-db:
@echo "Running Seed data migration..."
@docker compose exec -T postgres psql -U flexprice -d flexprice -f /docker-entrypoint-initdb.d/migration/postgres/V1__seed.sql
@echo "Postgres seed data migration complete"
# Initialize kafka topics
.PHONY: init-kafka
init-kafka:
@echo "Creating Kafka topics..."
@for i in 1 2 3 4 5; do \
echo "Attempt $$i: Checking if Kafka is ready..."; \
if docker compose exec -T kafka kafka-topics --bootstrap-server kafka:9092 --list >/dev/null 2>&1; then \
echo "Kafka is ready!"; \
docker compose exec -T kafka kafka-topics --create --if-not-exists \
--bootstrap-server kafka:9092 \
--topic events \
--partitions 1 \
--replication-factor 1 \
--config cleanup.policy=delete \
--config retention.ms=604800000; \
echo "Kafka topics created successfully"; \
exit 0; \
fi; \
echo "Kafka not ready yet, waiting..."; \
sleep 5; \
done; \
echo "Error: Kafka failed to become ready after 5 attempts"; \
exit 1
# Clean all docker containers and volumes related to the project
.PHONY: clean-docker
clean-docker:
@echo "Cleaning all docker containers and volumes..."
@docker compose down -v
@docker container prune -f
@docker volume rm $$(docker volume ls -q | grep flexprice) 2>/dev/null || true
@echo "Docker cleanup complete"
# Full local setup
.PHONY: setup-local
setup-local: up init-db init-kafka
@echo "Local setup complete. You can now run 'make run-server-local' to start the server"
# Clean everything and start fresh
.PHONY: clean-start
clean-start:
@make down
@docker compose down -v
@make setup-local
# Build the flexprice image separately
.PHONY: build-image
build-image:
@echo "Building flexprice image..."
@docker compose build flexprice-build
@echo "Flexprice image built successfully"
# Start only the flexprice services
.PHONY: start-flexprice
start-flexprice:
@echo "Starting flexprice services..."
@docker compose up -d flexprice-api flexprice-consumer flexprice-worker
@echo "Flexprice services started successfully"
# Stop only the flexprice services
.PHONY: stop-flexprice
stop-flexprice:
@echo "Stopping flexprice services..."
@docker compose stop flexprice-api flexprice-consumer flexprice-worker
@echo "Flexprice services stopped successfully"
# Restart only the flexprice services
.PHONY: restart-flexprice
restart-flexprice: stop-flexprice start-flexprice
@echo "Flexprice services restarted successfully"
# Full developer setup with clear instructions
.PHONY: dev-setup
dev-setup:
@echo "Setting up FlexPrice development environment..."
@echo "Step 1: Starting infrastructure services..."
@docker compose up -d postgres kafka clickhouse temporal temporal-ui
@echo "Step 2: Building FlexPrice application image..."
@make build-image
@echo "Step 3: Running database migrations and initializing Kafka..."
@make init-db init-kafka migrate-ent seed-db
@echo "Step 4: Starting FlexPrice services..."
@make start-flexprice
@echo ""
@echo "✅ FlexPrice development environment is now ready!"
@echo "📊 Available services:"
@echo " - API: http://localhost:8080"
@echo " - Temporal UI: http://localhost:8088"
@echo " - Kafka UI: http://localhost:8084 (with profile 'dev')"
@echo " - ClickHouse: http://localhost:8123"
@echo ""
@echo "💡 Useful commands:"
@echo " - make restart-flexprice # Restart FlexPrice services"
@echo " - make down # Stop all services"
@echo " - make clean-start # Clean everything and start fresh"
.PHONY: apply-migration
apply-migration:
@if [ -z "$(file)" ]; then \
echo "Error: Migration file not specified. Use 'make apply-migration file=<path>'"; \
exit 1; \
fi
@echo "Applying migration file: $(file)"
@PGPASSWORD=$(shell grep -A 2 "postgres:" config.yaml | grep password | awk '{print $$2}') \
psql -h $(shell grep -A 2 "postgres:" config.yaml | grep host | awk '{print $$2}') \
-U $(shell grep -A 2 "postgres:" config.yaml | grep username | awk '{print $$2}') \
-d $(shell grep -A 2 "postgres:" config.yaml | grep database | awk '{print $$2}') \
-f $(file)
@echo "Migration applied successfully"
.PHONY: docker-build-local
docker-build-local:
docker compose build flexprice-build
.PHONY: install-typst
install-typst:
@./scripts/install-typst.sh
# SDK Generation targets
.PHONY: install-openapi-generator
install-openapi-generator:
@which openapi-generator-cli > /dev/null || (npm install -g @openapitools/openapi-generator-cli)
.PHONY: generate-sdk generate-go-sdk generate-python-sdk generate-javascript-sdk regenerate-sdk clean-sdk update-sdk
# Generate all SDKs
generate-sdk: generate-go-sdk generate-python-sdk generate-javascript-sdk
@echo "All SDKs generated successfully with custom files"
# Regenerate all SDKs (clean + generate)
regenerate-sdk: clean-sdk generate-sdk
@echo "All SDKs regenerated successfully with custom files"
# Update swagger and regenerate all SDKs
update-sdk: swagger regenerate-sdk
@echo "Swagger updated and all SDKs regenerated with custom files"
# Clean all generated SDKs
clean-sdk:
@echo "Cleaning generated SDKs..."
@rm -rf api/javascript api/python api/go
@echo "Generated SDKs cleaned"
# Generate Go SDK
generate-go-sdk: install-openapi-generator
@echo "Generating Go SDK..."
@openapi-generator-cli generate \
-i docs/swagger/swagger-3-0.json \
-g go \
-o api/go \
--additional-properties=packageName=flexprice,isGoSubmodule=true,enumClassPrefix=true,structPrefix=true \
--git-repo-id=go-sdk \
--git-user-id=flexprice \
--global-property apiTests=false,modelTests=false
@chmod +x api/scripts/go/add_go_async.sh
@./api/scripts/go/add_go_async.sh
@echo "Copying custom files..."
@./scripts/copy-custom-files.sh go
@echo "Go SDK generated successfully"
# Generate Python SDK
generate-python-sdk: install-openapi-generator
@echo "Generating Python SDK..."
@openapi-generator-cli generate \
-i docs/swagger/swagger-3-0.json \
-g python \
-o api/python \
--additional-properties=packageName=flexprice \
--git-repo-id=python-sdk \
--git-user-id=flexprice \
--global-property apiTests=false,modelTests=false
@python api/scripts/python/add_python_async.py || echo "Failed to add async functionality, but continuing..."
@echo "Copying custom files..."
@./scripts/copy-custom-files.sh python
@echo "Python SDK generated successfully"
# Generate JavaScript/TypeScript SDK
generate-javascript-sdk: install-openapi-generator
@echo "Generating TypeScript SDK with modern ES7 module support..."
@./scripts/generate-ts-sdk.sh
# Copy custom files to specific SDKs (manual operation)
copy-custom:
@echo "Copying custom files to all SDKs..."
@./scripts/copy-custom-files.sh javascript
@./scripts/copy-custom-files.sh python
@./scripts/copy-custom-files.sh go
copy-javascript-custom:
@echo "Copying custom files to JavaScript SDK..."
@./scripts/copy-custom-files.sh javascript
copy-python-custom:
@echo "Copying custom files to Python SDK..."
@./scripts/copy-custom-files.sh python
copy-go-custom:
@echo "Copying custom files to Go SDK..."
@./scripts/copy-custom-files.sh go
# Show custom files status
show-custom-files:
@echo "Custom files status:"
@echo "==================="
@echo "JavaScript custom files:"
@if [ -d "api/custom/javascript" ]; then \
find api/custom/javascript -type f -not -name "README.md" | sed 's/^/ /' || echo " No custom files found"; \
else \
echo " No custom directory found"; \
fi
@echo ""
@echo "Python custom files:"
@if [ -d "api/custom/python" ]; then \
find api/custom/python -type f -not -name "README.md" | sed 's/^/ /' || echo " No custom files found"; \
else \
echo " No custom directory found"; \
fi
@echo ""
@echo "Go custom files:"
@if [ -d "api/custom/go" ]; then \
find api/custom/go -type f -not -name "README.md" | sed 's/^/ /' || echo " No custom files found"; \
else \
echo " No custom directory found"; \
fi
# Help for SDK management
help-sdk:
@echo "SDK Management Commands:"
@echo "======================="
@echo " make generate-sdk - Generate all SDKs with custom files"
@echo " make regenerate-sdk - Clean and regenerate all SDKs"
@echo " make update-sdk - Update swagger and regenerate all SDKs"
@echo " make clean-sdk - Clean all generated SDKs"
@echo " make copy-custom - Copy custom files to all SDKs"
@echo " make show-custom-files - Show status of custom files"
@echo ""
@echo "Individual SDK Commands:"
@echo " make generate-javascript-sdk - Generate JavaScript SDK"
@echo " make generate-python-sdk - Generate Python SDK"
@echo " make generate-go-sdk - Generate Go SDK"
@echo " make copy-javascript-custom - Copy custom files to JavaScript SDK"
@echo " make copy-python-custom - Copy custom files to Python SDK"
@echo " make copy-go-custom - Copy custom files to Go SDK"
# Note: Alternative modern approach removed during cleanup
# SDK publishing
sdk-publish-js:
@api/publish.sh --js $(if $(filter true,$(DRY_RUN)),--dry-run,) $(if $(VERSION),--version $(VERSION),)
sdk-publish-py:
@api/publish.sh --py $(if $(filter true,$(DRY_RUN)),--dry-run,) $(if $(VERSION),--version $(VERSION),)
sdk-publish-go:
@api/publish.sh --go $(if $(filter true,$(DRY_RUN)),--dry-run,) $(if $(VERSION),--version $(VERSION),)
sdk-publish-all:
@api/publish.sh --all $(if $(filter true,$(DRY_RUN)),--dry-run,)
sdk-publish-all-with-version:
@echo "Usage: make sdk-publish-all-with-version VERSION=x.y.z"
@test -n "$(VERSION)" || (echo "Error: VERSION is required"; exit 1)
@api/publish.sh --all --version $(VERSION) $(if $(filter true,$(DRY_RUN)),--dry-run,)
# Test GitHub workflow locally using act
test-github-workflow:
@echo "Testing GitHub workflow locally..."
@./scripts/ensure-act.sh
@if [ ! -f .env ]; then \
echo "Error: .env file not found. Please create a .env file with SDK_DEPLOY_GIT_TOKEN, NPM_AUTH_TOKEN, and PYPI_API_TOKEN"; \
exit 1; \
fi
@SDK_DEPLOY_GIT_TOKEN=$$(grep SDK_DEPLOY_GIT_TOKEN .env | cut -d '=' -f2) \
NPM_AUTH_TOKEN=$$(grep NPM_AUTH_TOKEN .env | cut -d '=' -f2) \
PYPI_API_TOKEN=$$(grep PYPI_API_TOKEN .env | cut -d '=' -f2) \
act release -e .github/workflows/test-event.json \
-s SDK_DEPLOY_GIT_TOKEN="$$SDK_DEPLOY_GIT_TOKEN" \
-s NPM_AUTH_TOKEN="$$NPM_AUTH_TOKEN" \
-s PYPI_API_TOKEN="$$PYPI_API_TOKEN" \
-P ubuntu-latest=catthehacker/ubuntu:act-latest \
--container-architecture linux/amd64 \
--action-offline-mode
.PHONY: sdk-publish-js sdk-publish-py sdk-publish-go sdk-publish-all sdk-publish-all-with-version test-github-workflow show-custom-files help-sdk