-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
1424 lines (1286 loc) · 60.1 KB
/
Copy pathMakefile
File metadata and controls
1424 lines (1286 loc) · 60.1 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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Makefile
# Variables
ADMIN_FRONTEND_DIR := ui/admin-frontend
FORCE_BUILD := false
SKIP_FRONTEND := false
SKIP_DOCS := false
# Detect if enterprise submodule exists and is initialized
ENTERPRISE_EXISTS := $(shell test -f enterprise/.git && echo "yes" || echo "no")
ifeq ($(ENTERPRISE_EXISTS),yes)
BUILD_TAGS := -tags enterprise
EDITION := ent
$(info 🏢 Building Enterprise Edition)
else
BUILD_TAGS :=
EDITION := ce
$(info 🌍 Building Community Edition)
endif
# Version information (from git tags)
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
# Build flags for production (optimized, stripped, with version info)
PROD_LDFLAGS := -ldflags="-w -s -X main.Version=$(VERSION) -X main.BuildHash=$(BUILD_HASH) -X main.BuildTime=$(BUILD_TIME)" -trimpath
# Build flags for development (with version info, no stripping)
DEV_LDFLAGS := -ldflags="-X main.Version=$(VERSION) -X main.BuildHash=$(BUILD_HASH) -X main.BuildTime=$(BUILD_TIME)"
# Default target
.DEFAULT_GOAL := help
all: build
# Help target
help:
@echo "Tyk AI Studio Build Targets"
@echo ""
@echo "Current edition: $(EDITION)"
@echo ""
@echo "🐳 Docker Development (RECOMMENDED - with hot reloading):"
@echo " make dev - Start minimal env (Studio + Frontend + Postgres)"
@echo " make dev-full - Start full stack (+ Gateway + Plugins)"
@echo " make dev-ent - Start enterprise minimal env"
@echo " make dev-full-ent - Start enterprise full stack (no plugin builds)"
@echo " make dev-full-ent-plugins - Same, plus build/watch all plugins"
@echo " make dev-down - Stop development environment"
@echo " make dev-help - Show all development commands"
@echo ""
@echo "Development (single platform, fast):"
@echo " make build-native - Build for current platform with CGO (auto-detect edition)"
@echo " make build-native-ce - Build CE for current platform with CGO"
@echo " make build-native-ent - Build ENT for current platform with CGO"
@echo " make build-local - Alias for build-native (backward compatible)"
@echo ""
@echo "Development flags:"
@echo " SKIP_FRONTEND=true - Skip frontend build (for faster iteration)"
@echo " SKIP_DOCS=true - Skip docs build (for faster iteration)"
@echo " Example: make build-native-ce SKIP_FRONTEND=true SKIP_DOCS=true"
@echo ""
@echo "Production (multi-platform, optimized, CGO-enabled):"
@echo " make build-prod - Build all platforms with CGO (auto-detect edition)"
@echo " make build-prod-ce - Build CE for all platforms with CGO"
@echo " make build-prod-ent - Build ENT for all platforms with CGO"
@echo ""
@echo "Platform-specific (CGO-enabled):"
@echo " make build-linux-amd64 - Linux AMD64 with CGO"
@echo " make build-linux-arm64 - Linux ARM64 with CGO (requires cross-compiler)"
@echo " make build-darwin-amd64 - Darwin AMD64 with CGO"
@echo " make build-darwin-arm64 - Darwin ARM64 with CGO"
@echo ""
@echo "Plugin Development:"
@echo " make tools - Build development tools (plugin-scaffold)"
@echo " make plugin-new - Scaffold a new plugin (NAME=x TYPE=y [CAPABILITIES=a,b])"
@echo " make plugin-help - Show plugin scaffolding help"
@echo " make plugins - Build all example plugins"
@echo " make plugin-publish - Build, sign, push a plugin + index it (NAME=x [VERSION=y])"
@echo " make plugin-verify - Check a published plugin's digest and signature (NAME=x|all)"
@echo " (guide: docs/site/docs/plugins-publishing.md)"
@echo ""
@echo "Packaging (RPM/DEB via GoReleaser + nfpm):"
@echo " make package - Build all packages (auto-detect edition)"
@echo " make package-ce - Build CE packages (both components)"
@echo " make package-ent - Build ENT packages (both components)"
@echo " make package-help - Show all packaging targets"
@echo " make test-package-smoke - Build CE packages and run smoke tests"
@echo ""
@echo "Other targets:"
@echo " make test - Run tests"
@echo " make clean - Clean build artifacts"
@echo " make show-edition - Show current edition info"
@echo ""
@echo "Integration Tests (requires Docker):"
@echo " make test-integration - Run all integration tests"
@echo " make test-integration-plugin-cache - Run cache plugin integration tests"
@echo " make test-integration-plugin-cache-full - Run all cache plugin tests (with cluster+syslog)"
@echo " make test-integration-plugin-cache-coverage - Run with coverage report"
@echo " make test-integration-plugin-github-rag - Run github-rag-ingest Vault integration tests"
@echo ""
# Build target (default to production multi-platform builds)
build: build-prod
# Build frontend (can be skipped with SKIP_FRONTEND=true)
build-frontend:
ifeq ($(SKIP_FRONTEND),true)
@echo "⏭️ Skipping frontend build (SKIP_FRONTEND=true)"
else
@echo "🔨 Building frontend..."
cd $(ADMIN_FRONTEND_DIR) && npm run build
endif
# Build documentation site (can be skipped with SKIP_DOCS=true)
build-docs:
ifeq ($(SKIP_DOCS),true)
@echo "⏭️ Skipping docs build (SKIP_DOCS=true)"
else
@echo "📚 Building documentation..."
cd docs/site && npm ci && npm run docs:build
endif
# ============================================================================
# Development Builds (single platform, fast, CGO enabled)
# ============================================================================
# Build for native platform (auto-detect edition)
build-native: build-frontend build-docs
@echo "🔨 Building $(EDITION) for native platform with CGO..."
@mkdir -p bin
CGO_ENABLED=1 go build $(BUILD_TAGS) $(DEV_LDFLAGS) -o bin/midsommar-$(EDITION)
cd microgateway && $(MAKE) build
cp microgateway/dist/microgateway-$(EDITION) bin/mgw-$(EDITION)
chmod +x bin/*
@echo "✅ Native build complete: bin/midsommar-$(EDITION) and bin/mgw-$(EDITION)"
# Build CE for native platform
build-native-ce: build-frontend build-docs
@echo "🔨 Building CE for native platform with CGO..."
@mkdir -p bin
CGO_ENABLED=1 go build $(DEV_LDFLAGS) -o bin/midsommar-ce
cd microgateway && $(MAKE) build-community
cp microgateway/dist/microgateway-ce bin/mgw-ce
chmod +x bin/*
@echo "✅ Native CE build complete"
# Build ENT for native platform
build-native-ent: build-frontend build-docs
@if [ ! -f enterprise/.git ]; then \
echo "❌ ERROR: Enterprise submodule not initialized."; \
echo "Run: make init-enterprise"; \
exit 1; \
fi
@echo "🔨 Building ENT for native platform with CGO..."
@mkdir -p bin
CGO_ENABLED=1 go build -tags enterprise $(DEV_LDFLAGS) -o bin/midsommar-ent
cd microgateway && $(MAKE) build-enterprise
cp microgateway/dist/microgateway-ent bin/mgw-ent
chmod +x bin/*
@echo "✅ Native ENT build complete"
# ============================================================================
# Production Builds (multi-platform, optimized, CGO enabled)
# ============================================================================
# Build production artifacts for all platforms (auto-detect edition)
build-prod: build-frontend
@echo "🏗️ Building production $(EDITION) artifacts..."
@mkdir -p bin
$(MAKE) build-linux-amd64 EDITION=$(EDITION) BUILD_TAGS="$(BUILD_TAGS)"
$(MAKE) build-linux-arm64 EDITION=$(EDITION) BUILD_TAGS="$(BUILD_TAGS)"
$(MAKE) build-darwin-amd64 EDITION=$(EDITION) BUILD_TAGS="$(BUILD_TAGS)"
$(MAKE) build-darwin-arm64 EDITION=$(EDITION) BUILD_TAGS="$(BUILD_TAGS)"
cd microgateway && $(MAKE) build-prod EDITION=$(EDITION)
cp microgateway/dist/microgateway-$(EDITION)-linux-amd64 bin/mgw-$(EDITION)-linux-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-$(EDITION)-linux-arm64 bin/mgw-$(EDITION)-linux-arm64 2>/dev/null || true
cp microgateway/dist/microgateway-$(EDITION)-darwin-amd64 bin/mgw-$(EDITION)-darwin-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-$(EDITION)-darwin-arm64 bin/mgw-$(EDITION)-darwin-arm64 2>/dev/null || true
chmod +x bin/* 2>/dev/null || true
@echo "✅ Production build complete"
# Build production CE for all platforms
build-prod-ce: build-frontend
@echo "🏗️ Building production CE artifacts..."
@mkdir -p bin
$(MAKE) build-linux-amd64 EDITION=ce BUILD_TAGS=""
$(MAKE) build-linux-arm64 EDITION=ce BUILD_TAGS=""
$(MAKE) build-darwin-amd64 EDITION=ce BUILD_TAGS=""
$(MAKE) build-darwin-arm64 EDITION=ce BUILD_TAGS=""
cd microgateway && $(MAKE) build-prod-ce
cp microgateway/dist/microgateway-ce-linux-amd64 bin/mgw-ce-linux-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-ce-linux-arm64 bin/mgw-ce-linux-arm64 2>/dev/null || true
cp microgateway/dist/microgateway-ce-darwin-amd64 bin/mgw-ce-darwin-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-ce-darwin-arm64 bin/mgw-ce-darwin-arm64 2>/dev/null || true
chmod +x bin/* 2>/dev/null || true
@echo "✅ Production CE build complete"
# Build production ENT for all platforms
build-prod-ent: build-frontend
@if [ ! -f enterprise/.git ]; then \
echo "❌ ERROR: Enterprise submodule not initialized."; \
echo "Run: make init-enterprise"; \
exit 1; \
fi
@echo "🏗️ Building production ENT artifacts..."
@mkdir -p bin
$(MAKE) build-linux-amd64 EDITION=ent BUILD_TAGS="-tags enterprise"
$(MAKE) build-linux-arm64 EDITION=ent BUILD_TAGS="-tags enterprise"
$(MAKE) build-darwin-amd64 EDITION=ent BUILD_TAGS="-tags enterprise"
$(MAKE) build-darwin-arm64 EDITION=ent BUILD_TAGS="-tags enterprise"
cd microgateway && $(MAKE) build-prod-ent
cp microgateway/dist/microgateway-ent-linux-amd64 bin/mgw-ent-linux-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-ent-linux-arm64 bin/mgw-ent-linux-arm64 2>/dev/null || true
cp microgateway/dist/microgateway-ent-darwin-amd64 bin/mgw-ent-darwin-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-ent-darwin-arm64 bin/mgw-ent-darwin-arm64 2>/dev/null || true
chmod +x bin/* 2>/dev/null || true
@echo "✅ Production ENT build complete"
# ============================================================================
# Platform-Specific Builds (CGO enabled)
# ============================================================================
# Linux AMD64 with CGO
build-linux-amd64:
@echo "Building midsommar $(EDITION) for linux/amd64 with CGO..."
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build $(BUILD_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-linux-amd64
# Linux ARM64 with CGO (requires cross-compiler)
build-linux-arm64:
@echo "Building midsommar $(EDITION) for linux/arm64 with CGO..."
@if ! which aarch64-linux-gnu-gcc > /dev/null 2>&1; then \
echo "⚠️ Warning: aarch64-linux-gnu-gcc not found"; \
echo " Install: sudo apt-get install gcc-aarch64-linux-gnu (Ubuntu/Debian)"; \
echo " Or: brew install FiloSottile/musl-cross/musl-cross (macOS)"; \
echo " Attempting build anyway..."; \
fi
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 \
CC=aarch64-linux-gnu-gcc \
go build $(BUILD_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-linux-arm64
# Darwin AMD64 with CGO
build-darwin-amd64:
@echo "Building midsommar $(EDITION) for darwin/amd64 with CGO..."
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \
go build $(BUILD_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-darwin-amd64
# Darwin ARM64 with CGO
build-darwin-arm64:
@echo "Building midsommar $(EDITION) for darwin/arm64 with CGO..."
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 \
go build $(BUILD_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-darwin-arm64
# ============================================================================
# Backward Compatibility Targets
# ============================================================================
# Build for local development (alias for build-native)
build-local: build-native
# Legacy build-community (now uses explicit CGO builds)
build-community: build-prod-ce
@echo "Note: build-community now builds production artifacts with CGO"
@echo "For quick local builds, use: make build-native-ce"
# Legacy build-enterprise (now uses explicit CGO builds)
build-enterprise: build-prod-ent
@echo "Note: build-enterprise now builds production artifacts with CGO"
@echo "For quick local builds, use: make build-native-ent"
# ============================================================================
# Package Building (RPM/DEB using GoReleaser + nfpm)
# ============================================================================
# These targets use the SAME GoReleaser configs and Docker image as CI,
# ensuring local packages are identical to release packages.
#
# Builds run inside the tykio/golang-cross Docker container (same as CI)
# because CGO cross-compilation requires Linux cross-compiler toolchains.
#
# Prerequisites:
# Docker must be running
#
# Usage:
# make package Build all packages (auto-detect edition)
# make package-studio Build AI Studio packages only
# make package-microgateway Build Microgateway packages only
# make package-ce Build CE packages for both components
# make package-ent Build ENT packages for both components
# ============================================================================
GOLANG_CROSS_IMAGE ?= tykio/golang-cross:1.26-bullseye
GORELEASER_FLAGS ?= --snapshot --skip=sign --skip=publish --clean
# Internal helper: run goreleaser inside the cross-compilation Docker container.
# Usage: $(call run_goreleaser,<goreleaser-config>,<goflags>)
# This matches CI exactly: same image, same env vars, same goreleaser invocation.
# NOTE: does NOT use --clean to allow building both components into the same dist/.
# Use `make clean-dist` to reset before a fresh build.
define run_goreleaser
docker run --rm --platform linux/amd64 \
-e CGO_ENABLED=1 \
-e GOFLAGS='$(2)' \
-e PACKAGECLOUD_REPO=local/dev \
-e DEBVERS='unused' \
-e RPMVERS='unused' \
-e GOCACHE=/cache/go-build \
-e GOMODCACHE=/go/pkg/mod \
-v $(CURDIR):/go/src/github.com/TykTechnologies/midsommar \
-v $(HOME)/go/pkg/mod:/go/pkg/mod \
-v $(HOME)/.cache/go-build:/cache/go-build \
-w /go/src/github.com/TykTechnologies/midsommar \
$(GOLANG_CROSS_IMAGE) \
goreleaser release -f $(1) $(GORELEASER_FLAGS)
endef
clean-dist:
rm -rf dist/
.PHONY: package package-studio package-microgateway package-ce package-ent
.PHONY: package-studio-ce package-studio-ent package-microgateway-ce package-microgateway-ent
.PHONY: package-help test-package-smoke test-package-smoke-ent
# Build all packages for current edition
package: clean-dist package-studio package-microgateway
@echo "✅ All packages built in dist/"
@ls -la dist/*.deb dist/*.rpm 2>/dev/null || echo "No packages found"
# Build AI Studio packages (current edition)
package-studio: build-frontend build-docs
@echo "📦 Building AI Studio $(EDITION) packages..."
$(call run_goreleaser,ci/goreleaser/goreleaser.yml,$(BUILD_TAGS))
@echo "✅ AI Studio packages:"
@ls -la dist/tyk-ai-studio*.deb dist/tyk-ai-studio*.rpm 2>/dev/null
# Build Microgateway packages (current edition)
package-microgateway:
@echo "📦 Building Microgateway $(EDITION) packages..."
$(call run_goreleaser,ci/goreleaser/goreleaser-microgateway.yml,$(BUILD_TAGS))
@echo "✅ Microgateway packages:"
@ls -la dist/tyk-microgateway*.deb dist/tyk-microgateway*.rpm 2>/dev/null
# CE variants
# GoReleaser uses --clean which wipes dist/ each run. For combined builds,
# we save studio packages to .dist-staging/ (outside dist/) then merge after mgw build.
package-ce: build-frontend build-docs
@echo "📦 Building all CE packages..."
$(call run_goreleaser,ci/goreleaser/goreleaser.yml,)
@mkdir -p .dist-staging && cp dist/*.deb dist/*.rpm .dist-staging/ 2>/dev/null || true
$(call run_goreleaser,ci/goreleaser/goreleaser-microgateway.yml,)
@cp .dist-staging/* dist/ 2>/dev/null || true
@rm -rf .dist-staging
@echo "✅ CE packages:"
@ls dist/*.deb dist/*.rpm 2>/dev/null
# ENT variants
package-ent: build-frontend build-docs
@if [ ! -f enterprise/.git ]; then \
echo "❌ ERROR: Enterprise submodule not initialized. Run: make init-enterprise"; \
exit 1; \
fi
@echo "📦 Building all ENT packages..."
$(call run_goreleaser,ci/goreleaser/goreleaser.yml,-tags=enterprise)
@mkdir -p .dist-staging && cp dist/*.deb dist/*.rpm .dist-staging/ 2>/dev/null || true
$(call run_goreleaser,ci/goreleaser/goreleaser-microgateway.yml,-tags=enterprise)
@cp .dist-staging/* dist/ 2>/dev/null || true
@rm -rf .dist-staging
@echo "✅ ENT packages:"
@ls dist/*.deb dist/*.rpm 2>/dev/null
# Package smoke tests
test-package-smoke: package-ce
@echo "🧪 Running package smoke tests (CE)..."
docker compose -f tests/packaging/compose.yml up -d --build --wait
cd tests/packaging && npx playwright install --with-deps chromium && npx playwright test --reporter=list || \
(docker compose -f ../../tests/packaging/compose.yml logs && exit 1)
docker compose -f tests/packaging/compose.yml down -v
@echo "✅ Package smoke tests passed"
test-package-smoke-ent: package-ent
@echo "🧪 Running package smoke tests (ENT)..."
@# Source license from dev/.env.secrets if available
$(eval export TYK_AI_LICENSE=$(shell grep -s '^TYK_AI_LICENSE=' dev/.env.secrets | cut -d= -f2-))
@if [ -z "$$TYK_AI_LICENSE" ]; then \
echo "⚠️ Warning: TYK_AI_LICENSE not set. ENT smoke tests may fail."; \
echo " Set it in dev/.env.secrets or export TYK_AI_LICENSE=..."; \
fi
docker compose -f tests/packaging/compose.yml up -d --build --wait
cd tests/packaging && npx playwright install --with-deps chromium && npx playwright test --reporter=list || \
(docker compose -f ../../tests/packaging/compose.yml logs && exit 1)
docker compose -f tests/packaging/compose.yml down -v
@echo "✅ Package smoke tests passed"
# Package help
package-help:
@echo "Package Building Targets (all run inside Docker for cross-compilation)"
@echo ""
@echo " make package Build all packages (auto-detect edition)"
@echo " make package-studio Build AI Studio packages"
@echo " make package-microgateway Build Microgateway packages"
@echo " make package-ce Build all CE packages"
@echo " make package-ent Build all ENT packages"
@echo " make package-studio-ce Build AI Studio CE packages"
@echo " make package-studio-ent Build AI Studio ENT packages"
@echo " make package-microgateway-ce Build Microgateway CE packages"
@echo " make package-microgateway-ent Build Microgateway ENT packages"
@echo " make test-package-smoke Build CE packages and run smoke tests"
@echo " make test-package-smoke-ent Build ENT packages and run smoke tests"
@echo ""
@echo "Packages output to dist/ directory"
@echo "Override Docker image: GOLANG_CROSS_IMAGE=... make package"
# Build all plugins
plugins:
@echo "Building studio plugins..."
@failed_plugins=""; \
for plugin in examples/plugins/studio/*/; do \
if [ -d "$$plugin/server" ]; then \
plugin_name=$$(basename "$$plugin"); \
echo "Building studio plugin: $$plugin_name"; \
if (cd "$$plugin/server" && go build -o ../$$plugin_name); then \
echo " ✓ Successfully built $$plugin_name"; \
else \
echo " ✗ Failed to build $$plugin_name"; \
failed_plugins="$$failed_plugins $$plugin_name"; \
fi; \
fi; \
done; \
echo "Building gateway plugins..."; \
for plugin in examples/plugins/gateway/*/; do \
if [ -f "$$plugin/main.go" ]; then \
plugin_name=$$(basename "$$plugin"); \
echo "Building gateway plugin: $$plugin_name"; \
if (cd microgateway && go build -o "../$$plugin/$$plugin_name" "../$$plugin"); then \
echo " ✓ Successfully built $$plugin_name"; \
else \
echo " ✗ Failed to build $$plugin_name"; \
failed_plugins="$$failed_plugins $$plugin_name"; \
fi; \
fi; \
done; \
if [ -n "$$failed_plugins" ]; then \
echo ""; \
echo "⚠️ Some plugins failed to build:$$failed_plugins"; \
echo "The following plugins built successfully can be used."; \
else \
echo ""; \
echo "✅ All plugins built successfully!"; \
fi
# ============================================================================
# Plugin Scaffolding
# ============================================================================
# Usage:
# make plugin-new NAME=my-plugin TYPE=studio
# make plugin-new NAME=my-plugin TYPE=studio CAPABILITIES=studio_ui,post_auth,on_response
# make plugin-new NAME=my-enricher TYPE=gateway
# make plugin-new NAME=my-assistant TYPE=agent
# make plugin-help
.PHONY: plugin-new plugin-help tools
# Build all development tools
tools: bin/plugin-scaffold
@echo "✅ Development tools built successfully"
@echo " - bin/plugin-scaffold (plugin scaffolding)"
# Build the scaffolding tool (rebuilds only if source changes)
bin/plugin-scaffold: $(wildcard cmd/plugin-scaffold/*.go)
@echo "Building plugin-scaffold tool..."
@mkdir -p bin
@go build -o bin/plugin-scaffold ./cmd/plugin-scaffold
# Scaffold a new plugin
plugin-new: bin/plugin-scaffold
@if [ -z "$(NAME)" ] || [ -z "$(TYPE)" ]; then \
echo "Usage: make plugin-new NAME=my-plugin TYPE=studio|gateway|agent|data-collector [CAPABILITIES=cap1,cap2]"; \
echo ""; \
echo "Run 'make plugin-help' for more information."; \
exit 1; \
fi
@./bin/plugin-scaffold -name="$(NAME)" -type="$(TYPE)" -capabilities="$(CAPABILITIES)"
# Show plugin scaffolding help
plugin-help: bin/plugin-scaffold
@./bin/plugin-scaffold -help
# ============================================================================
# Plugin Release (build -> sign -> push -> marketplace index entry)
# ============================================================================
# One command takes a plugin from source to a signed, indexed marketplace
# release. The version comes from the plugin's manifest.json and is used
# verbatim as the OCI tag, and the digest written into the marketplace entry is
# read back from the registry - so the tag, the binary and the index entry
# cannot drift apart.
#
# Usage:
# make plugin-publish NAME=llm-cache SIGN_KEY=~/keys/plugin-ci.key
# make plugin-publish NAME=llm-cache DRY_RUN=1 # print the plan, push nothing
# make plugin-publish NAME=llm-cache YES=1 # no confirmation prompt (CI)
# make plugin-publish NAME=llm-cache NO_PUSH=1 # commit the entry, don't push it
# make plugin-verify NAME=llm-cache [VERSION=1.0.1] PUB_KEY=~/keys/plugin-ci.pub
#
# Variables: NAME (required), VERSION, REG, PLATFORMS, SIGN_KEY, PUB_KEY,
# MIN_STUDIO_VERSION, DRY_RUN, YES, NO_PUSH, FORCE, SKIP_SIGN,
# SKIP_UI, SKIP_MARKETPLACE
#
# Full guide: docs/site/docs/plugins-publishing.md
.PHONY: plugin-publish plugin-verify
# This Makefile defines its own VERSION (the git describe of the platform), so
# only forward VERSION to the script when it was set on the command line - and
# blank it in the recipe environment so the platform version can never be
# mistaken for a plugin version.
PLUGIN_VERSION_FLAG :=
ifeq ($(origin VERSION),command line)
PLUGIN_VERSION_FLAG := --version "$(VERSION)"
endif
plugin-publish:
@if [ -z "$(NAME)" ]; then \
echo "Usage: make plugin-publish NAME=<plugin> [VERSION=x.y.z] SIGN_KEY=/path/to/plugin-ci.key"; \
echo ""; \
echo "Plugins are looked up under community/plugins, enterprise/plugins,"; \
echo "tyk-internal/plugins and examples/plugins."; \
echo "Add DRY_RUN=1 to see the full plan without pushing anything."; \
echo ""; \
echo "Full guide: docs/site/docs/plugins-publishing.md"; \
echo "All flags: ./tools/publish-plugin.sh --help"; \
exit 1; \
fi
@env VERSION= ./tools/publish-plugin.sh publish "$(NAME)" $(PLUGIN_VERSION_FLAG)
plugin-verify:
@if [ -z "$(NAME)" ]; then \
echo "Usage: make plugin-verify NAME=<plugin>|all [VERSION=x.y.z] [PUB_KEY=/path/to/plugin-ci.pub]"; \
echo ""; \
echo "NAME=all audits every published entry in both marketplace repos."; \
echo "Full guide: docs/site/docs/plugins-publishing.md"; \
exit 1; \
fi
@env VERSION= ./tools/publish-plugin.sh verify "$(NAME)" $(PLUGIN_VERSION_FLAG)
# Test target (legacy - use test-all for more control)
test:
go test $(BUILD_TAGS) ./...
cd microgateway && go test $(BUILD_TAGS) ./...
# ============================================================================
# Unified Testing System
# ============================================================================
# Usage:
# make test-all # Run unit + integration tests (auto-detect edition)
# make test-all EDITION=ent # Run with enterprise edition
# make test-quick # Unit tests only (fast feedback)
# make test-ci # CI tests with coverage
# make test-all TEST_COMPONENTS="studio" # Test only studio
# make test-all TEST_TYPES="unit" # Unit tests only
#
# Components: studio, microgateway, frontend, plugins
# Types: unit, integration, e2e
# Editions: ce, ent
# Test configuration variables (can be overridden)
TEST_COMPONENTS ?= studio microgateway frontend plugins enterprise
TEST_TYPES ?= unit integration
TEST_EDITION ?= $(EDITION)
TEST_VERBOSE ?= false
TEST_COVERAGE ?= false
TEST_TIMEOUT ?= 30m
# Determine build tags based on edition
ifeq ($(TEST_EDITION),ent)
TEST_BUILD_TAGS := -tags enterprise
else
TEST_BUILD_TAGS :=
endif
# Verbose flag
ifeq ($(TEST_VERBOSE),true)
TEST_VERBOSE_FLAG := -v
else
TEST_VERBOSE_FLAG :=
endif
# Coverage flag
ifeq ($(TEST_COVERAGE),true)
TEST_COVERAGE_FLAG := -coverprofile=coverage.out -covermode=atomic
else
TEST_COVERAGE_FLAG :=
endif
# Primary unified test target
.PHONY: test-all
test-all: ## Run all tests with configurable options
@echo "=========================================="
@echo "Tyk AI Studio Unified Test Suite"
@echo "=========================================="
@echo "Edition: $(TEST_EDITION)"
@echo "Components: $(TEST_COMPONENTS)"
@echo "Types: $(TEST_TYPES)"
@echo "Timeout: $(TEST_TIMEOUT)"
@echo "=========================================="
@failed=0; \
for component in $(TEST_COMPONENTS); do \
for type in $(TEST_TYPES); do \
target="test-$${component}-$${type}"; \
if $(MAKE) -n $$target > /dev/null 2>&1; then \
echo ""; \
echo ">>> Running: $$target"; \
if ! $(MAKE) $$target TEST_EDITION=$(TEST_EDITION) TEST_VERBOSE=$(TEST_VERBOSE) TEST_COVERAGE=$(TEST_COVERAGE) TEST_TIMEOUT=$(TEST_TIMEOUT); then \
echo "FAILED: $$target"; \
failed=1; \
fi; \
fi; \
done; \
done; \
if [ $$failed -eq 1 ]; then \
echo ""; \
echo "=========================================="; \
echo "SOME TESTS FAILED"; \
echo "=========================================="; \
exit 1; \
fi; \
echo ""; \
echo "=========================================="; \
echo "ALL TESTS PASSED"; \
echo "=========================================="
.PHONY: test-quick
test-quick: ## Run only unit tests (fast feedback)
$(MAKE) test-all TEST_TYPES="unit" TEST_COMPONENTS="studio microgateway frontend"
.PHONY: test-ci
test-ci: ## Run CI-appropriate tests (unit + integration, with coverage)
$(MAKE) test-all TEST_TYPES="unit integration" TEST_COVERAGE=true TEST_VERBOSE=true
# ============================================================================
# AI Studio Tests
# ============================================================================
.PHONY: test-studio-unit
test-studio-unit: ## Run AI Studio unit tests
@echo "Running AI Studio unit tests ($(TEST_EDITION))..."
go test $(TEST_BUILD_TAGS) $(TEST_VERBOSE_FLAG) $(TEST_COVERAGE_FLAG) \
-timeout $(TEST_TIMEOUT) -race -short ./...
.PHONY: test-studio-integration
test-studio-integration: ## Run AI Studio integration tests
@echo "Running AI Studio integration tests ($(TEST_EDITION))..."
go test $(TEST_BUILD_TAGS) $(TEST_VERBOSE_FLAG) \
-timeout $(TEST_TIMEOUT) -count=1 ./tests/...
# ============================================================================
# Microgateway Tests
# ============================================================================
.PHONY: test-microgateway-unit
test-microgateway-unit: ## Run Microgateway unit tests
@echo "Running Microgateway unit tests ($(TEST_EDITION))..."
cd microgateway && go test $(TEST_BUILD_TAGS) $(TEST_VERBOSE_FLAG) \
-timeout $(TEST_TIMEOUT) -race -short ./...
.PHONY: test-microgateway-integration
test-microgateway-integration: ## Run Microgateway integration tests
@echo "Running Microgateway integration tests ($(TEST_EDITION))..."
cd microgateway && go test $(TEST_BUILD_TAGS) $(TEST_VERBOSE_FLAG) \
-timeout $(TEST_TIMEOUT) -count=1 ./tests/integration/...
# ============================================================================
# Live Vendor Conformance Tests
# ============================================================================
#
# Calls REAL LLM vendors and spends REAL money. Gated twice over -- the
# `vendorlive` build tag AND VENDOR_TESTS_ENABLED=true -- so it can never be
# picked up by `go test ./...`, `make test-all` or CI by accident.
#
# Setup: cp test-secrets/vendors.env.example test-secrets/vendors.env
# $EDITOR test-secrets/vendors.env
# Design: features/VendorConformance.md
#
# Filters (all optional, comma separated):
# VENDORS=openai,anthropic SURFACES=shim,universal SCENARIOS=tools
VENDOR_TEST_TIMEOUT ?= 30m
.PHONY: test-vendors
test-vendors: ## Run live vendor conformance tests (needs test-secrets/vendors.env)
@if [ ! -f test-secrets/vendors.env ]; then \
echo "test-secrets/vendors.env not found."; \
echo " cp test-secrets/vendors.env.example test-secrets/vendors.env"; \
exit 1; \
fi
@echo "Running live vendor conformance tests (gateway surfaces)..."
cd microgateway && VENDOR_TESTS_VENDORS="$(VENDORS)" \
VENDOR_TESTS_SURFACES="$(SURFACES)" \
VENDOR_TESTS_SCENARIOS="$(SCENARIOS)" \
go test -tags vendorlive -v -count=1 \
-timeout $(VENDOR_TEST_TIMEOUT) ./tests/vendorconformance/...
.PHONY: test-vendors-preflight
test-vendors-preflight: ## Verify vendor credentials and model IDs without spending on completions
cd microgateway && VENDOR_TESTS_VENDORS="$(VENDORS)" \
go test -tags vendorlive -v -count=1 \
-timeout 5m -run 'TestPreflight' ./tests/vendorconformance/...
.PHONY: test-vendors-update-golden
test-vendors-update-golden: ## Refresh golden envelope snapshots
cd microgateway && VENDOR_TESTS_UPDATE_GOLDEN=true \
VENDOR_TESTS_VENDORS="$(VENDORS)" \
go test -tags vendorlive -v -count=1 \
-timeout $(VENDOR_TEST_TIMEOUT) ./tests/vendorconformance/...
.PHONY: test-vendors-harness
test-vendors-harness: ## Run the credential-free unit tests that protect the conformance harness itself
go test -count=1 ./pkg/testinfra/vendorconformance/...
# ============================================================================
# Frontend Tests
# ============================================================================
.PHONY: test-frontend-unit
test-frontend-unit: ## Run frontend Jest tests
@echo "Running frontend unit tests..."
cd ui/admin-frontend && npm test
# ============================================================================
# Plugin Tests
# ============================================================================
.PHONY: test-plugins-unit
test-plugins-unit: ## Run plugin unit tests (all community + enterprise plugin modules)
@echo "Running plugin unit tests ($(TEST_EDITION))..."
@failed=""; \
for mod in $$(find community/plugins -name go.mod 2>/dev/null | sort); do \
dir=$$(dirname $$mod); \
echo ""; echo ">>> $$dir"; \
( cd $$dir && go test $(TEST_VERBOSE_FLAG) -timeout $(TEST_TIMEOUT) ./... ) \
|| failed="$$failed $$dir"; \
done; \
if [ "$(TEST_EDITION)" = "ent" ]; then \
for mod in $$(find enterprise/plugins -name go.mod 2>/dev/null | sort); do \
dir=$$(dirname $$mod); \
echo ""; echo ">>> $$dir (enterprise)"; \
( cd $$dir && go test -tags enterprise $(TEST_VERBOSE_FLAG) -timeout $(TEST_TIMEOUT) ./... ) \
|| failed="$$failed $$dir"; \
done; \
else \
echo "Skipping enterprise plugin unit tests (set EDITION=ent to enable)"; \
fi; \
if [ -n "$$failed" ]; then \
echo ""; echo "FAILED plugin modules:$$failed"; exit 1; \
fi
# ============================================================================
# Enterprise Module Tests
# ============================================================================
.PHONY: test-enterprise-unit
test-enterprise-unit: ## Run enterprise module unit tests (features/, scripting/, ...)
@if [ "$(TEST_EDITION)" != "ent" ] || [ ! -f enterprise/go.mod ]; then \
echo "Skipping enterprise module unit tests (set EDITION=ent to enable)"; \
exit 0; \
fi; \
echo "Running enterprise module unit tests..."; \
cd enterprise && go test -tags enterprise $(TEST_VERBOSE_FLAG) -timeout $(TEST_TIMEOUT) ./...
.PHONY: test-plugins-integration
test-plugins-integration: ## Run plugin integration tests (requires Docker)
@if [ "$(TEST_EDITION)" != "ent" ]; then \
echo "Skipping enterprise plugin integration tests (set EDITION=ent to enable)"; \
exit 0; \
fi
@echo "Running enterprise plugin integration tests..."
@echo ">>> advanced-llm-cache integration tests"
cd enterprise/plugins/advanced-llm-cache && \
go test -v -count=1 -tags="integration,enterprise" \
-timeout $(TEST_TIMEOUT) ./tests/integration/...
@echo ">>> llm-load-balancer integration tests"
cd enterprise/plugins/llm-load-balancer && \
go test -v -count=1 -tags="integration,enterprise" \
-timeout $(TEST_TIMEOUT) ./tests/integration/...
@echo ">>> github-rag-ingest Vault integration tests"
@if [ -d "community/plugins/github-rag-ingest/server" ]; then \
cd community/plugins/github-rag-ingest/server && \
go test -v -count=1 -tags=integration -timeout $(TEST_TIMEOUT) ./secrets/... || true; \
fi
.PHONY: test-plugins-e2e
test-plugins-e2e: ## Run plugin E2E tests (requires Docker)
@if [ "$(TEST_EDITION)" != "ent" ]; then \
echo "Skipping enterprise plugin e2e tests (set EDITION=ent to enable)"; \
exit 0; \
fi
@echo "Running enterprise plugin E2E tests..."
cd enterprise/plugins/llm-load-balancer && \
go test -v -count=1 -tags="e2e,enterprise" \
-timeout $(TEST_TIMEOUT) ./tests/e2e/...
# ============================================================================
# UI E2E Tests (Playwright)
# ============================================================================
.PHONY: test-ui-e2e
test-ui-e2e: ## Run UI E2E tests (requires Docker Compose environment)
@echo "Running UI E2E tests..."
@echo "Note: Requires Docker Compose test environment to be running"
@echo "Start with: make start-test-env"
@# Uses --workers=1 because tests share database state and will fail with race conditions if run in parallel
cd tests/ui && npm ci && npx playwright install --with-deps chromium && npm run test:serial
.PHONY: test-ui-e2e-with-env
test-ui-e2e-with-env: ## Start test env and run UI E2E tests
@echo "Starting test environment (postgres + studio + frontend)..."
docker compose -f tests/compose.yml up -d --build
@echo "Waiting for test environment to be ready..."
@attempts=0; \
max_attempts=120; \
while true; do \
backend=$$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8081/login 2>/dev/null); \
frontend=$$(curl -s -o /dev/null -w '%{http_code}' http://localhost:3000 2>/dev/null); \
if [ "$$backend" = "200" ] && [ "$$frontend" = "200" ]; then break; fi; \
attempts=$$((attempts+1)); \
echo "Waiting for AI Studio (backend=$$backend frontend=$$frontend) ($$attempts/$$max_attempts)"; \
if [ $$attempts -ge $$max_attempts ]; then \
echo "Timed out waiting for test environment"; \
docker compose -f tests/compose.yml logs --tail=100; \
docker compose -f tests/compose.yml down -v; \
exit 1; \
fi; \
sleep 5; \
done
@echo "Test environment is ready, running tests..."
$(MAKE) test-ui-e2e || (docker compose -f tests/compose.yml down -v && exit 1)
docker compose -f tests/compose.yml down -v
# ============================================================================
# Test Help and Discovery
# ============================================================================
.PHONY: test-help
test-help: ## Show testing system help
@echo "Tyk AI Studio Unified Testing System"
@echo ""
@echo "Primary Targets:"
@echo " make test-all Run all tests (default: unit + integration)"
@echo " make test-quick Run only unit tests (fast feedback)"
@echo " make test-ci Run CI tests with coverage"
@echo ""
@echo "Component Targets:"
@echo " make test-studio-unit AI Studio Go unit tests"
@echo " make test-studio-integration AI Studio integration tests"
@echo " make test-microgateway-unit Microgateway unit tests"
@echo " make test-microgateway-integration Microgateway integration tests"
@echo " make test-frontend-unit Frontend Jest tests"
@echo " make test-plugins-unit Plugin unit tests"
@echo " make test-plugins-integration Plugin integration tests (Docker required)"
@echo " make test-plugins-e2e Plugin E2E tests (Docker required)"
@echo " make test-ui-e2e UI Playwright E2E tests"
@echo " make test-ui-e2e-with-env UI E2E with auto-started environment"
@echo ""
@echo "Configuration Variables:"
@echo " TEST_EDITION=ce|ent Edition to test (default: auto-detect)"
@echo " TEST_COMPONENTS=\"...\" Components to test (space-separated)"
@echo " TEST_TYPES=\"...\" Test types to run (space-separated)"
@echo " TEST_VERBOSE=true Enable verbose output"
@echo " TEST_COVERAGE=true Generate coverage report"
@echo " TEST_TIMEOUT=30m Test timeout duration"
@echo ""
@echo "Components: studio, microgateway, frontend, plugins"
@echo "Types: unit, integration, e2e"
@echo ""
@echo "Examples:"
@echo " make test-all EDITION=ent"
@echo " make test-all TEST_COMPONENTS=\"studio frontend\" TEST_TYPES=\"unit\""
@echo " make test-all TEST_VERBOSE=true TEST_COVERAGE=true"
.PHONY: test-list
test-list: ## List all available test targets
@echo "Available test targets:"
@grep -E '^test-[a-zA-Z0-9_-]+:.*##' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*## "}; {printf " %-35s %s\n", $$1, $$2}'
# ============================================================================
# Integration Tests (Enterprise) - Legacy targets preserved
# ============================================================================
# Note: The advanced-llm-cache plugin has its own go.mod, so tests run from
# within the plugin directory
# Run all enterprise integration tests (requires Docker)
# Note: -count=1 disables test caching so env vars are respected on each run
test-integration:
@echo "Running all enterprise integration tests..."
cd enterprise/plugins/advanced-llm-cache && go test -v -count=1 -tags="integration,enterprise" ./tests/integration/...
# Run integration tests for advanced-llm-cache plugin
test-integration-plugin-cache:
@echo "Running advanced-llm-cache integration tests..."
cd enterprise/plugins/advanced-llm-cache && go test -v -count=1 -tags="integration,enterprise" ./tests/integration/...
# Run full integration tests with all optional features enabled
test-integration-plugin-cache-full:
@echo "Running full advanced-llm-cache integration tests (all features)..."
cd enterprise/plugins/advanced-llm-cache && INTEGRATION_REDIS_CLUSTER=1 INTEGRATION_SYSLOG=1 \
go test -v -count=1 -tags="integration,enterprise" ./tests/integration/...
# Run integration tests with coverage
test-integration-plugin-cache-coverage:
@echo "Running advanced-llm-cache integration tests with coverage..."
cd enterprise/plugins/advanced-llm-cache && go test -v -count=1 -tags="integration,enterprise" -coverprofile=integration-coverage.out \
./tests/integration/...
cd enterprise/plugins/advanced-llm-cache && go tool cover -func=integration-coverage.out | tail -1
# Run integration tests with Redis cluster (slower startup)
test-integration-plugin-cache-cluster:
@echo "Running Redis cluster integration tests..."
cd enterprise/plugins/advanced-llm-cache && INTEGRATION_REDIS_CLUSTER=1 \
go test -v -count=1 -tags="integration,enterprise" -run ".*Cluster.*" \
./tests/integration/...
# Run integration tests with Syslog
test-integration-plugin-cache-syslog:
@echo "Running Syslog audit integration tests..."
cd enterprise/plugins/advanced-llm-cache && INTEGRATION_SYSLOG=1 \
go test -v -count=1 -tags="integration,enterprise" -run ".*Syslog.*" \
./tests/integration/...
# Run Vault integration tests for github-rag-ingest plugin
test-integration-plugin-github-rag:
@echo "Running github-rag-ingest Vault integration tests..."
cd community/plugins/github-rag-ingest/server && \
go test -v -count=1 -tags=integration ./secrets/...
# Performance testing targets
perf-test:
@echo "Running performance test suite..."
go test -bench=BenchmarkProxy* ./proxy/ -benchmem
go test -bench=BenchmarkGateway* ./pkg/aigateway/ -benchmem
go test -bench=BenchmarkAnalytics* ./analytics/ -benchmem
go test -bench=BenchmarkService* ./services/ -benchmem
go test -bench=BenchmarkLoad* ./tests/performance/ -benchtime=30s
perf-profile:
@echo "Running performance tests with profiling..."
go test -bench=BenchmarkProxyRequest ./proxy/ -cpuprofile=cpu.prof -memprofile=mem.prof -benchmem
@echo "Profile files generated: cpu.prof, mem.prof"
@echo "Analyze with: go tool pprof cpu.prof or go tool pprof mem.prof"
perf-baseline:
@echo "Establishing performance baseline..."
@mkdir -p performance/baselines
go test -bench=. ./... -benchmem -count=5 > performance/baselines/baseline-$(shell date +%Y%m%d-%H%M%S).txt
@echo "Baseline saved to performance/baselines/"
perf-compare:
@echo "Comparing current performance to baseline..."
@if [ ! -d performance/baselines ]; then \
echo "No baselines found. Run 'make perf-baseline' first."; \
exit 1; \
fi
@LATEST_BASELINE=$$(ls -t performance/baselines/baseline-*.txt | head -n 1); \
go test -bench=. ./... -benchmem -count=5 > performance/current-run.txt; \
echo "Comparing against: $$LATEST_BASELINE"; \
echo "Current results saved to: performance/current-run.txt"; \
echo "Use benchstat to compare: benchstat $$LATEST_BASELINE performance/current-run.txt"
perf-report:
@echo "Generating performance report..."
@mkdir -p performance/reports
@REPORT_FILE=performance/reports/report-$(shell date +%Y%m%d-%H%M%S).html; \
echo "<!DOCTYPE html><html><head><title>Performance Report</title></head><body>" > $$REPORT_FILE; \
echo "<h1>Midsommar Performance Report - $(shell date)</h1>" >> $$REPORT_FILE; \
echo "<h2>System Info</h2><pre>" >> $$REPORT_FILE; \
go version >> $$REPORT_FILE; \
echo "CPU: $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 'unknown')" >> $$REPORT_FILE; \
echo "Memory: $(shell free -h 2>/dev/null | grep '^Mem:' | awk '{print $$2}' || echo 'unknown')" >> $$REPORT_FILE; \
echo "</pre><h2>Benchmark Results</h2><pre>" >> $$REPORT_FILE; \
go test -bench=. ./... -benchmem >> $$REPORT_FILE 2>&1; \
echo "</pre></body></html>" >> $$REPORT_FILE; \
echo "Report generated: $$REPORT_FILE"
perf-clean:
@echo "Cleaning performance test artifacts..."
rm -f *.prof
rm -f performance/current-run.txt
rm -rf performance/reports/*
@echo "Performance artifacts cleaned"
# Clean target
clean:
rm -f midsommar*
rm -rf bin/
rm -rf $(ADMIN_FRONTEND_DIR)/build
cd microgateway && rm -rf bin/ dist/