forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
251 lines (205 loc) · 8.89 KB
/
Makefile
File metadata and controls
251 lines (205 loc) · 8.89 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
#----------------------------------------------------------------------------------
# Base
#----------------------------------------------------------------------------------
OUTDIR ?= _output
PROJECT ?= service-mesh-hub
DOCKER_REPO ?= soloio
SMH_IMAGE ?= $(DOCKER_REPO)/service-mesh-hub
CA_IMAGE ?= $(DOCKER_REPO)/cert-agent
SOURCES := $(shell find . -name "*.go" | grep -v test.go)
RELEASE := "true"
ifeq ($(TAGGED_VERSION),)
TAGGED_VERSION := $(shell git describe --tags --dirty --always)
RELEASE := "false"
endif
VERSION ?= $(shell echo $(TAGGED_VERSION) | cut -c 2-)
.PHONY: print-version
print-version:
ifeq ($(TAGGED_VERSION),)
exit 1
endif
echo $(VERSION)
LDFLAGS := "-X github.com/solo-io/$(PROJECT)/pkg/common/version.Version=$(VERSION)"
GCFLAGS := all="-N -l"
print-info:
@echo RELEASE: $(RELEASE)
@echo TAGGED_VERSION: $(TAGGED_VERSION)
@echo VERSION: $(VERSION)
#----------------------------------------------------------------------------------
# Code Generation
#----------------------------------------------------------------------------------
.PHONY: fmt
fmt:
goimports -w $(shell ls -d */ | grep -v vendor)
.PHONY: mod-download
mod-download:
go mod download
# Dependencies for code generation
.PHONY: install-go-tools
install-go-tools: mod-download
go install istio.io/tools/cmd/protoc-gen-jsonshim
go install github.com/gogo/protobuf/protoc-gen-gogo
go install github.com/golang/protobuf/protoc-gen-go
go install github.com/solo-io/protoc-gen-ext
go install github.com/golang/mock/mockgen
go install golang.org/x/tools/cmd/goimports
go install github.com/onsi/ginkgo/ginkgo
go install github.com/gobuffalo/packr/packr
# Call all generated code targets
.PHONY: generated-code
generated-code: operator-gen \
manifest-gen \
go-generate \
generated-reference-docs \
fmt
go mod tidy
#----------------------------------------------------------------------------------
# Go generate
#----------------------------------------------------------------------------------
# Run go-generate on all sub-packages
go-generate:
go generate -v ./...
#----------------------------------------------------------------------------------
# Operator Code Generation
#----------------------------------------------------------------------------------
# Generate Operator Code
.PHONY: operator-gen
operator-gen:
go run -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) codegen/generate.go
#----------------------------------------------------------------------------------
# Docs Code Generation
#----------------------------------------------------------------------------------
# Generate Reference documentation
.PHONY: generated-reference-docs
generated-reference-docs:
go run codegen/docs/docsgen.go
#----------------------------------------------------------------------------------
# Build
#----------------------------------------------------------------------------------
.PHONY: build-all-images
build-all-images: service-mesh-hub-image cert-agent-image
#----------------------------------------------------------------------------------
# Build service-mesh-hub controller + image
#----------------------------------------------------------------------------------
# for local development only; to build docker image, use service-mesh-hub-linux-amd-64
.PHONY: service-mesh-hub
service-mesh-hub: $(OUTDIR)/service-mesh-hub
$(OUTDIR)/service-mesh-hub: $(SOURCES)
go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/service-mesh-hub/main.go
.PHONY: service-mesh-hub-linux-amd64
service-mesh-hub-linux-amd64: $(OUTDIR)/service-mesh-hub-linux-amd64
$(OUTDIR)/service-mesh-hub-linux-amd64: $(SOURCES)
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/service-mesh-hub/main.go
# build image with service-mesh-hub binary
# this is an alternative to using operator-gen to build the image
.PHONY: service-mesh-hub-image
service-mesh-hub-image: service-mesh-hub-linux-amd64
cp $(OUTDIR)/service-mesh-hub-linux-amd64 build/service-mesh-hub/ && \
docker build -t $(SMH_IMAGE):$(VERSION) build/service-mesh-hub/
rm build/service-mesh-hub/service-mesh-hub-linux-amd64
.PHONY: service-mesh-hub-image-push
service-mesh-hub-image-push: service-mesh-hub-image
ifeq ($(RELEASE),"true")
docker push $(SMH_IMAGE):$(VERSION)
endif
#----------------------------------------------------------------------------------
# Build cert-agent + image
#----------------------------------------------------------------------------------
# for local development only; to build docker image, use cert-agent-linux-amd-64
.PHONY: cert-agent
cert-agent: $(OUTDIR)/cert-agent
$(OUTDIR)/cert-agent: $(SOURCES)
go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/cert-agent/main.go
.PHONY: cert-agent-linux-amd64
cert-agent-linux-amd64: $(OUTDIR)/cert-agent-linux-amd64
$(OUTDIR)/cert-agent-linux-amd64: $(SOURCES)
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/cert-agent/main.go
# build image with cert-agent binary
# this is an alternative to using operator-gen to build the image
.PHONY: cert-agent-image
cert-agent-image: cert-agent-linux-amd64
cp $(OUTDIR)/cert-agent-linux-amd64 build/cert-agent/ && \
docker build -t $(CA_IMAGE):$(VERSION) build/cert-agent/
rm build/cert-agent/cert-agent-linux-amd64
.PHONY: cert-agent-image-push
cert-agent-image-push: cert-agent-image
ifeq ($(RELEASE),"true")
docker push $(CA_IMAGE):$(VERSION)
endif
#----------------------------------------------------------------------------------
# Build service-mesh-hub cli (meshctl)
#----------------------------------------------------------------------------------
.PHONY: meshctl-linux-amd64
meshctl-linux-amd64: $(OUTDIR)/meshctl-linux-amd64
$(OUTDIR)/meshctl-linux-amd64: $(SOURCES)
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux packr build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/meshctl/main.go
.PHONY: meshctl-darwin-amd64
meshctl-darwin-amd64: $(OUTDIR)/meshctl-darwin-amd64
$(OUTDIR)/meshctl-darwin-amd64: $(SOURCES)
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin packr build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/meshctl/main.go
.PHONY: meshctl-windows-amd64
meshctl-windows-amd64: $(OUTDIR)/meshctl-windows-amd64.exe
$(OUTDIR)/meshctl-windows-amd64.exe: $(SOURCES)
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows packr build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/meshctl/main.go
.PHONY: build-cli
build-cli: install-go-tools meshctl-linux-amd64 meshctl-darwin-amd64 meshctl-windows-amd64
.PHONY: install-cli
install-cli:
packr build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o ${GOPATH}/bin/meshctl cmd/meshctl/main.go
#----------------------------------------------------------------------------------
# Push images
#----------------------------------------------------------------------------------
.PHONY: push-all-images
push-all-images: service-mesh-hub-image-push cert-agent-image-push
#----------------------------------------------------------------------------------
# Helm chart
#----------------------------------------------------------------------------------
HELM_ROOTDIR := install/helm
# Include helm makefile so its targets can be ran from the root of this repo
include install/helm/helm.mk
# Generate Manifests from Helm Chart
.PHONY: chart-gen
chart-gen:
go run -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) codegen/generate.go -chart
.PHONY: manifest-gen
manifest-gen: install/service-mesh-hub-default.yaml
install/service-mesh-hub-default.yaml: chart-gen
helm template --include-crds --namespace service-mesh-hub install/helm/service-mesh-hub > $@
#----------------------------------------------------------------------------------
# Test
#----------------------------------------------------------------------------------
# run all tests
# set TEST_PKG to run a specific test package
.PHONY: run-tests
run-tests:
ginkgo -r -failFast -trace $(GINKGOFLAGS) \
-ldflags=$(LDFLAGS) \
-gcflags=$(GCFLAGS) \
-progress \
-compilers=4 \
-skipPackage=$(SKIP_PACKAGES) $(TEST_PKG)
# regen code+manifests, image build+push, and run all tests
# convenience for local testing
.PHONY: test-everything
test-everything: clean-generated-code generated-code manifest-gen run-tests
##----------------------------------------------------------------------------------
## Release
##----------------------------------------------------------------------------------
.PHONY: upload-github-release-assets
upload-github-release-assets: build-cli
ifeq ($(RELEASE),"true")
go run ci/upload_github_release_assets.go
endif
#----------------------------------------------------------------------------------
# Clean
#----------------------------------------------------------------------------------
.PHONY: clean
clean: clean-helm
rm -f install/service-mesh-hub-default.yaml
rm -rf _output/ vendor_any/
.PHONY: clean-generated-code
clean-generated-code:
find pkg -name "*.pb.go" -type f -delete
find pkg -name "*.hash.go" -type f -delete
find pkg -name "*.gen.go" -type f -delete
find pkg -name "*deepcopy.go" -type f -delete