github.com/solo-io/service-mesh-hub@v0.9.2/Makefile (about) 1 #---------------------------------------------------------------------------------- 2 # Base 3 #---------------------------------------------------------------------------------- 4 OUTDIR ?= _output 5 PROJECT ?= service-mesh-hub 6 7 DOCKER_REPO ?= soloio 8 SMH_IMAGE ?= $(DOCKER_REPO)/service-mesh-hub 9 CA_IMAGE ?= $(DOCKER_REPO)/cert-agent 10 11 SOURCES := $(shell find . -name "*.go" | grep -v test.go) 12 RELEASE := "true" 13 ifeq ($(TAGGED_VERSION),) 14 TAGGED_VERSION := $(shell git describe --tags --dirty --always) 15 RELEASE := "false" 16 endif 17 18 VERSION ?= $(shell echo $(TAGGED_VERSION) | cut -c 2-) 19 .PHONY: print-version 20 print-version: 21 ifeq ($(TAGGED_VERSION),) 22 exit 1 23 endif 24 echo $(VERSION) 25 26 LDFLAGS := "-X github.com/solo-io/$(PROJECT)/pkg/common/version.Version=$(VERSION)" 27 GCFLAGS := all="-N -l" 28 29 print-info: 30 @echo RELEASE: $(RELEASE) 31 @echo TAGGED_VERSION: $(TAGGED_VERSION) 32 @echo VERSION: $(VERSION) 33 34 #---------------------------------------------------------------------------------- 35 # Code Generation 36 #---------------------------------------------------------------------------------- 37 38 DEPSGOBIN=$(shell pwd)/$(OUTDIR)/.bin 39 export PATH:=$(DEPSGOBIN):$(PATH) 40 export GOBIN:=$(DEPSGOBIN) 41 42 .PHONY: fmt 43 fmt: 44 goimports -w $(shell ls -d */ | grep -v vendor) 45 46 .PHONY: mod-download 47 mod-download: 48 go mod download 49 50 .PHONY: clear-vendor-any 51 clear-vendor-any: 52 rm -rf vendor_any 53 54 # Dependencies for code generation 55 .PHONY: install-go-tools 56 install-go-tools: mod-download 57 mkdir -p $(DEPSGOBIN) 58 go install istio.io/tools/cmd/protoc-gen-jsonshim 59 go install github.com/gogo/protobuf/protoc-gen-gogo 60 go install github.com/golang/protobuf/protoc-gen-go 61 go install github.com/solo-io/protoc-gen-ext 62 go install github.com/golang/mock/mockgen 63 go install golang.org/x/tools/cmd/goimports 64 go install github.com/onsi/ginkgo/ginkgo 65 go install github.com/gobuffalo/packr/packr 66 67 # Call all generated code targets 68 .PHONY: generated-code 69 generated-code: operator-gen \ 70 manifest-gen \ 71 go-generate \ 72 generated-reference-docs \ 73 fmt 74 go mod tidy 75 76 #---------------------------------------------------------------------------------- 77 # Go generate 78 #---------------------------------------------------------------------------------- 79 80 # Run go-generate on all sub-packages 81 go-generate: 82 go generate -v ./... 83 84 #---------------------------------------------------------------------------------- 85 # Operator Code Generation 86 #---------------------------------------------------------------------------------- 87 88 # Generate Operator Code 89 .PHONY: operator-gen 90 operator-gen: clear-vendor-any 91 go run -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) codegen/generate.go 92 93 #---------------------------------------------------------------------------------- 94 # Docs Code Generation 95 #---------------------------------------------------------------------------------- 96 97 # Generate Reference documentation 98 .PHONY: generated-reference-docs 99 generated-reference-docs: clear-vendor-any 100 go run codegen/docs/docsgen.go 101 102 #---------------------------------------------------------------------------------- 103 # Build 104 #---------------------------------------------------------------------------------- 105 106 .PHONY: build-all-images 107 build-all-images: service-mesh-hub-image cert-agent-image 108 109 #---------------------------------------------------------------------------------- 110 # Build service-mesh-hub controller + image 111 #---------------------------------------------------------------------------------- 112 113 # for local development only; to build docker image, use service-mesh-hub-linux-amd-64 114 .PHONY: service-mesh-hub 115 service-mesh-hub: $(OUTDIR)/service-mesh-hub 116 $(OUTDIR)/service-mesh-hub: $(SOURCES) 117 go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/service-mesh-hub/main.go 118 119 .PHONY: service-mesh-hub-linux-amd64 120 service-mesh-hub-linux-amd64: $(OUTDIR)/service-mesh-hub-linux-amd64 121 $(OUTDIR)/service-mesh-hub-linux-amd64: $(SOURCES) 122 CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/service-mesh-hub/main.go 123 124 # build image with service-mesh-hub binary 125 # this is an alternative to using operator-gen to build the image 126 .PHONY: service-mesh-hub-image 127 service-mesh-hub-image: service-mesh-hub-linux-amd64 128 cp $(OUTDIR)/service-mesh-hub-linux-amd64 build/service-mesh-hub/ && \ 129 docker build -t $(SMH_IMAGE):$(VERSION) build/service-mesh-hub/ 130 rm build/service-mesh-hub/service-mesh-hub-linux-amd64 131 132 .PHONY: service-mesh-hub-image-push 133 service-mesh-hub-image-push: service-mesh-hub-image 134 ifeq ($(RELEASE),"true") 135 docker push $(SMH_IMAGE):$(VERSION) 136 endif 137 138 .PHONY: service-mesh-hub-image-load 139 service-mesh-hub-image-load: service-mesh-hub-image 140 kind load docker-image --name mgmt-cluster $(SMH_IMAGE):$(VERSION) 141 142 #---------------------------------------------------------------------------------- 143 # Build cert-agent + image 144 #---------------------------------------------------------------------------------- 145 146 # for local development only; to build docker image, use cert-agent-linux-amd-64 147 .PHONY: cert-agent 148 cert-agent: $(OUTDIR)/cert-agent 149 $(OUTDIR)/cert-agent: $(SOURCES) 150 go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/cert-agent/main.go 151 152 .PHONY: cert-agent-linux-amd64 153 cert-agent-linux-amd64: $(OUTDIR)/cert-agent-linux-amd64 154 $(OUTDIR)/cert-agent-linux-amd64: $(SOURCES) 155 CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/cert-agent/main.go 156 157 # build image with cert-agent binary 158 # this is an alternative to using operator-gen to build the image 159 .PHONY: cert-agent-image 160 cert-agent-image: cert-agent-linux-amd64 161 cp $(OUTDIR)/cert-agent-linux-amd64 build/cert-agent/ && \ 162 docker build -t $(CA_IMAGE):$(VERSION) build/cert-agent/ 163 rm build/cert-agent/cert-agent-linux-amd64 164 165 .PHONY: cert-agent-image-push 166 cert-agent-image-push: cert-agent-image 167 ifeq ($(RELEASE),"true") 168 docker push $(CA_IMAGE):$(VERSION) 169 endif 170 171 .PHONY: cert-agent-image-load 172 cert-agent-image-load: cert-agent-image 173 kind load docker-image --name mgmt-cluster $(CA_IMAGE):$(VERSION) 174 175 176 #---------------------------------------------------------------------------------- 177 # Build service-mesh-hub cli (meshctl) 178 #---------------------------------------------------------------------------------- 179 180 .PHONY: meshctl-linux-amd64 181 meshctl-linux-amd64: $(OUTDIR)/meshctl-linux-amd64 182 $(OUTDIR)/meshctl-linux-amd64: $(SOURCES) 183 CGO_ENABLED=0 GOARCH=amd64 GOOS=linux packr build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/meshctl/main.go 184 185 .PHONY: meshctl-darwin-amd64 186 meshctl-darwin-amd64: $(OUTDIR)/meshctl-darwin-amd64 187 $(OUTDIR)/meshctl-darwin-amd64: $(SOURCES) 188 CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin packr build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/meshctl/main.go 189 190 .PHONY: meshctl-windows-amd64 191 meshctl-windows-amd64: $(OUTDIR)/meshctl-windows-amd64.exe 192 $(OUTDIR)/meshctl-windows-amd64.exe: $(SOURCES) 193 CGO_ENABLED=0 GOARCH=amd64 GOOS=windows packr build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ cmd/meshctl/main.go 194 195 .PHONY: build-cli 196 build-cli: install-go-tools meshctl-linux-amd64 meshctl-darwin-amd64 meshctl-windows-amd64 197 198 .PHONY: install-cli 199 install-cli: 200 packr build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o ${GOPATH}/bin/meshctl cmd/meshctl/main.go 201 202 #---------------------------------------------------------------------------------- 203 # Push images 204 #---------------------------------------------------------------------------------- 205 206 .PHONY: push-all-images 207 push-all-images: service-mesh-hub-image-push cert-agent-image-push 208 209 #---------------------------------------------------------------------------------- 210 # Helm chart 211 #---------------------------------------------------------------------------------- 212 HELM_ROOTDIR := install/helm 213 # Include helm makefile so its targets can be ran from the root of this repo 214 include install/helm/helm.mk 215 216 # Generate Manifests from Helm Chart 217 .PHONY: chart-gen 218 chart-gen: clear-vendor-any 219 go run -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) codegen/generate.go -chart 220 221 .PHONY: manifest-gen 222 manifest-gen: install/service-mesh-hub-default.yaml 223 install/service-mesh-hub-default.yaml: chart-gen 224 helm template --include-crds --namespace service-mesh-hub install/helm/service-mesh-hub > $@ 225 226 #---------------------------------------------------------------------------------- 227 # Test 228 #---------------------------------------------------------------------------------- 229 230 # run all tests 231 # set TEST_PKG to run a specific test package 232 .PHONY: run-tests 233 run-tests: 234 ginkgo -r -failFast -trace $(GINKGOFLAGS) \ 235 -ldflags=$(LDFLAGS) \ 236 -gcflags=$(GCFLAGS) \ 237 -progress \ 238 -race \ 239 -compilers=4 \ 240 -skipPackage=$(SKIP_PACKAGES) $(TEST_PKG) 241 242 # regen code+manifests, image build+push, and run all tests 243 # convenience for local testing 244 .PHONY: test-everything 245 test-everything: clean-generated-code generated-code manifest-gen run-tests 246 247 ##---------------------------------------------------------------------------------- 248 ## Release 249 ##---------------------------------------------------------------------------------- 250 251 .PHONY: upload-github-release-assets 252 upload-github-release-assets: build-cli 253 ifeq ($(RELEASE),"true") 254 go run ci/upload_github_release_assets.go 255 endif 256 257 #---------------------------------------------------------------------------------- 258 # Clean 259 #---------------------------------------------------------------------------------- 260 261 .PHONY: clean 262 clean: clean-helm 263 rm -f install/service-mesh-hub-default.yaml 264 rm -rf _output/ vendor_any/ 265 266 .PHONY: clean-generated-code 267 clean-generated-code: 268 find pkg -name "*.pb.go" -type f -delete 269 find pkg -name "*.hash.go" -type f -delete 270 find pkg -name "*.gen.go" -type f -delete 271 find pkg -name "*deepcopy.go" -type f -delete