-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (110 loc) · 4.28 KB
/
Copy pathMakefile
File metadata and controls
138 lines (110 loc) · 4.28 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
BUILD_ARGS = -trimpath
LDFLAGS = -X main.Build=$(if $(BUILD_NUMBER),$(BUILD_NUMBER),"DEBUG")
CMD_PATH = "./cmd/"
# Set up OS specific bits
ifeq ($(OS),Windows_NT)
GOVERSION := $(shell go version | awk "{print substr($$3, 3)}")
GOISMIN := $(shell IF "$(GOVERSION)" GEQ "$(GOMINVERSION)" ECHO 1)
CMD_SUFFIX = .exe
NULL_FILE = nul
else
GOVERSION := $(shell go version | awk '{print substr($$3, 3)}')
GOISMIN := $(shell expr "$(GOVERSION)" ">=" "$(GOMINVERSION)")
CMD_SUFFIX =
NULL_FILE = /dev/null
endif
ALL_LINUX = linux-amd64 \
linux-386 \
linux-arm64
ALL = $(ALL_LINUX)
all: $(ALL:%=build/%/server) $(ALL:%=build/%/server-client) $(ALL:%=build/%/agent)
release: $(ALL:%=build/nebula-provisioner-%.tar.gz)
release-linux: $(ALL_LINUX:%=build/nebula-provisioner-%.tar.gz)
build/%/server: generate webapp .FORCE
CGO_ENABLED=0 \
GOOS=$(firstword $(subst -, , $*)) \
GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${CMD_PATH}/server
build/%/server-client: .FORCE
CGO_ENABLED=0 \
GOOS=$(firstword $(subst -, , $*)) \
GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${CMD_PATH}/server-client
build/%/agent: .FORCE
CGO_ENABLED=0 \
GOOS=$(firstword $(subst -, , $*)) \
GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${CMD_PATH}/agent
build/nebula-provisioner-%.tar.gz: build/%/server build/%/server-client build/%/agent
tar -zcv -C build/$* -f $@ server server-client agent
bin: generate webapp
go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" $(BUILD_TAGS) -o ./bin/server${CMD_SUFFIX} ${CMD_PATH}/server
go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" $(BUILD_TAGS) -o ./bin/server-client${CMD_SUFFIX} ${CMD_PATH}/server-client
go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" $(BUILD_TAGS) -o ./bin/agent${CMD_SUFFIX} ${CMD_PATH}/agent
dev: BUILD_TAGS=-tags dev
dev: LDFLAGS=-X github.com/cego/nebula-provisioner/webapp.Dir=$(CURDIR)/webapp/
dev: bin
fmt:
go fmt ./...
vet:
go vet -v ./...
test:
go test -v ./...
impsort:
find . -iname '*.go' | grep -v '\.pb\.go$$' | xargs go run golang.org/x/tools/cmd/goimports -w
WEBAPP_DIRS = $(shell find ./webapp/ -type d | grep -vE 'webapp/(node_modules|dist)')
WEBAPP_FILES = $(shell find ./webapp/ -type f -name '*' | grep -vE 'webapp/(node_modules|dist)')
webapp: ./webapp/ $(WEBAPP_DIRS) $(WEBAPP_FILES)
$(MAKE) -C webapp build
.PHONY: generate
generate: protoc-gen-go protoc-gen-go-grpc buf gqlgen
$(BUF) generate
$(GQLGEN) generate
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
BUF = $(LOCALBIN)/buf
PROTOC_GEN_GO = $(LOCALBIN)/protoc-gen-go
PROTOC_GEN_GO_GRPC = $(LOCALBIN)/protoc-gen-go-grpc
GQLGEN = $(LOCALBIN)/gqlgen
## Tool Versions
BUF_VERSION ?= v1.66.1
PROTOC_GEN_GO_VERSION ?= v1.36.11
PROTOC_GEN_GO_GRPC_VERSION ?= v1.6.1
GQLGEN_VERSION ?= v0.17.88
.PHONY: buf
buf: $(BUF) ## Download buf locally if necessary.
$(BUF): $(LOCALBIN)
$(call go-install-tool,$(BUF),github.com/bufbuild/buf/cmd/buf,$(BUF_VERSION))
.PHONY: protoc-gen-go
protoc-gen-go: $(PROTOC_GEN_GO) ## Download protoc-gen-go locally if necessary.
$(PROTOC_GEN_GO): $(LOCALBIN)
$(call go-install-tool,$(PROTOC_GEN_GO),google.golang.org/protobuf/cmd/protoc-gen-go,$(PROTOC_GEN_GO_VERSION))
.PHONY: protoc-gen-go-grpc
protoc-gen-go-grpc: $(PROTOC_GEN_GO_GRPC) ## Download protoc-gen-go-grpc locally if necessary.
$(PROTOC_GEN_GO_GRPC): $(LOCALBIN)
$(call go-install-tool,$(PROTOC_GEN_GO_GRPC),google.golang.org/grpc/cmd/protoc-gen-go-grpc,$(PROTOC_GEN_GO_GRPC_VERSION))
.PHONY: gqlgen
gqlgen: $(GQLGEN) ## Download gqlgen locally if necessary.
$(GQLGEN): $(LOCALBIN)
$(call go-install-tool,$(GQLGEN),github.com/99designs/gqlgen,$(GQLGEN_VERSION))
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef
.FORCE:
.PHONY: test bin generate dev
.DEFAULT_GOAL := bin