forked from zalando/skipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
188 lines (149 loc) · 6.94 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
SOURCES = $(shell find . -name '*.go' -not -path "./vendor/*" -and -not -path "./_test_plugins" -and -not -path "./_test_plugins_fail" )
PACKAGES = $(shell go list ./...)
CURRENT_VERSION = $(shell git describe --tags --always --dirty)
VERSION ?= $(CURRENT_VERSION)
COMMIT_HASH = $(shell git rev-parse --short HEAD)
LIMIT_FDS = $(shell ulimit -n)
TEST_ETCD_VERSION ?= v2.3.8
TEST_PLUGINS = _test_plugins/filter_noop.so \
_test_plugins/predicate_match_none.so \
_test_plugins/dataclient_noop.so \
_test_plugins/multitype_noop.so \
_test_plugins_fail/fail.so
default: build
lib: $(SOURCES)
go build $(PACKAGES)
bindir:
mkdir -p bin
skipper: $(SOURCES) bindir
go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" -o bin/skipper ./cmd/skipper/*.go
eskip: $(SOURCES) bindir
go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" -o bin/eskip ./cmd/eskip/*.go
webhook: $(SOURCES) bindir
go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" -o bin/webhook ./cmd/webhook/*.go
routesrv: $(SOURCES) bindir
go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" -o bin/routesrv ./cmd/routesrv/*.go
fixlimits:
ifeq (LIMIT_FDS, 256)
ulimit -n 1024
endif
build: $(SOURCES) lib skipper eskip webhook routesrv
build.linux.static:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/skipper -ldflags "-extldflags=-static -X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.linux.arm64:
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.linux.armv7:
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.darwin.arm64:
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.darwin:
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
build.windows:
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o bin/skipper -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
install: $(SOURCES)
go install -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/skipper
go install -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT_HASH)" ./cmd/eskip
check: build check-plugins
# go test $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do go test $$p || break; done
shortcheck: build check-plugins fixlimits
# go test -test.short -run ^Test $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do go test -test.short -run ^Test $$p || break -1; done
cicheck: build check-plugins
# go test -test.short -run ^Test $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do go test -tags=redis -test.short -run ^Test $$p || break -1; done
check-race: build
# go test -race -test.short -run ^Test $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do go test -race -test.short -run ^Test $$p || break -1; done
check-plugins: $(TEST_PLUGINS)
go test -run LoadPlugins
_test_plugins/%.so: _test_plugins/%.go
go build -buildmode=plugin -o $@ $<
_test_plugins_fail/%.so: _test_plugins_fail/%.go
go build -buildmode=plugin -o $@ $<
bench: build $(TEST_PLUGINS)
# go test -bench . $(PACKAGES)
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do go test -bench . $$p; done
lint: build staticcheck
clean:
go clean -i -cache -testcache
rm -rf .coverprofile-all .cover
rm -f ./_test_plugins/*.so
rm -f ./_test_plugins_fail/*.so
rm -rf .bin
deps:
go env
./etcd/install.sh $(TEST_ETCD_VERSION)
@go install honnef.co/go/tools/cmd/staticcheck@latest
@go install github.com/securego/gosec/v2/cmd/gosec@latest
@go install golang.org/x/vuln/cmd/govulncheck@latest
vet: $(SOURCES)
go vet $(PACKAGES)
# TODO(sszuecs) review disabling these checks, f.e.:
# -ST1000 missing package doc in many packages
# -ST1003 wrong naming convention Api vs API, Id vs ID
# -ST1012 too many error variables are not having prefix "err"
# -ST1020 too many wrong comments on exported functions to fix right away
# -ST1021 too many wrong comments on exported functions to fix right away
# -ST1022 too many wrong comments on exported functions to fix right away
staticcheck: $(SOURCES)
staticcheck -checks "all,-ST1000,-ST1003,-ST1012,-ST1020,-ST1021" $(PACKAGES)
# TODO(sszuecs) review disabling these checks, f.e.:
# G101 find by variable name match "oauth" are not hardcoded credentials
# G104 ignoring errors are in few cases fine
# G304 reading kubernetes secret filepaths are not a file inclusions
# G307 mostly warns about defer rsp.Body.Close(), see https://github.com/securego/gosec/issues/925
# G402 See https://github.com/securego/gosec/issues/551 and https://github.com/securego/gosec/issues/528
gosec: $(SOURCES)
gosec -quiet -exclude="G101,G104,G304,G307,G402" ./...
govulncheck: $(SOURCES)
govulncheck ./...
fmt: $(SOURCES)
@gofmt -w -s $(SOURCES)
check-fmt: $(SOURCES)
@if [ "$$(gofmt -s -d $(SOURCES))" != "" ]; then false; else true; fi
precommit: fmt build vet staticcheck check-race shortcheck
.coverprofile-all: $(SOURCES) $(TEST_PLUGINS)
# go list -f \
# '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' \
# $(PACKAGES) | xargs -i sh -c {}
#
# due to vendoring and how go test ./... is not the same as go test ./a/... ./b/...
# probably can be reverted once etcd is fully mocked away for tests
#
for p in $(PACKAGES); do \
go list -f \
'{{if len .TestGoFiles}}"go test -tags=redis -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' \
$$p | xargs -i sh -c {}; \
done
go install github.com/modocache/gover@latest
gover . .coverprofile-all
cover: .coverprofile-all
go tool cover -func .coverprofile-all
show-cover: .coverprofile-all
go tool cover -html .coverprofile-all
publish-coverage: .coverprofile-all
curl -s https://codecov.io/bash -o codecov
bash codecov -f .coverprofile-all