-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
213 lines (176 loc) · 8.8 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
# 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: FIRST_COLUMN_WIDTH=35
help: ## Output the self-documenting make targets
@grep -hE '^[%a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-$(FIRST_COLUMN_WIDTH)s\033[0m %s\n", $$1, $$2}'
#----------------------------------------------------------------------------------
# Base
#----------------------------------------------------------------------------------
ROOTDIR := $(shell pwd)
PACKAGE_PATH:=github.com/solo-io/solo-kit
OUTPUT_DIR ?= $(ROOTDIR)/_output
DEPSGOBIN:=$(OUTPUT_DIR)/.bin
SOURCES := $(shell find . -name "*.go" | grep -v test.go)
GO_BUILD_FLAGS := GO111MODULE=on CGO_ENABLED=0
# Important to use binaries built from module.
export PATH:=$(DEPSGOBIN):$(PATH)
export GOBIN:=$(DEPSGOBIN)
#----------------------------------------------------------------------------------
# Version, Release
#----------------------------------------------------------------------------------
VERSION ?= $(shell git describe --tags --dirty | cut -c 2-)
RELEASE := "false"
# If TAGGED_VERSION does exist, this is a release in CI
ifneq ($(TAGGED_VERSION),)
RELEASE := "true"
VERSION ?= $(shell echo $(TAGGED_VERSION) | cut -c 2-)
endif
#----------------------------------------------------------------------------------
# Repo init
#----------------------------------------------------------------------------------
# https://www.viget.com/articles/two-ways-to-share-git-hooks-with-your-team/
.PHONY: init
init:
git config core.hooksPath .githooks
#----------------------------------------------------------------------------------
# Protobufs
#----------------------------------------------------------------------------------
PROTOS := $(shell find api/v1 -name "*.proto")
GENERATED_PROTO_FILES := $(shell find pkg/api/v1/resources/core -name "*.pb.go")
.PHONY: update-all
update-all: mod-download update-deps update-code-generator
.PHONY: mod-download
mod-download:
go mod download all
.PHONY: install-tools
install-tools: update-deps install-protoc
.PHONY: update-deps
update-deps:
mkdir -p $(DEPSGOBIN)
go install github.com/solo-io/[email protected]
go install github.com/solo-io/[email protected]
go install golang.org/x/tools/cmd/goimports
go install github.com/golang/protobuf/[email protected]
go install github.com/envoyproxy/[email protected]
go install github.com/golang/mock/gomock
go install github.com/golang/mock/mockgen
# proto compiler installation
# no explicit arm build, but x86_64 build works on arm macs
PROTOC_VERSION:=3.6.1
PROTOC_URL:=https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}
.PHONY: 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: update-code-generator
update-code-generator:
chmod +x $(shell go list -f '{{ .Dir }}' -m k8s.io/code-generator)/generate-groups.sh
# clone solo's fork of code-generator, required for tests & kube type gen
mkdir -p $(GOPATH)/src/k8s.io && \
cd $(GOPATH)/src/k8s.io && \
(git clone https://github.com/kubernetes/code-generator || echo "already found code-generator") && \
cd $(GOPATH)/src/k8s.io/code-generator && \
(git remote add solo https://github.com/solo-io/k8s-code-generator || echo "already have remote solo") && \
git fetch solo && \
git checkout fixed-for-solo-kit-1-16-2 && \
git pull
#----------------------------------------------------------------------------------
# Kubernetes Clientsets
#----------------------------------------------------------------------------------
$(OUTPUT_DIR):
mkdir -p $@
.PHONY: clientset
clientset: $(OUTPUT_DIR) $(OUTPUT_DIR)/.clientset
$(OUTPUT_DIR)/.clientset: $(GENERATED_PROTO_FILES) $(SOURCES)
$(shell go list -f '{{ .Dir }}' -m k8s.io/code-generator)/generate-groups.sh all \
$(PACKAGE_PATH)/pkg/api/v1/clients/kube/crd/client \
$(PACKAGE_PATH)/pkg/api/v1/clients/kube/crd \
"solo.io:v1"
touch $@
#----------------------------------------------------------------------------------
# Generated Code
#----------------------------------------------------------------------------------
.PHONY: clean
clean:
rm -rf vendor_any
find . -type d -name "doc-gen-test*" -exec rm -rf {} + # remove all doc-gen-test* directories
find . -type d -name "_output" -exec rm -rf {} + # remove all _output directories
.PHONY: generate-all
generate-all: generated-code
.PHONY: generated-code
generated-code: $(OUTPUT_DIR)/.generated-code update-licenses
SUBDIRS:=pkg test
$(OUTPUT_DIR)/.generated-code:
mkdir -p $(OUTPUT_DIR)
go mod tidy
$(GO_BUILD_FLAGS) go generate ./...
gofmt -w $(SUBDIRS)
$(DEPSGOBIN)/goimports -w $(SUBDIRS)
touch $@
.PHONY: verify-envoy-protos
verify-envoy-protos:
@echo Verifying validity of generated envoy files...
$(GO_BUILD_FLAGS) CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build pkg/api/external/verify.go
#----------------------------------------------------------------------------------
# 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_DEPRECATIONS=$(GINKGO_VERSION)
GINKGO_FLAGS ?= -v -tags=purego -compilers=4 --randomize-all --trace -progress -race
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:
go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)
.PHONY: test
test: install-test-tools ## Run all tests, or only run the test package at {TEST_PKG} if it is specified
ifneq ($(RELEASE), "true")
$(GINKGO_ENV) ginkgo \
$(GINKGO_FLAGS) $(GINKGO_REPORT_FLAGS) $(GINKGO_USER_FLAGS) \
$(TEST_PKG)
endif
.PHONY: test-with-coverage
test-with-coverage: GINKGO_FLAGS += $(GINKGO_COVERAGE_FLAGS)
test-with-coverage: test
go tool cover -html $(OUTPUT_DIR)/coverage.cov
#----------------------------------------------------------------------------------
# Update third party licenses and check for GPL Licenses
#----------------------------------------------------------------------------------
update-licenses:
# check for GPL licenses, if there are any, this will fail
cd ci/oss_compliance; GO111MODULE=on go run oss_compliance.go osagen -c "GNU General Public License v2.0,GNU General Public License v3.0,GNU Lesser General Public License v2.1,GNU Lesser General Public License v3.0,GNU Affero General Public License v3.0"
cd ci/oss_compliance; GO111MODULE=on go run oss_compliance.go osagen -s "Mozilla Public License 2.0,GNU General Public License v2.0,GNU General Public License v3.0,GNU Lesser General Public License v2.1,GNU Lesser General Public License v3.0,GNU Affero General Public License v3.0"> osa_provided.md
cd ci/oss_compliance; GO111MODULE=on go run oss_compliance.go osagen -i "Mozilla Public License 2.0"> osa_included.md