forked from libopenstorage/openstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
405 lines (332 loc) · 11.2 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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
HAS_SDKTEST := $(shell command -v sdk-test 2> /dev/null)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(TRAVIS_BRANCH), master)
MOCKSDKSERVERTAG := latest
else
ifeq ($(BRANCH), master)
MOCKSDKSERVERTAG := latest
else
MOCKSDKSERVERTAG := $(shell go run tools/sdkver/sdkver.go)
endif
endif
REGISTRY = openstorage
IMAGE_MOCKSDKSERVER := $(REGISTRY)/mock-sdk-server:$(MOCKSDKSERVERTAG)
ifndef TAGS
TAGS := daemon
endif
ifndef PKGS
PKGS := $(shell go list ./... 2>&1 | grep -v 'vendor' | grep -v 'sanity')
endif
ifeq ($(BUILD_TYPE),debug)
BUILDFLAGS := -gcflags "-N -l"
endif
ifdef HAVE_BTRFS
TAGS+=btrfs_noversion have_btrfs
endif
ifdef HAVE_CHAINFS
TAGS+=have_chainfs
endif
ifndef PROTOC
PROTOC = protoc
endif
ifndef PROTOS_PATH
PROTOS_PATH = $(GOPATH)/src
endif
ifndef PROTOSRC_PATH
PROTOSRC_PATH = $(PROTOS_PATH)/github.com/libopenstorage/openstorage
endif
OSDSANITY:=cmd/osd-sanity/osd-sanity
.PHONY: \
all \
deps \
update-deps \
test-deps \
update-test-deps \
vendor-update \
vendor-without-update \
vendor \
build \
install \
proto \
lint \
vet \
packr \
errcheck \
pretest \
test \
docs \
docker-build-osd-dev \
docker-build \
docker-test \
docker-build-osd-internal \
docker-build-osd \
launch \
launch-local-btrfs \
install-flexvolume-plugin \
$(OSDSANITY)-install \
$(OSDSANITY)-clean \
clean \
generate \
generate-mockfiles \
sdk-check-version
all: build $(OSDSANITY)
# TOOLS build rules
#
$(GOPATH)/bin/golint:
@echo "Installing missing $@ ..."
go get -u github.com/golang/lint/golint
$(GOPATH)/bin/errcheck:
@echo "Installing missing $@ ..."
go get -u github.com/kisielk/errcheck
$(GOPATH)/bin/protoc-gen-go:
@echo "Installing missing $@ ..."
go get -u github.com/golang/protobuf/protoc-gen-go
$(GOPATH)/bin/protoc-gen-grpc-gateway:
@echo "Installing missing $@ ..."
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
$(GOPATH)/bin/protoc-gen-swagger:
@echo "Installing missing $@ ..."
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
$(GOPATH)/bin/govendor:
@echo "Installing missing $@ ..."
go get -u github.com/kardianos/govendor
$(GOPATH)/bin/packr:
@echo "Installing missing $@ ..."
go get -u github.com/gobuffalo/packr/...
$(GOPATH)/bin/cover:
@echo "Installing missing $@ ..."
go get -u golang.org/x/tools/cmd/cover
$(GOPATH)/bin/gotestcover:
@echo "Installing missing $@ ..."
go get -u github.com/pierrre/gotestcover
# DEPS build rules
#
deps:
go get -d -v $(PKGS)
update-deps:
go get -d -v -u -f $(PKGS)
test-deps:
go get -d -v -t $(PKGS)
update-test-deps:
go get -tags "$(TAGS)" -d -v -t -u -f $(PKGS)
vendor-update:
GOOS=linux GOARCH=amd64 go get -tags "daemon btrfs_noversion have_btrfs have_chainfs" -d -v -t -u -f $(PKGS)
vendor-without-update: $(GOPATH)/bin/govendor
rm -rf vendor
govendor init
GOOS=linux GOARCH=amd64 govendor add +external
GOOS=linux GOARCH=amd64 govendor update +vendor
GOOS=linux GOARCH=amd64 govendor add +external
GOOS=linux GOARCH=amd64 govendor update +vendor
vendor: vendor-update vendor-without-update
build: packr
go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)
install: packr $(OSDSANITY)-install
go install -tags "$(TAGS)" $(PKGS)
go install github.com/libopenstorage/openstorage/cmd/osd-token-generator
$(OSDSANITY):
@$(MAKE) -C cmd/osd-sanity
$(OSDSANITY)-install:
@$(MAKE) -C cmd/osd-sanity install
$(OSDSANITY)-clean:
@$(MAKE) -C cmd/osd-sanity clean
docker-build-proto:
docker build -t quay.io/openstorage/osd-proto -f Dockerfile.proto .
docker-proto: $(GOPATH)/bin/protoc-gen-go
docker run \
--privileged \
-v $(shell pwd):/go/src/github.com/libopenstorage/openstorage \
-e "GOPATH=/go" \
-e "DOCKER_PROTO=yes" \
-e "PATH=/bin:/usr/bin:/usr/local/bin:/go/bin" \
quay.io/openstorage/osd-proto \
make proto
proto: $(GOPATH)/bin/protoc-gen-go $(GOPATH)/bin/protoc-gen-grpc-gateway $(GOPATH)/bin/protoc-gen-swagger
ifndef DOCKER_PROTO
$(error Do not run directly. Run 'make docker-proto' instead.)
endif
@echo ">>> Generating protobuf definitions from api/api.proto"
$(PROTOC) -I $(PROTOSRC_PATH) \
-I /usr/local/include \
-I $(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc:. \
$(PROTOSRC_PATH)/api/api.proto
$(PROTOC) -I $(PROTOSRC_PATH) \
-I /usr/local/include \
-I $(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--grpc-gateway_out=logtostderr=true:. \
$(PROTOSRC_PATH)/api/api.proto
$(PROTOC) -I $(PROTOSRC_PATH) \
-I /usr/local/include \
-I $(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--swagger_out=logtostderr=true:$(PROTOSRC_PATH)/api/server/sdk \
$(PROTOSRC_PATH)/api/api.proto
@echo ">>> Upgrading swagger 2.0 to openapi 3.0"
mv api/server/sdk/api/api.swagger.json api/server/sdk/api/20api.swagger.json
swagger2openapi api/server/sdk/api/20api.swagger.json -o api/server/sdk/api/api.swagger.json
rm -f api/server/sdk/api/20api.swagger.json
@echo ">>> Generating grpc protobuf definitions from pkg/flexvolume/flexvolume.proto"
$(PROTOC) -I/usr/local/include -I$(PROTOSRC_PATH) -I$(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. $(PROTOSRC_PATH)/pkg/flexvolume/flexvolume.proto
$(PROTOC) -I/usr/local/include -I$(PROTOSRC_PATH) -I$(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. $(PROTOSRC_PATH)/pkg/flexvolume/flexvolume.proto
@echo ">>> Generating protobuf definitions from pkg/jsonpb/testing/testing.proto"
$(PROTOC) -I $(PROTOSRC_PATH) $(PROTOSRC_PATH)/pkg/jsonpb/testing/testing.proto --go_out=plugins=grpc:.
@echo ">>> Updating SDK versions"
go run tools/sdkver/sdkver.go --swagger api/server/sdk/api/api.swagger.json
lint: $(GOPATH)/bin/golint
golint $(PKGS)
vet:
go vet $(PKGS)
errcheck: $(GOPATH)/bin/errcheck
errcheck -tags "$(TAGS)" $(PKGS)
pretest: lint vet errcheck
install-sdk-test:
ifndef HAS_SDKTEST
@echo "Installing sdk-test"
@-go get -d -u github.com/libopenstorage/sdk-test 1>/dev/null 2>&1
@(cd $(GOPATH)/src/github.com/libopenstorage/sdk-test/cmd/sdk-test && make install )
endif
test-sdk: install-sdk-test launch-sdk
timeout 30 sh -c 'until curl --silent -X GET -d {} http://localhost:9110/v1/clusters/inspectcurrent | grep STATUS_OK; do sleep 1; done'
sdk-test -ginkgo.noColor -ginkgo.noisySkippings=false -sdk.endpoint=localhost:9100 -sdk.cpg=$(GOPATH)/src/github.com/libopenstorage/sdk-test/cmd/sdk-test/cb.yaml
test: packr
go test -tags "$(TAGS)" $(TESTFLAGS) $(PKGS)
docs:
go generate ./cmd/osd/main.go
packr: $(GOPATH)/bin/packr
packr clean
packr
generate-mockfiles:
go generate $(PKGS)
generate: docs generate-mockfiles
sdk: docker-proto docker-build-mock-sdk-server
docker-build-mock-sdk-server: packr
rm -rf _tmp
mkdir -p _tmp
CGO_ENABLED=0 GOOS=linux go build \
-a -ldflags '-extldflags "-static"' \
-tags "$(TAGS)" \
-o ./_tmp/osd \
./cmd/osd
docker build -t $(IMAGE_MOCKSDKSERVER) -f Dockerfile.sdk .
rm -rf _tmp
docker-build-osd-dev-base:
docker build -t quay.io/openstorage/osd-dev-base -f Dockerfile.osd-dev-base .
push-mock-sdk-server: docker-build-mock-sdk-server
docker push $(IMAGE_MOCKSDKSERVER)
docker-build-osd-dev:
# This image is local only and will not be pushed
docker build -t openstorage/osd-dev -f Dockerfile.osd-dev .
docker-build: docker-build-osd-dev
docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
openstorage/osd-dev \
make build
docker-test: docker-build-osd-dev
docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /mnt:/mnt \
-e AWS_REGION \
-e AWS_ZONE \
-e AWS_INSTANCE_NAME \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e GOOGLE_APPLICATION_CREDENTIALS \
-e GCE_INSTANCE_NAME \
-e GCE_INSTANCE_ZONE \
-e GCE_INSTANCE_PROJECT \
-e AZURE_INSTANCE_NAME \
-e AZURE_SUBSCRIPTION_ID \
-e AZURE_RESOURCE_GROUP_NAME \
-e AZURE_ENVIRONMENT \
-e AZURE_TENANT_ID \
-e AZURE_CLIENT_ID \
-e AZURE_CLIENT_SECRET \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
-e "TESTFLAGS=$(TESTFLAGS)" \
openstorage/osd-dev \
make test
docker-build-osd-internal:
rm -rf _tmp
mkdir -p _tmp
go build -a -tags "$(TAGS)" -o _tmp/osd cmd/osd/main.go
docker build -t quay.io/openstorage/osd -f Dockerfile.osd .
docker-build-osd: docker-build-osd-dev
docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
openstorage/osd-dev \
make docker-build-osd-internal
launch-sdk-quick:
@-docker stop sdk > /dev/null 2>&1
docker run --rm --name sdk \
-d -p 9110:9110 -p 9100:9100 \
$(IMAGE_MOCKSDKSERVER)
launch-sdk: sdk launch-sdk-quick
launch: docker-build-osd
docker run \
--privileged \
-d \
-v $(shell pwd)/etc:/etc \
-v /run/docker/plugins:/run/docker/plugins \
-v /var/lib/osd/:/var/lib/osd/ \
-p 9005:9005 \
-p 9100:9100 \
-p 9110:9110 \
quay.io/openstorage/osd -d -f /etc/config/config.yaml
# must set HAVE_BTRFS
launch-local-btrfs: install
sudo bash -x etc/btrfs/init.sh
sudo $(shell which osd) -d -f etc/config/config_btrfs.yaml
install-flexvolume:
go install -a -tags "$(TAGS)" github.com/libopenstorage/openstorage/pkg/flexvolume github.com/libopenstorage/openstorage/pkg/flexvolume/cmd/flexvolume
install-flexvolume-plugin: install-flexvolume
sudo rm -rf /usr/libexec/kubernetes/kubelet/volume/exec-plugins/openstorage~openstorage
sudo mkdir -p /usr/libexec/kubernetes/kubelet/volume/exec-plugins/openstorage~openstorage
sudo chmod 777 /usr/libexec/kubernetes/kubelet/volume/exec-plugins/openstorage~openstorage
cp $(GOPATH)/bin/flexvolume /usr/libexec/kubernetes/kubelet/volume/exec-plugins/openstorage~openstorage/openstorage
clean: $(OSDSANITY)-clean
go clean -i $(PKGS)
packr clean
# Generate test-coverage HTML report
# - note: the 'go test -coverprofile...' does append results, so we're merging individual pkgs in for-loop
coverage: packr $(GOPATH)/bin/cover $(GOPATH)/bin/gotestcover
gotestcover -coverprofile=coverage.out $(PKGS)
go tool cover -html=coverage.out -o coverage.html
@echo "INFO: Summary of coverage"
go tool cover -func=coverage.out
@cp coverage.out coverage.html /mnt/ && \
echo "INFO: libopenstorage coverage saved at /mnt/coverage.{html,out}"
docker-coverage: docker-build-osd-dev
docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /mnt:/mnt \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
-e "TESTFLAGS=$(TESTFLAGS)" \
openstorage/osd-dev \
make coverage
docker-images: docker-build-proto docker-build-osd-dev-base
push-docker-images: docker-images
docker push quay.io/openstorage/osd-dev-base
docker push quay.io/openstorage/osd-proto
# This needs to be adjusted for each release branch according
# to the SDK Version.
# For master (until released), major should be 0 and patch should be 0.
# For release branches, major and minor should be frozen.
sdk-check-version:
go run tools/sdkver/sdkver.go --check-major=0 --check-patch=0