forked from k8sgateway/k8sgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
1306 lines (1074 loc) · 60.3 KB
/
Makefile
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
# imports should be after the set up flags so are lower
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables
.DEFAULT_GOAL := help
#----------------------------------------------------------------------------------
# Help
#----------------------------------------------------------------------------------
# Our Makefile is quite large, and hard to reason through
# `make help` can be used to self-document targets
# To update a target to be self-documenting (and appear with the `help` command),
# place a comment after the target that is prefixed by `##`. For example:
# custom-target: ## comment that will appear in the documentation when running `make help`
#
# **NOTE TO DEVELOPERS**
# As you encounter make targets that are frequently used, please make them self-documenting
.PHONY: help
help: NAME_COLUMN_WIDTH=35
help: LINE_COLUMN_WIDTH=5
help: ## Output the self-documenting make targets
@grep -hnE '^[%a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = "[:]|(## )"}; {printf "\033[36mL%-$(LINE_COLUMN_WIDTH)s%-$(NAME_COLUMN_WIDTH)s\033[0m %s\n", $$1, $$2, $$4}'
#----------------------------------------------------------------------------------
# Base
#----------------------------------------------------------------------------------
ROOTDIR := $(shell pwd)
OUTPUT_DIR ?= $(ROOTDIR)/_output
DEPSGOBIN := $(OUTPUT_DIR)/.bin
# Important to use binaries built from module.
export PATH:=$(DEPSGOBIN):$(PATH)
export GOBIN:=$(DEPSGOBIN)
# If you just put your username, then that refers to your account at hub.docker.com
# To use quay images, set the IMAGE_REGISTRY to "quay.io/solo-io" (or leave unset)
# To use dockerhub images, set the IMAGE_REGISTRY to "soloio"
# To use gcr images, set the IMAGE_REGISTRY to "gcr.io/$PROJECT_NAME"
IMAGE_REGISTRY ?= quay.io/solo-io
# Kind of a hack to make sure _output exists
z := $(shell mkdir -p $(OUTPUT_DIR))
# a semver resembling 1.0.1-dev. Most calling jobs customize this. Ex: v1.15.0-pr8278
VERSION ?= 1.0.1-dev
SOURCES := $(shell find . -name "*.go" | grep -v test.go)
# ATTENTION: when updating to a new major version of Envoy, check if
# universal header validation has been enabled and if so, we expect
# failures in `test/e2e/header_validation_test.go`
# for more information, see https://github.com/solo-io/gloo/pull/9633
# and
# https://soloio.slab.com/posts/extended-http-methods-design-doc-40j7pjeu
ENVOY_GLOO_IMAGE ?= quay.io/solo-io/envoy-gloo:1.31.2-patch1
LDFLAGS := "-X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)"
GCFLAGS ?=
UNAME_M := $(shell uname -m)
# if `GO_ARCH` is set, then it will keep its value. Else, it will be changed based off the machine's host architecture.
# if the machines architecture is set to arm64 then we want to set the appropriate values, else we only support amd64
IS_ARM_MACHINE := $(or $(filter $(UNAME_M), arm64), $(filter $(UNAME_M), aarch64))
ifneq ($(IS_ARM_MACHINE), )
ifneq ($(GOARCH), amd64)
GOARCH := arm64
endif
PLATFORM := --platform=linux/$(GOARCH)
else
# currently we only support arm64 and amd64 as a GOARCH option.
ifneq ($(GOARCH), arm64)
GOARCH := amd64
endif
endif
GOOS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
GO_BUILD_FLAGS := GO111MODULE=on CGO_ENABLED=0 GOARCH=$(GOARCH)
GOLANG_ALPINE_IMAGE_NAME = golang:$(shell go version | egrep -o '([0-9]+\.[0-9]+)')-alpine3.18
TEST_ASSET_DIR ?= $(ROOTDIR)/_test
# This is the location where assets are placed after a test failure
# This is used by our e2e tests to emit information about the running instance of Gloo Gateway
BUG_REPORT_DIR := $(TEST_ASSET_DIR)/bug_report
$(BUG_REPORT_DIR):
mkdir -p $(BUG_REPORT_DIR)
# This is the location where logs are stored for future processing.
# This is used to generate summaries of test outcomes and may be used in the future to automate
# processing of data based on test outcomes.
TEST_LOG_DIR := $(TEST_ASSET_DIR)/test_log
$(TEST_LOG_DIR):
mkdir -p $(TEST_LOG_DIR)
# Used to install ca-certificates in GLOO_DISTROLESS_BASE_IMAGE
PACKAGE_DONOR_IMAGE ?= debian:11
# Harvested for utility binaries (sh, wget, sleep, nc, echo, ls, cat, vi)
# in GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE
# We use the uclibc variant as it is statically compiled so the binaries can be copied over and run on another image without issues (unlike glibc)
UTILS_DONOR_IMAGE ?= busybox:uclibc
# Use a distroless debian variant that is in sync with the ubuntu version used for envoy
# https://github.com/solo-io/envoy-gloo-ee/blob/main/ci/Dockerfile#L7 - check /etc/debian_version in the ubuntu version used
# This is the true base image for GLOO_DISTROLESS_BASE_IMAGE and GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE
# Since we only publish amd64 images, we use the amd64 variant. If we decide to change this, we need to update the distroless dockerfiles as well
DISTROLESS_BASE_IMAGE ?= gcr.io/distroless/base-debian11:latest-amd64
# DISTROLESS_BASE_IMAGE + ca-certificates
GLOO_DISTROLESS_BASE_IMAGE ?= $(IMAGE_REGISTRY)/distroless-base:$(VERSION)
# GLOO_DISTROLESS_BASE_IMAGE + utility binaries (sh, wget, sleep, nc, echo, ls, cat, vi)
GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE ?= $(IMAGE_REGISTRY)/distroless-base-with-utils:$(VERSION)
# BASE_IMAGE used in non distroless variants
ALPINE_BASE_IMAGE ?= alpine:3.17.6
#----------------------------------------------------------------------------------
# Macros
#----------------------------------------------------------------------------------
# This macro takes a relative path as its only argument and returns all the files
# in the tree rooted at that directory that match the given criteria.
get_sources = $(shell find $(1) -name "*.go" | grep -v test | grep -v generated.go | grep -v mock_)
#----------------------------------------------------------------------------------
# Imports
#----------------------------------------------------------------------------------
# glooctl and other ci related targets are in this file.
# they rely on some of the args set above
include Makefile.ci
#----------------------------------------------------------------------------------
# Repo setup
#----------------------------------------------------------------------------------
# https://www.viget.com/articles/two-ways-to-share-git-hooks-with-your-team/
.PHONY: init
init:
git config core.hooksPath .githooks
# Runs [`goimports`](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) which updates imports and formats code
# TODO: deprecate in favor of using fmt-v2
.PHONY: fmt
fmt:
$(DEPSGOBIN)/goimports -w $(shell ls -d */ | grep -v vendor)
# Formats code and imports
.PHONY: fmt-v2
fmt-v2:
$(DEPSGOBIN)/goimports -local "github.com/solo-io/gloo/" -w $(shell ls -d */ | grep -v vendor)
.PHONY: fmt-changed
fmt-changed:
git diff --name-only | grep '.*.go$$' | xargs -- goimports -w
# must be a separate target so that make waits for it to complete before moving on
.PHONY: mod-download
mod-download: check-go-version
go mod download all
LINTER_VERSION := $(shell cat .github/workflows/static-analysis.yaml | yq '.jobs.static-analysis.steps.[] | select( .uses == "*golangci/golangci-lint-action*") | .with.version ')
# https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md
.PHONY: install-go-tools
install-go-tools: mod-download ## Download and install Go dependencies
mkdir -p $(DEPSGOBIN)
chmod +x $(shell go list -f '{{ .Dir }}' -m k8s.io/code-generator)/generate-groups.sh
go install github.com/solo-io/protoc-gen-ext
go install github.com/solo-io/protoc-gen-openapi
go install github.com/envoyproxy/protoc-gen-validate
go install github.com/golang/protobuf/protoc-gen-go
go install golang.org/x/tools/cmd/goimports
go install github.com/cratonica/2goarray
go install github.com/golang/mock/mockgen
go install github.com/saiskee/gettercheck
go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)
# This version must stay in sync with the version used in CI: .github/workflows/static-analysis.yaml
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(LINTER_VERSION)
go install github.com/quasilyte/go-ruleguard/cmd/ruleguard@v0.3.16
# Kubebuilder docs generation
go install fybrik.io/crdoc@v0.6.3
.PHONY: install-go-test-coverage
install-go-test-coverage:
go install github.com/vladopajic/go-test-coverage/v2@v2.8.1
.PHONY: check-format
check-format:
NOT_FORMATTED=$$(gofmt -l ./projects/ ./pkg/ ./test/) && if [ -n "$$NOT_FORMATTED" ]; then echo These files are not formatted: $$NOT_FORMATTED; exit 1; fi
.PHONY: check-spelling
check-spelling:
./ci/spell.sh check
#----------------------------------------------------------------------------
# Analyze
#----------------------------------------------------------------------------
# The analyze target runs a suite of static analysis tools against the codebase.
# The options are defined in .golangci.yaml, and can be overridden by setting the ANALYZE_OPTIONS variable.
.PHONY: analyze
ANALYZE_OPTIONS ?= --fast --verbose
analyze:
$(DEPSGOBIN)/golangci-lint run $(ANALYZE_OPTIONS) ./...
#----------------------------------------------------------------------------------
# Ginkgo Tests
#----------------------------------------------------------------------------------
GINKGO_VERSION ?= $(shell echo $(shell go list -m github.com/onsi/ginkgo/v2) | cut -d' ' -f2)
GINKGO_ENV ?= GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore ACK_GINKGO_RC=true ACK_GINKGO_DEPRECATIONS=$(GINKGO_VERSION)
GINKGO_FLAGS ?= -tags=purego --trace -progress -race --fail-fast -fail-on-pending --randomize-all --compilers=5 --flake-attempts=3
GINKGO_REPORT_FLAGS ?= --json-report=test-report.json --junit-report=junit.xml -output-dir=$(OUTPUT_DIR)
GINKGO_COVERAGE_FLAGS ?= --cover --covermode=atomic --coverprofile=coverage.cov
TEST_PKG ?= ./... # Default to run all tests
# This is a way for a user executing `make test` to be able to provide flags which we do not include by default
# For example, you may want to run tests multiple times, or with various timeouts
GINKGO_USER_FLAGS ?=
.PHONY: install-test-tools
install-test-tools: check-go-version
go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)
# proto compiler installation
PROTOC_VERSION:=3.6.1
PROTOC_URL:=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}
.PHONY: install-protoc
.SILENT: install-protoc
install-protoc:
mkdir -p $(DEPSGOBIN)
if [ $(shell ${DEPSGOBIN}/protoc --version | grep -c ${PROTOC_VERSION}) -ne 0 ]; then \
echo expected protoc version ${PROTOC_VERSION} already installed ;\
else \
if [ "$(shell uname)" = "Darwin" ]; then \
echo "downloading protoc for osx" ;\
wget $(PROTOC_URL)-osx-x86_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
elif [ "$(shell uname -m)" = "aarch64" ]; then \
echo "downloading protoc for linux aarch64" ;\
wget $(PROTOC_URL)-linux-aarch_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
else \
echo "downloading protoc for linux x86-64" ;\
wget $(PROTOC_URL)-linux-x86_64.zip -O $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
fi ;\
unzip $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip -d $(DEPSGOBIN)/protoc-${PROTOC_VERSION} ;\
mv $(DEPSGOBIN)/protoc-${PROTOC_VERSION}/bin/protoc $(DEPSGOBIN)/protoc ;\
chmod +x $(DEPSGOBIN)/protoc ;\
rm -rf $(DEPSGOBIN)/protoc-${PROTOC_VERSION} $(DEPSGOBIN)/protoc-${PROTOC_VERSION}.zip ;\
fi
.PHONY: test
test: ## Run all tests, or only run the test package at {TEST_PKG} if it is specified
$(GINKGO_ENV) $(DEPSGOBIN)/ginkgo -ldflags=$(LDFLAGS) \
$(GINKGO_FLAGS) $(GINKGO_REPORT_FLAGS) $(GINKGO_USER_FLAGS) \
$(TEST_PKG)
# https://go.dev/blog/cover#heat-maps
.PHONY: test-with-coverage
test-with-coverage: GINKGO_FLAGS += $(GINKGO_COVERAGE_FLAGS)
test-with-coverage: test
go tool cover -html $(OUTPUT_DIR)/coverage.cov
.PHONY: run-tests
run-tests: GINKGO_FLAGS += -skip-package=e2e,gateway2,test/kubernetes/testutils/helper ## Run all non E2E tests, or only run the test package at {TEST_PKG} if it is specified
run-tests: GINKGO_FLAGS += --label-filter="!end-to-end && !performance"
run-tests: test
.PHONY: run-performance-tests
# Performance tests are filtered using a Ginkgo label
# This means that any tests which do not rely on Ginkgo, will by default be compiled and run
# Since this is not the desired behavior, we explicitly skip these packages
run-performance-tests: GINKGO_FLAGS += -skip-package=gateway2,kubernetes/e2e,test/kube2e
run-performance-tests: GINKGO_FLAGS += --label-filter="performance" ## Run only tests with the Performance label
run-performance-tests: test
.PHONY: run-e2e-tests
run-e2e-tests: TEST_PKG = ./test/e2e/ ## Run all in-memory E2E tests
run-e2e-tests: GINKGO_FLAGS += --label-filter="end-to-end && !performance"
run-e2e-tests: test
.PHONY: run-hashicorp-e2e-tests
run-hashicorp-e2e-tests: TEST_PKG = ./test/consulvaulte2e/
run-hashicorp-e2e-tests: GINKGO_FLAGS += --label-filter="end-to-end && !performance"
run-hashicorp-e2e-tests: test
.PHONY: run-kube-e2e-tests
run-kube-e2e-tests: TEST_PKG = ./test/kube2e/$(KUBE2E_TESTS) ## Run the Kubernetes E2E Tests in the {KUBE2E_TESTS} package
run-kube-e2e-tests: test
#----------------------------------------------------------------------------------
# Go Tests
#----------------------------------------------------------------------------------
GO_TEST_ENV ?= GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore
# Testings flags: https://pkg.go.dev/cmd/go#hdr-Testing_flags
# The default timeout for a suite is 10 minutes, but this can be overridden by setting the -timeout flag. Currently set
# to 25 minutes based on the time it takes to run the longest test setup (k8s_gw_test).
GO_TEST_ARGS ?= -timeout=25m -cpu=4 -race -outputdir=$(OUTPUT_DIR)
GO_TEST_COVERAGE_ARGS ?= --cover --covermode=atomic --coverprofile=cover.out
# This is a way for a user executing `make go-test` to be able to provide args which we do not include by default
# For example, you may want to run tests multiple times, or with various timeouts
GO_TEST_USER_ARGS ?=
.PHONY: go-test
go-test: ## Run all tests, or only run the test package at {TEST_PKG} if it is specified
go-test: clean-bug-report clean-test-logs $(BUG_REPORT_DIR) $(TEST_LOG_DIR) # Ensure the bug_report dir is reset before each invocation
@$(GO_TEST_ENV) go test -ldflags=$(LDFLAGS) \
$(GO_TEST_ARGS) $(GO_TEST_USER_ARGS) \
$(TEST_PKG) > $(TEST_LOG_DIR)/go-test 2>&1; \
RESULT=$$?; \
cat $(TEST_LOG_DIR)/go-test; \
if [ $$RESULT -ne 0 ]; then exit $$RESULT; fi # ensure non-zero exit code if tests fail
# https://go.dev/blog/cover#heat-maps
.PHONY: go-test-with-coverage
go-test-with-coverage: GO_TEST_ARGS += $(GO_TEST_COVERAGE_ARGS)
go-test-with-coverage: go-test
.PHONY: validate-test-coverage
validate-test-coverage:
${GOBIN}/go-test-coverage --config=./test_coverage.yml
.PHONY: view-test-coverage
view-test-coverage:
go tool cover -html $(OUTPUT_DIR)/cover.out
#----------------------------------------------------------------------------------
# Clean
#----------------------------------------------------------------------------------
# Important to clean before pushing new releases. Dockerfiles and binaries may not update properly
.PHONY: clean
clean:
rm -rf _output
rm -rf _test
rm -rf docs/site*
rm -rf docs/themes
rm -rf docs/resources
git clean -f -X install
.PHONY: clean-tests
clean-tests:
find * -type f -name '*.test' -exec rm {} \;
find * -type f -name '*.cov' -exec rm {} \;
find * -type f -name 'junit*.xml' -exec rm {} \;
.PHONY: clean-bug-report
clean-bug-report:
rm -rf $(BUG_REPORT_DIR)
.PHONY: clean-test-logs
clean-test-logs:
rm -rf $(TEST_LOG_DIR)
.PHONY: clean-vendor-any
clean-vendor-any:
rm -rf vendor_any
# Removes files generated by codegen other than docs and tests
.PHONY: clean-solo-kit-gen
clean-solo-kit-gen:
find * -type f -name '*.sk.md' -not -path "docs/*" -not -path "test/*" -exec rm {} \;
find * -type f -name '*.sk.go' -not -path "docs/*" -not -path "test/*" -exec rm {} \;
find * -type f -name '*.pb.go' -not -path "docs/*" -not -path "test/*" -exec rm {} \;
find * -type f -name '*.pb.hash.go' -not -path "docs/*" -not -path "test/*" -exec rm {} \;
find * -type f -name '*.pb.equal.go' -not -path "docs/*" -not -path "test/*" -exec rm {} \;
find * -type f -name '*.pb.clone.go' -not -path "docs/*" -not -path "test/*" -exec rm {} \;
.PHONY: clean-cli-docs
clean-cli-docs:
rm docs/content/reference/cli/glooctl* || true # ignore error if file doesn't exist
#----------------------------------------------------------------------------------
# Generated Code and Docs
#----------------------------------------------------------------------------------
.PHONY: generate-all
generate-all: generated-code
# Run codegen with debug logs
# DEBUG=1 controls the debug level in the logger used by solo-kit
# ref: https://github.com/solo-io/solo-kit/blob/main/pkg/code-generator/codegen/generator.go#L14
# ref: https://github.com/solo-io/go-utils/blob/main/log/log.go#L14
.PHONY: generate-all-debug
generate-all-debug: export DEBUG = 1
generate-all-debug: generate-all
# Generates all required code, cleaning and formatting as well; this target is executed in CI
.PHONY: generated-code
generated-code: check-go-version clean-solo-kit-gen ## Run all codegen and formatting as required by CI
generated-code: go-generate-all generate-cli-docs getter-check mod-tidy
generated-code: verify-enterprise-protos generate-helm-files update-licenses
generated-code: generate-crd-reference-docs
generated-code: fmt
.PHONY: go-generate-all
go-generate-all: clean-vendor-any ## Run all go generate directives in the repo, including codegen for protos, mockgen, and more
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore GO111MODULE=on go generate ./...
.PHONY: go-generate-apis
go-generate-apis: clean-vendor-any ## Runs the generate directive in generate.go, which executes codegen for protos
GO111MODULE=on go generate generate.go
.PHONY: go-generate-mocks
go-generate-mocks: clean-vendor-any ## Runs all generate directives for mockgen in the repo
GO111MODULE=on go generate -run="mockgen" ./...
.PHONY: generate-cli-docs
generate-cli-docs: clean-cli-docs ## Removes existing CLI docs and re-generates them
GO111MODULE=on go run projects/gloo/cli/cmd/docs/main.go
# Ensures that accesses for fields which have "getter" functions are exclusively done via said "getter" functions
.PHONY: getter-check
getter-check:
$(DEPSGOBIN)/gettercheck -ignoretests -ignoregenerated -write ./...
.PHONY: mod-tidy
mod-tidy:
go mod tidy
# Validates that protos used exclusively in EE are valid
.PHONY: verify-enterprise-protos
verify-enterprise-protos:
@echo Verifying validity of generated enterprise files...
$(GO_BUILD_FLAGS) GOOS=linux go build projects/gloo/pkg/api/v1/enterprise/verify.go
# Validates that local Go version matches go.mod
.PHONY: check-go-version
check-go-version:
./ci/check-go-version.sh
.PHONY: generated-code-apis
generated-code-apis: clean-solo-kit-gen go-generate-apis fmt ## Executes the targets necessary to generate formatted code from all protos
.PHONY: generated-code-cleanup
generated-code-cleanup: getter-check mod-tidy update-licenses fmt ## Executes the targets necessary to cleanup and format code
.PHONY: generate-changelog
generate-changelog: ## Generate a changelog entry
@./devel/tools/changelog.sh
#----------------------------------------------------------------------------------
# Generate CRD Reference Documentation
#
# We are trying to migrate our APIs and CRDs to be built using Kubebuilder.
#
# Historically, our docs are generated using Protocol Buffers as the source of truth,
# and code generation (https://github.com/solo-io/solo-kit/tree/main/pkg/code-generator/docgen)
# to generate the Markdown for these APIs.
#
# With the migration to Kubebuilder, protos are no longer the source of truth, and we must rely on other means to
# generate documentation. As https://github.com/kubernetes-sigs/controller-tools/issues/240 calls out, there isn't an agreed
# upon approach yet. We chose to use https://github.com/fybrik/crdoc as it allows us to generate the Markdown for our docs,
# which is used by Hugo. Other tools produced HTML, which wouldn't have worked for our current setup.
#
#----------------------------------------------------------------------------------
GWPARAMS_INPUT_CRD := install/helm/gloo/crds/gateway.gloo.solo.io_gatewayparameters.yaml
GWPARAMS_OUTPUT_MARKDOWN := docs/content/reference/api/github.com/solo-io/gloo/projects/gateway2/api/v1alpha1/gateway_parameters.md
DRA_INPUT_CRD := install/helm/gloo/crds/gateway.gloo.solo.io_directresponses.yaml
DRA_OUTPUT_MARKDOWN := docs/content/reference/api/github.com/solo-io/gloo/projects/gateway2/api/v1alpha1/direct_response_action.md
.PHONY: generate-crd-reference-docs
generate-crd-reference-docs:
$(DEPSGOBIN)/crdoc --resources $(GWPARAMS_INPUT_CRD) --output $(GWPARAMS_OUTPUT_MARKDOWN)
$(DEPSGOBIN)/crdoc --resources $(DRA_INPUT_CRD) --output $(DRA_OUTPUT_MARKDOWN)
#----------------------------------------------------------------------------------
# Generate mocks
#----------------------------------------------------------------------------------
# The values in this array are used in a foreach loop to dynamically generate the
# commands in the generate-client-mocks target.
# For each value, the ":" character will be replaced with " " using the subst function,
# thus turning the string into a 3-element array. The n-th element of the array will
# then be selected via the word function
MOCK_RESOURCE_INFO := \
gloo:artifact:ArtifactClient \
gloo:endpoint:EndpointClient \
gloo:proxy:ProxyClient \
gloo:secret:SecretClient \
gloo:settings:SettingsClient \
gloo:upstream:UpstreamClient \
gateway:gateway:GatewayClient \
gateway:virtual_service:VirtualServiceClient\
gateway:route_table:RouteTableClient\
.PHONY: generate-client-mocks
generate-client-mocks:
@$(foreach INFO, $(MOCK_RESOURCE_INFO), \
echo Generating mock for $(word 3,$(subst :, , $(INFO)))...; \
GOBIN=$(DEPSGOBIN) $(DEPSGOBIN)/mockgen -destination=projects/$(word 1,$(subst :, , $(INFO)))/pkg/mocks/mock_$(word 2,$(subst :, , $(INFO)))_client.go \
-package=mocks \
github.com/solo-io/gloo/projects/$(word 1,$(subst :, , $(INFO)))/pkg/api/v1 \
$(word 3,$(subst :, , $(INFO))) \
;)
#----------------------------------------------------------------------------------
# Gloo distroless base images
#----------------------------------------------------------------------------------
DISTROLESS_DIR=projects/distroless
DISTROLESS_OUTPUT_DIR=$(OUTPUT_DIR)/$(DISTROLESS_DIR)
$(DISTROLESS_OUTPUT_DIR)/Dockerfile: $(DISTROLESS_DIR)/Dockerfile
mkdir -p $(DISTROLESS_OUTPUT_DIR)
cp $< $@
.PHONY: distroless-docker
distroless-docker: $(DISTROLESS_OUTPUT_DIR)/Dockerfile
docker buildx build --load $(PLATFORM) $(DISTROLESS_OUTPUT_DIR) -f $(DISTROLESS_OUTPUT_DIR)/Dockerfile \
--build-arg PACKAGE_DONOR_IMAGE=$(PACKAGE_DONOR_IMAGE) \
--build-arg BASE_IMAGE=$(DISTROLESS_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(GLOO_DISTROLESS_BASE_IMAGE) $(QUAY_EXPIRATION_LABEL)
$(DISTROLESS_OUTPUT_DIR)/Dockerfile.utils: $(DISTROLESS_DIR)/Dockerfile.utils
mkdir -p $(DISTROLESS_OUTPUT_DIR)
cp $< $@
.PHONY: distroless-with-utils-docker
distroless-with-utils-docker: distroless-docker $(DISTROLESS_OUTPUT_DIR)/Dockerfile.utils
docker buildx build --load $(PLATFORM) $(DISTROLESS_OUTPUT_DIR) -f $(DISTROLESS_OUTPUT_DIR)/Dockerfile.utils \
--build-arg UTILS_DONOR_IMAGE=$(UTILS_DONOR_IMAGE) \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE) $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Ingress
#----------------------------------------------------------------------------------
INGRESS_DIR=projects/ingress
INGRESS_SOURCES=$(call get_sources,$(INGRESS_DIR))
INGRESS_OUTPUT_DIR=$(OUTPUT_DIR)/$(INGRESS_DIR)
$(INGRESS_OUTPUT_DIR)/ingress-linux-$(GOARCH): $(INGRESS_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(INGRESS_DIR)/cmd/main.go
.PHONY: ingress
ingress: $(INGRESS_OUTPUT_DIR)/ingress-linux-$(GOARCH)
$(INGRESS_OUTPUT_DIR)/Dockerfile.ingress: $(INGRESS_DIR)/cmd/Dockerfile
cp $< $@
.PHONY: ingress-docker
ingress-docker: $(INGRESS_OUTPUT_DIR)/ingress-linux-$(GOARCH) $(INGRESS_OUTPUT_DIR)/Dockerfile.ingress
docker buildx build --load $(PLATFORM) $(INGRESS_OUTPUT_DIR) -f $(INGRESS_OUTPUT_DIR)/Dockerfile.ingress \
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/ingress:$(VERSION) $(QUAY_EXPIRATION_LABEL)
$(INGRESS_OUTPUT_DIR)/Dockerfile.ingress.distroless: $(INGRESS_DIR)/cmd/Dockerfile.distroless
cp $< $@
.PHONY: ingress-distroless-docker
ingress-distroless-docker: $(INGRESS_OUTPUT_DIR)/ingress-linux-$(GOARCH) $(INGRESS_OUTPUT_DIR)/Dockerfile.ingress.distroless distroless-docker
docker buildx build --load $(PLATFORM) $(INGRESS_OUTPUT_DIR) -f $(INGRESS_OUTPUT_DIR)/Dockerfile.ingress.distroless \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/ingress:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Access Logger
#----------------------------------------------------------------------------------
ACCESS_LOG_DIR=projects/accesslogger
ACCESS_LOG_SOURCES=$(call get_sources,$(ACCESS_LOG_DIR))
ACCESS_LOG_OUTPUT_DIR=$(OUTPUT_DIR)/$(ACCESS_LOG_DIR)
$(ACCESS_LOG_OUTPUT_DIR)/access-logger-linux-$(GOARCH): $(ACCESS_LOG_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(ACCESS_LOG_DIR)/cmd/main.go
.PHONY: access-logger
access-logger: $(ACCESS_LOG_OUTPUT_DIR)/access-logger-linux-$(GOARCH)
$(ACCESS_LOG_OUTPUT_DIR)/Dockerfile.access-logger: $(ACCESS_LOG_DIR)/cmd/Dockerfile
cp $< $@
.PHONY: access-logger-docker
access-logger-docker: $(ACCESS_LOG_OUTPUT_DIR)/access-logger-linux-$(GOARCH) $(ACCESS_LOG_OUTPUT_DIR)/Dockerfile.access-logger
docker buildx build --load $(PLATFORM) $(ACCESS_LOG_OUTPUT_DIR) -f $(ACCESS_LOG_OUTPUT_DIR)/Dockerfile.access-logger \
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/access-logger:$(VERSION) $(QUAY_EXPIRATION_LABEL)
$(ACCESS_LOG_OUTPUT_DIR)/Dockerfile.access-logger.distroless: $(ACCESS_LOG_DIR)/cmd/Dockerfile.distroless
cp $< $@
.PHONY: access-logger-distroless-docker
access-logger-distroless-docker: $(ACCESS_LOG_OUTPUT_DIR)/access-logger-linux-$(GOARCH) $(ACCESS_LOG_OUTPUT_DIR)/Dockerfile.access-logger.distroless distroless-docker
docker buildx build --load $(PLATFORM) $(ACCESS_LOG_OUTPUT_DIR) -f $(ACCESS_LOG_OUTPUT_DIR)/Dockerfile.access-logger.distroless \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/access-logger:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Discovery
#----------------------------------------------------------------------------------
DISCOVERY_DIR=projects/discovery
DISCOVERY_SOURCES=$(call get_sources,$(DISCOVERY_DIR))
DISCOVERY_OUTPUT_DIR=$(OUTPUT_DIR)/$(DISCOVERY_DIR)
$(DISCOVERY_OUTPUT_DIR)/discovery-linux-$(GOARCH): $(DISCOVERY_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(DISCOVERY_DIR)/cmd/main.go
.PHONY: discovery
discovery: $(DISCOVERY_OUTPUT_DIR)/discovery-linux-$(GOARCH)
$(DISCOVERY_OUTPUT_DIR)/Dockerfile.discovery: $(DISCOVERY_DIR)/cmd/Dockerfile
cp $< $@
.PHONY: discovery-docker
discovery-docker: $(DISCOVERY_OUTPUT_DIR)/discovery-linux-$(GOARCH) $(DISCOVERY_OUTPUT_DIR)/Dockerfile.discovery
docker buildx build --load $(PLATFORM) $(DISCOVERY_OUTPUT_DIR) -f $(DISCOVERY_OUTPUT_DIR)/Dockerfile.discovery \
--build-arg GOARCH=$(GOARCH) \
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
-t $(IMAGE_REGISTRY)/discovery:$(VERSION) $(QUAY_EXPIRATION_LABEL)
$(DISCOVERY_OUTPUT_DIR)/Dockerfile.discovery.distroless: $(DISCOVERY_DIR)/cmd/Dockerfile.distroless
cp $< $@
.PHONY: discovery-distroless-docker
discovery-distroless-docker: $(DISCOVERY_OUTPUT_DIR)/discovery-linux-$(GOARCH) $(DISCOVERY_OUTPUT_DIR)/Dockerfile.discovery.distroless distroless-docker
docker buildx build --load $(PLATFORM) $(DISCOVERY_OUTPUT_DIR) -f $(DISCOVERY_OUTPUT_DIR)/Dockerfile.discovery.distroless \
--build-arg GOARCH=$(GOARCH) \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_IMAGE) \
-t $(IMAGE_REGISTRY)/discovery:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Gloo
#----------------------------------------------------------------------------------
GLOO_DIR=projects/gloo
EDGE_GATEWAY_DIR=projects/gateway
K8S_GATEWAY_DIR=projects/gateway2
GLOO_SOURCES=$(call get_sources,$(GLOO_DIR))
EDGE_GATEWAY_SOURCES=$(call get_sources,$(EDGE_GATEWAY_DIR))
K8S_GATEWAY_SOURCES=$(call get_sources,$(K8S_GATEWAY_DIR))
GLOO_OUTPUT_DIR=$(OUTPUT_DIR)/$(GLOO_DIR)
# We include the files in EDGE_GATEWAY_DIR and K8S_GATEWAY_DIR as dependencies to the gloo build
# so changes in those directories cause the make target to rebuild
$(GLOO_OUTPUT_DIR)/gloo-linux-$(GOARCH): $(GLOO_SOURCES) $(EDGE_GATEWAY_SOURCES) $(K8S_GATEWAY_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(GLOO_DIR)/cmd/main.go
.PHONY: gloo
gloo: $(GLOO_OUTPUT_DIR)/gloo-linux-$(GOARCH)
$(GLOO_OUTPUT_DIR)/Dockerfile.gloo: $(GLOO_DIR)/cmd/Dockerfile
cp $< $@
.PHONY: gloo-docker
gloo-docker: $(GLOO_OUTPUT_DIR)/gloo-linux-$(GOARCH) $(GLOO_OUTPUT_DIR)/Dockerfile.gloo
docker buildx build --load $(PLATFORM) $(GLOO_OUTPUT_DIR) -f $(GLOO_OUTPUT_DIR)/Dockerfile.gloo \
--build-arg GOARCH=$(GOARCH) \
--build-arg ENVOY_IMAGE=$(ENVOY_GLOO_IMAGE) \
-t $(IMAGE_REGISTRY)/gloo:$(VERSION) $(QUAY_EXPIRATION_LABEL)
$(GLOO_OUTPUT_DIR)/Dockerfile.gloo.distroless: $(GLOO_DIR)/cmd/Dockerfile.distroless
cp $< $@
# Explicitly specify the base image is amd64 as we only build the amd64 flavour of gloo envoy
.PHONY: gloo-distroless-docker
gloo-distroless-docker: $(GLOO_OUTPUT_DIR)/gloo-linux-$(GOARCH) $(GLOO_OUTPUT_DIR)/Dockerfile.gloo.distroless distroless-with-utils-docker
docker buildx build --load $(PLATFORM) $(GLOO_OUTPUT_DIR) -f $(GLOO_OUTPUT_DIR)/Dockerfile.gloo.distroless \
--build-arg GOARCH=$(GOARCH) \
--build-arg ENVOY_IMAGE=$(ENVOY_GLOO_IMAGE) \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE) \
-t $(IMAGE_REGISTRY)/gloo:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Gloo with race detection enabled.
# This is intended to be used to aid in local debugging by swapping out this image in a running gloo instance
#----------------------------------------------------------------------------------
GLOO_RACE_OUT_DIR=$(OUTPUT_DIR)/gloo-race
$(GLOO_RACE_OUT_DIR)/Dockerfile.build: $(GLOO_DIR)/Dockerfile
mkdir -p $(GLOO_RACE_OUT_DIR)
cp $< $@
# Hardcode GOARCH for targets that are both built and run entirely in amd64 docker containers
$(GLOO_RACE_OUT_DIR)/.gloo-race-docker-build: $(GLOO_SOURCES) $(GLOO_RACE_OUT_DIR)/Dockerfile.build
docker buildx build --load $(PLATFORM) -t $(IMAGE_REGISTRY)/gloo-race-build-container:$(VERSION) \
-f $(GLOO_RACE_OUT_DIR)/Dockerfile.build \
--build-arg GO_BUILD_IMAGE=$(GOLANG_ALPINE_IMAGE_NAME) \
--build-arg VERSION=$(VERSION) \
--build-arg GCFLAGS=$(GCFLAGS) \
--build-arg LDFLAGS=$(LDFLAGS) \
--build-arg USE_APK=true \
--build-arg GOARCH=amd64 \
$(PLATFORM) \
.
touch $@
# Hardcode GOARCH for targets that are both built and run entirely in amd64 docker containers
# Build inside container as we need to target linux and must compile with CGO_ENABLED=1
# We may be running Docker in a VM (eg, minikube) so be careful about how we copy files out of the containers
$(GLOO_RACE_OUT_DIR)/gloo-linux-$(GOARCH): $(GLOO_RACE_OUT_DIR)/.gloo-race-docker-build
docker create -ti --name gloo-race-temp-container $(IMAGE_REGISTRY)/gloo-race-build-container:$(VERSION) bash
docker cp gloo-race-temp-container:/gloo-linux-amd64 $(GLOO_RACE_OUT_DIR)/gloo-linux-amd64
docker rm -f gloo-race-temp-container
# Build the gloo project with race detection enabled
.PHONY: gloo-race
gloo-race: $(GLOO_RACE_OUT_DIR)/gloo-linux-$(GOARCH)
$(GLOO_RACE_OUT_DIR)/Dockerfile: $(GLOO_DIR)/cmd/Dockerfile
cp $< $@
# Hardcode GOARCH for targets that are both built and run entirely in amd64 docker containers
# Take the executable built in gloo-race and put it in a docker container
.PHONY: gloo-race-docker
gloo-race-docker: $(GLOO_RACE_OUT_DIR)/.gloo-race-docker
$(GLOO_RACE_OUT_DIR)/.gloo-race-docker: $(GLOO_RACE_OUT_DIR)/gloo-linux-amd64 $(GLOO_RACE_OUT_DIR)/Dockerfile
docker buildx build --load $(PLATFORM) $(GLOO_RACE_OUT_DIR) \
--build-arg ENVOY_IMAGE=$(ENVOY_GLOO_IMAGE) --build-arg GOARCH=amd64 \
-t $(IMAGE_REGISTRY)/gloo:$(VERSION)-race $(QUAY_EXPIRATION_LABEL)
touch $@
#----------------------------------------------------------------------------------
# SDS Server - gRPC server for serving Secret Discovery Service config for Gloo Edge MTLS
#----------------------------------------------------------------------------------
SDS_DIR=projects/sds
SDS_SOURCES=$(call get_sources,$(SDS_DIR))
SDS_OUTPUT_DIR=$(OUTPUT_DIR)/$(SDS_DIR)
$(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH): $(SDS_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(SDS_DIR)/cmd/main.go
.PHONY: sds
sds: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH)
$(SDS_OUTPUT_DIR)/Dockerfile.sds: $(SDS_DIR)/cmd/Dockerfile
cp $< $@
.PHONY: sds-docker
sds-docker: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH) $(SDS_OUTPUT_DIR)/Dockerfile.sds
docker buildx build --load $(PLATFORM) $(SDS_OUTPUT_DIR) -f $(SDS_OUTPUT_DIR)/Dockerfile.sds \
--build-arg GOARCH=$(GOARCH) \
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
-t $(IMAGE_REGISTRY)/sds:$(VERSION) $(QUAY_EXPIRATION_LABEL)
$(SDS_OUTPUT_DIR)/Dockerfile.sds.distroless: $(SDS_DIR)/cmd/Dockerfile.distroless
cp $< $@
.PHONY: sds-distroless-docker
sds-distroless-docker: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH) $(SDS_OUTPUT_DIR)/Dockerfile.sds.distroless distroless-with-utils-docker
docker buildx build --load $(PLATFORM) $(SDS_OUTPUT_DIR) -f $(SDS_OUTPUT_DIR)/Dockerfile.sds.distroless \
--build-arg GOARCH=$(GOARCH) \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE) \
-t $(IMAGE_REGISTRY)/sds:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Envoy init (BASE/SIDECAR)
#----------------------------------------------------------------------------------
ENVOYINIT_DIR=projects/envoyinit/cmd
ENVOYINIT_SOURCES=$(call get_sources,$(ENVOYINIT_DIR))
ENVOYINIT_OUTPUT_DIR=$(OUTPUT_DIR)/$(ENVOYINIT_DIR)
$(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH): $(ENVOYINIT_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(ENVOYINIT_DIR)/main.go
.PHONY: envoyinit
envoyinit: $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH)
$(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit: $(ENVOYINIT_DIR)/Dockerfile.envoyinit
cp $< $@
$(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh: $(ENVOYINIT_DIR)/docker-entrypoint.sh
cp $< $@
.PHONY: gloo-envoy-wrapper-docker
gloo-envoy-wrapper-docker: $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH) $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit $(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh
docker buildx build --load $(PLATFORM) $(ENVOYINIT_OUTPUT_DIR) -f $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit \
--build-arg GOARCH=$(GOARCH) \
--build-arg ENVOY_IMAGE=$(ENVOY_GLOO_IMAGE) \
-t $(IMAGE_REGISTRY)/gloo-envoy-wrapper:$(VERSION) $(QUAY_EXPIRATION_LABEL)
$(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit.distroless: $(ENVOYINIT_DIR)/Dockerfile.envoyinit.distroless
cp $< $@
# Explicitly specify the base image is amd64 as we only build the amd64 flavour of gloo envoy
.PHONY: gloo-envoy-wrapper-distroless-docker
gloo-envoy-wrapper-distroless-docker: $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH) $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit.distroless $(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh distroless-with-utils-docker
docker buildx build --load $(PLATFORM) $(ENVOYINIT_OUTPUT_DIR) -f $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit.distroless \
--build-arg GOARCH=$(GOARCH) \
--build-arg ENVOY_IMAGE=$(ENVOY_GLOO_IMAGE) \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE) \
-t $(IMAGE_REGISTRY)/gloo-envoy-wrapper:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Certgen - Job for creating TLS Secrets in Kubernetes
#----------------------------------------------------------------------------------
CERTGEN_DIR=jobs/certgen/cmd
CERTGEN_SOURCES=$(call get_sources,$(CERTGEN_DIR))
CERTGEN_OUTPUT_DIR=$(OUTPUT_DIR)/$(CERTGEN_DIR)
$(CERTGEN_OUTPUT_DIR)/certgen-linux-$(GOARCH): $(CERTGEN_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(CERTGEN_DIR)/main.go
.PHONY: certgen
certgen: $(CERTGEN_OUTPUT_DIR)/certgen-linux-$(GOARCH)
$(CERTGEN_OUTPUT_DIR)/Dockerfile.certgen: $(CERTGEN_DIR)/Dockerfile
cp $< $@
.PHONY: certgen-docker
certgen-docker: $(CERTGEN_OUTPUT_DIR)/certgen-linux-$(GOARCH) $(CERTGEN_OUTPUT_DIR)/Dockerfile.certgen
docker buildx build --load $(PLATFORM) $(CERTGEN_OUTPUT_DIR) -f $(CERTGEN_OUTPUT_DIR)/Dockerfile.certgen \
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/certgen:$(VERSION) $(QUAY_EXPIRATION_LABEL)
$(CERTGEN_OUTPUT_DIR)/Dockerfile.certgen.distroless: $(CERTGEN_DIR)/Dockerfile.distroless
cp $< $@
.PHONY: certgen-distroless-docker
certgen-distroless-docker: $(CERTGEN_OUTPUT_DIR)/certgen-linux-$(GOARCH) $(CERTGEN_OUTPUT_DIR)/Dockerfile.certgen.distroless distroless-docker
docker buildx build --load $(PLATFORM) $(CERTGEN_OUTPUT_DIR) -f $(CERTGEN_OUTPUT_DIR)/Dockerfile.certgen.distroless \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/certgen:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Kubectl - Used in jobs during helm install/upgrade/uninstall
#----------------------------------------------------------------------------------
KUBECTL_DIR=jobs/kubectl
KUBECTL_OUTPUT_DIR=$(OUTPUT_DIR)/$(KUBECTL_DIR)
$(KUBECTL_OUTPUT_DIR)/Dockerfile.kubectl: $(KUBECTL_DIR)/Dockerfile
mkdir -p $(KUBECTL_OUTPUT_DIR)
cp $< $@
.PHONY: kubectl-docker
kubectl-docker: $(KUBECTL_OUTPUT_DIR)/Dockerfile.kubectl
docker buildx build --load $(PLATFORM) $(KUBECTL_OUTPUT_DIR) -f $(KUBECTL_OUTPUT_DIR)/Dockerfile.kubectl \
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/kubectl:$(VERSION) $(QUAY_EXPIRATION_LABEL)
$(KUBECTL_OUTPUT_DIR)/Dockerfile.kubectl.distroless: $(KUBECTL_DIR)/Dockerfile.distroless
mkdir -p $(KUBECTL_OUTPUT_DIR)
cp $< $@
.PHONY: kubectl-distroless-docker
kubectl-distroless-docker: $(KUBECTL_OUTPUT_DIR)/Dockerfile.kubectl.distroless distroless-with-utils-docker
docker buildx build --load $(PLATFORM) $(KUBECTL_OUTPUT_DIR) -f $(KUBECTL_OUTPUT_DIR)/Dockerfile.kubectl.distroless \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE) \
--build-arg GOARCH=$(GOARCH) \
-t $(IMAGE_REGISTRY)/kubectl:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
#----------------------------------------------------------------------------------
# Deployment Manifests / Helm
#----------------------------------------------------------------------------------
HELM_SYNC_DIR := $(OUTPUT_DIR)/helm
HELM_DIR := install/helm/gloo
.PHONY: generate-helm-files
generate-helm-files: $(OUTPUT_DIR)/.helm-prepared ## Generates required helm files
HELM_PREPARED_INPUT := $(HELM_DIR)/generate.go $(wildcard $(HELM_DIR)/generate/*.go)
$(OUTPUT_DIR)/.helm-prepared: $(HELM_PREPARED_INPUT)
mkdir -p $(HELM_SYNC_DIR)/charts
IMAGE_REGISTRY=$(IMAGE_REGISTRY) go run $(HELM_DIR)/generate.go --version $(VERSION) --generate-helm-docs
touch $@
.PHONY: package-chart
package-chart: generate-helm-files
mkdir -p $(HELM_SYNC_DIR)/charts
helm package --destination $(HELM_SYNC_DIR)/charts $(HELM_DIR)
helm repo index $(HELM_SYNC_DIR)
#----------------------------------------------------------------------------------
# Publish Artifacts
#
# We publish artifacts using our CI pipeline. This may happen during any of the following scenarios:
# - Release
# - Development Build (a one-off build for unreleased code)
# - Pull Request (we publish unreleased artifacts to be consumed by our Enterprise project)
#----------------------------------------------------------------------------------
# TODO: delete this logic block when we have a github actions-managed release
# git_tag is evaluated when is used (recursively expanded variable)
# https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html#SEC59
git_tag = $(shell git describe --abbrev=0 --tags)
# Semantic versioning format https://semver.org/
# Regex copied from: https://github.com/solo-io/go-utils/blob/16d4d94e4e5f182ca8c10c5823df303087879dea/versionutils/version.go#L338
tag_regex := v[0-9]+[.][0-9]+[.][0-9]+(-[a-z]+)*(-[a-z]+[0-9]*)?$
ifneq (,$(TEST_ASSET_ID))
PUBLISH_CONTEXT := PULL_REQUEST
ifeq ($(shell echo $(git_tag) | egrep "$(tag_regex)"),)
# Forked repos don't have tags by default, so we create a standard tag for them
# This only impacts the version of the assets used in CI for this PR, so it is ok that it is not a real tag
VERSION = 1.0.0-$(TEST_ASSET_ID)
else
# example: 1.16.0-beta4-{TEST_ASSET_ID}
VERSION = $(shell echo $(git_tag) | cut -c 2-)-$(TEST_ASSET_ID)
endif
LDFLAGS := "-X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)"
endif
# TODO: delete this logic block when we have a github actions-managed release
ifneq (,$(TAGGED_VERSION))
PUBLISH_CONTEXT := RELEASE
VERSION := $(shell echo $(TAGGED_VERSION) | cut -c 2-)
LDFLAGS := "-X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)"
endif
# controller variable for the "Publish Artifacts" section. Defines which targets exist. Possible Values: NONE, RELEASE, PULL_REQUEST
PUBLISH_CONTEXT ?= NONE
# specify which bucket to upload helm chart to
HELM_BUCKET ?= gs://solo-public-tagged-helm
# modifier to docker builds which can auto-delete docker images after a set time
QUAY_EXPIRATION_LABEL ?= --label quay.expires-after=3w
# define empty publish targets so calls won't fail
.PHONY: publish-docker
.PHONY: publish-docker-retag
.PHONY: publish-glooctl
.PHONY: publish-helm-chart
# don't define Publish Artifacts Targets if we don't have a release context
ifneq (,$(filter $(PUBLISH_CONTEXT),RELEASE PULL_REQUEST))
ifeq (RELEASE, $(PUBLISH_CONTEXT)) # RELEASE contexts have additional make targets
HELM_BUCKET := gs://solo-public-helm
QUAY_EXPIRATION_LABEL :=
# Re-tag docker images previously pushed to the ORIGINAL_IMAGE_REGISTRY,
# and push them to a secondary repository, defined at IMAGE_REGISTRY
publish-docker-retag: docker-retag docker-push
# publish glooctl
publish-glooctl: build-cli
VERSION=$(VERSION) GO111MODULE=on go run ci/upload_github_release_assets.go false
else
# dry run publish glooctl
publish-glooctl: build-cli
VERSION=$(VERSION) GO111MODULE=on go run ci/upload_github_release_assets.go true
endif # RELEASE exclusive make targets
# Build and push docker images to the defined $(IMAGE_REGISTRY)
publish-docker: docker docker-push
# create a new helm chart and publish it to $(HELM_BUCKET)
publish-helm-chart: generate-helm-files
@echo "Uploading helm chart to $(HELM_BUCKET) with name gloo-$(VERSION).tgz"
until $$(GENERATION=$$(gsutil ls -a $(HELM_BUCKET)/index.yaml | tail -1 | cut -f2 -d '#') && \
gsutil cp -v $(HELM_BUCKET)/index.yaml $(HELM_SYNC_DIR)/index.yaml && \
helm package --destination $(HELM_SYNC_DIR)/charts $(HELM_DIR) >> /dev/null && \
helm repo index $(HELM_SYNC_DIR) --merge $(HELM_SYNC_DIR)/index.yaml && \
gsutil -m rsync $(HELM_SYNC_DIR)/charts $(HELM_BUCKET)/charts && \
gsutil -h x-goog-if-generation-match:"$$GENERATION" cp $(HELM_SYNC_DIR)/index.yaml $(HELM_BUCKET)/index.yaml); do \
echo "Failed to upload new helm index (updated helm index since last download?). Trying again"; \
sleep 2; \
done
endif # Publish Artifact Targets
#----------------------------------------------------------------------------------
# Docker
#----------------------------------------------------------------------------------
docker-retag-%-distroless:
docker tag $(ORIGINAL_IMAGE_REGISTRY)/$*:$(VERSION)-distroless $(IMAGE_REGISTRY)/$*:$(VERSION)-distroless
docker-retag-%:
docker tag $(ORIGINAL_IMAGE_REGISTRY)/$*:$(VERSION) $(IMAGE_REGISTRY)/$*:$(VERSION)
docker-push-%-distroless:
docker push $(IMAGE_REGISTRY)/$*:$(VERSION)-distroless
docker-push-%:
docker push $(IMAGE_REGISTRY)/$*:$(VERSION)
.PHONY: docker-standard
docker-standard: check-go-version ## Build docker images (standard only)
docker-standard: gloo-docker
docker-standard: discovery-docker
docker-standard: gloo-envoy-wrapper-docker
docker-standard: sds-docker
docker-standard: certgen-docker
docker-standard: ingress-docker
docker-standard: access-logger-docker
docker-standard: kubectl-docker