forked from vmware-archive/vsphere-storage-for-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
365 lines (289 loc) · 10.1 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
# Copyright 2016 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Makefile for Docker data volume plugin
# Guest Package Version
# PKG_VERSION is either set externally as part of a build off a tag or
# suffixed with a sha1 of the most recent commit to the prefix of the
# most recent tag. Tagged builds use the externally defined version,
# developer builds use last tagged release and sha1 of the most recent commit.
# Format: <last tagged release>.<last commit hash>
PKG_VERSION ?= $(shell \
git describe --tags `git rev-list --tags --max-count=1` \
).$(shell \
git log --pretty=format:'%h' -n 1)
export PKG_VERSION
export INCLUDE_UI
EPOCH := 0
# Place binaries here
BIN := ../build
# Location for scripts
SCRIPTS := ../misc/scripts
# Packaging variables
PLUGNAME := docker-volume-vsphere
GOPATH_PLUGNAME := $(PLUGNAME)/vmdk_plugin
GOPATH_ORG :=vmware
MAINTAINERS := cna-storage@vmware.com
REPO_URL := https://github.com/$(GOPATH_ORG)/$(PLUGNAME)
MIN_DOCKER_VERSION :=1.9
DOCKER_PACKAGE := docker-engine
DOCKER_PACKAGE_PHOTON := docker
AFTER_INSTALL := $(SCRIPTS)/install/after-install.sh
BEFORE_REMOVE := $(SCRIPTS)/install/before-remove.sh
AFTER_REMOVE := $(SCRIPTS)/install/after-remove.sh
#
# Scripts to deploy and control services - used from Makefile and from Drone CI
#
CHECK := $(SCRIPTS)/check.sh
BUILD := $(SCRIPTS)/build.sh
SYSTEMD_UNIT := $(SCRIPTS)/install/$(PLUGNAME).service
UPSTART_CONF := $(SCRIPTS)/install/$(PLUGNAME).conf
PACKAGE := package
SYSTEMD_LIB := $(PACKAGE)/lib/systemd/system/
INSTALL_BIN := $(PACKAGE)/usr/local/bin
UPSTART_INIT := $(PACKAGE)/etc/init/
# esx service for docker volume ops
ESX_SRC := ../esx_service
VMCI_SRC := $(ESX_SRC)/vmci/*.h $(ESX_SRC)/vmci/vmci_client.c
# binaries location
PLUGIN_BIN = $(BIN)/$(PLUGNAME)
# all binaries for VMs - plugin and tests
VM_BINS = $(PLUGIN_BIN) $(BIN)/$(VMDKOPS_TEST_MODULE).test $(BIN)/$(PLUGNAME).test
VIBFILE := vmware-esx-vmdkops-$(PKG_VERSION).vib
VIB_BIN := $(BIN)/$(VIBFILE)
# plugin name, for go build
PLUGIN := github.com/$(GOPATH_ORG)/$(GOPATH_PLUGNAME)
GO := GO15VENDOREXPERIMENT=1 go
FPM := fpm
# make sure we rebuild of vmkdops or Dockerfile change (since we develop them together)
VMDKOPS_MODULE := drivers/vmdk/vmdkops
VMDKOPS_TEST_MODULE := vmdkops
VMDKOPS_MODULE_SRC = $(VMDKOPS_MODULE)/*.go $(VMCI_SRC)
# All sources. We rebuild if anything changes here
SRC = main.go log_formatter.go utils/refcount/refcnt.go \
utils/fs/fs.go utils/config/config.go utils/TestInputParamsUtil.go \
drivers/photon/photon_driver.go drivers/vmdk/vmdk_driver.go
# Canned recipe
define log_target
@echo
@echo "=> Running target $@" `date`
@echo
endef
# The default build is using a prebuilt docker image that has all dependencies.
.PHONY: dockerbuild build-all
build-all: dockerbuild package
dockerbuild:
@$(CHECK) dockerbuild
$(BUILD) pylint
$(BUILD) build
# The non docker build.
.PHONY: build pylint
build: prereqs .code_verify $(VM_BINS)
$(MAKE) --directory=$(ESX_SRC) $@
pylint:
$(MAKE) --directory=$(ESX_SRC) $@
.PHONY: gvt
gvt:
$(BUILD) gvt
.PHONY: documentation
documentation:
$(BUILD) documentation
.PHONY: prereqs
prereqs:
@$(CHECK)
$(PLUGIN_BIN): $(SRC) $(VMDKOPS_MODULE_SRC)
@-mkdir -p $(BIN) && chmod a+w $(BIN)
$(GO) build --ldflags '-extldflags "-static"' -o $(PLUGIN_BIN) $(PLUGIN)
$(BIN)/$(VMDKOPS_TEST_MODULE).test: $(VMDKOPS_MODULE_SRC) $(VMDKOPS_MODULE)/*_test.go
$(GO) test -c -o $@ $(PLUGIN)/$(VMDKOPS_MODULE) -cover
$(BIN)/$(PLUGNAME).test: $(SRC) *_test.go
$(GO) test -c -o $@ $(PLUGIN) -cover
.PHONY: clean
clean:
$(BUILD) clean-as-root
.PHONY: clean-as-root
clean-as-root: pkg-post
rm -rf $(BIN) .code_verify
$(MAKE) --directory=$(ESX_SRC) clean
# GO Code quality checks.
DIRS_TO_VERIFY := . utils/fs utils/config drivers/photon drivers/vmdk drivers/vmdk/vmdkops
FILES_TO_VERIFY := $(foreach dir, $(DIRS_TO_VERIFY), $(dir)/*.go)
.code_verify: $(FILES_TO_VERIFY)
@for i in $(DIRS_TO_VERIFY) ; do ${GOPATH}/bin/golint $$i ; done
go tool vet .
gofmt -s -l -w .
@touch $@
# Build the linux distro packages
DOCKER = $(DEBUG) docker
.PHONY: fpm-docker
fpm-docker:
@echo "Building FPM container. It could take a while, please stand by..."
$(DOCKER) build -t cnastorage/fpm -f misc/dockerfiles/Dockerfile.fpm . > /dev/null
.PHONY: pkg
pkg: dockerdeb dockerrpm
.PHONY: package
package: pkg
.PHONY: dockerdeb
dockerdeb: pkg-post
$(BUILD) deb
.PHONY: dockerrpm pkg-post
dockerrpm:
$(BUILD) rpm
DESCRIPTION := "Docker Volume Driver for vSphere"
FPM_COMMON := -p $(BIN) \
-C $(PACKAGE) \
-s dir \
-n $(PLUGNAME) \
-v $(PKG_VERSION) \
--provides $(PLUGNAME) \
-m $(MAINTAINERS) \
--url $(REPO_URL) \
--after-install $(AFTER_INSTALL) \
--before-remove $(BEFORE_REMOVE) \
--after-remove $(AFTER_REMOVE) \
--description $(DESCRIPTION) \
--architecture x86_64 \
--force
# FPM should be installed for target deb
.PHONY: deb
deb: pkg-prep deb-pkg-prep
@$(CHECK) pkg
$(FPM) --deb-no-default-config-files $(FPM_COMMON) -d '$(DOCKER_PACKAGE) > $(MIN_DOCKER_VERSION)' -t deb .
# Upstart needed for older versions of Ubuntu
.PHONY: deb-pkg-prep
deb-pkg-prep:
@mkdir -p $(UPSTART_INIT)
@cp $(UPSTART_CONF) $(UPSTART_INIT)
# Target to build for rpm based systems. Due to variations in how docker is packaged between RHEL and Photon,
# skip dependency check vs building 2 different rpm packages.
.PHONY: rpm
rpm: pkg-prep
@$(CHECK) pkg
#$(FPM) --epoch $(EPOCH) $(FPM_COMMON) -d '$(DOCKER_PACKAGE_PHOTON) > $(MIN_DOCKER_VERSION)' -t rpm .
$(FPM) --epoch $(EPOCH) $(FPM_COMMON) -t rpm .
.PHONY: pkg-prep
pkg-prep:
@mkdir -p $(SYSTEMD_LIB)
@cp $(SYSTEMD_UNIT) $(SYSTEMD_LIB)
@mkdir -p $(INSTALL_BIN)
@cp $(PLUGIN_BIN) $(INSTALL_BIN)
@chmod a+w -R $(PACKAGE)
.PHONY: pkg-post
pkg-post:
@rm -rf $(PACKAGE)
@rm -rf DEBIAN
#
# 'make deploy'
# ----------
# temporary goal to simplify my deployments and sanity check test (create/delete)
#
# expectations:
# Need target machines (ESX/Guest) to have proper ~/.ssh/authorized_keys
#
# You can
# set ESX and VM (and VM1 / VM2) as env. vars,
# or pass on command line
# make deploy-esx ESX=10.20.105.54
# make deploy-vm VM=10.20.105.121
# make testremote ESX=10.20.105.54 VM1=10.20.105.121 VM2=10.20.105.122
VM1 ?= "$(VM)"
VM2 ?= "$(VM)"
TEST_VM = root@$(VM1)
VM1_DOCKER = tcp://$(VM1):2375
VM2_DOCKER = tcp://$(VM2):2375
SSH := $(DEBUG) ssh $(SSH_KEY_OPT) -kTax -o StrictHostKeyChecking=no
# bin locations on target guest
TMP_LOC := /tmp/$(PLUGNAME)
# script sources live here. All scripts are copied to test VM during deployment
# scripts started locally to deploy to and clean up test machines
DEPLOY_VM_SH := $(SCRIPTS)/deploy-tools.sh deployvm
DEPLOY_VM_TEST_SH := $(SCRIPTS)/deploy-tools.sh deployvmtest
DEPLOY_ESX_SH := $(SCRIPTS)/deploy-tools.sh deployesx
CLEANVM_SH := $(SCRIPTS)/deploy-tools.sh cleanvm
CLEANESX_SH := $(SCRIPTS)/deploy-tools.sh cleanesx
#
# Deploy to existing testbed, Expects ESX VM1 and VM2 env vars
#
.PHONY: deploy-esx deploy-vm deploy-vm-test deploy deploy-all deploy
deploy-esx: clean-esx
$(DEPLOY_ESX_SH) "$(ESX)" "$(VIB_BIN)"
VMS= $(VM1) $(VM2)
deploy-vm: clean-vm
$(DEPLOY_VM_SH) "$(VMS)" $(BIN)
deploy-vm-test:
$(DEPLOY_VM_TEST_SH) "$(VMS)" $(BIN) $(SCRIPTS)
deploy-all: deploy-esx deploy-vm deploy-vm-test
deploy: deploy-all
#
# 'make test' or 'make testremote'
# CAUTION: FOR NOW, RUN testremote DIRECTLY VIA 'make'. DO NOT run via './build.sh'
# reason: ssh keys for accessing remote hosts are not in container used by ./build.sh
# ----------
# this is a set of unit tests run on build machine
.PHONY: test
test:
$(log_target)
$(SCRIPTS)/build.sh testasroot
.PHONY: testasroot
testasroot:
$(log_target)
$(GO) test $(PLUGIN)/drivers/vmdk/vmdkops -cover -v
$(GO) test $(PLUGIN)/utils/config -cover -v
# does sanity check of create/remove docker volume on the guest
TEST_VOL_NAME ?= DefaultTestVol
TEST_VERBOSE = -test.v
CONN_MSG := "Please make sure Docker is running and is configured to accept TCP connections"
.PHONY: checkremote
checkremote:
@$(SSH) $(TEST_VM) docker -H $(VM1_DOCKER) ps > /dev/null 2>/dev/null || \
(echo VM1 $(VM1): $(CONN_MSG) ; exit 1)
@$(SSH) $(TEST_VM) docker -H $(VM2_DOCKER) ps > /dev/null 2>/dev/null || \
(echo VM2 $(VM2): $(CONN_MSG); exit 1)
.PHONY: test-vm test-esx test-all testremote e2e-tests
# test-vm runs GO unit tests and plugin test suite on a guest VM
# expects binaries to be deployed ot the VM and ESX (see deploy-all target)
test-vm: checkremote deploy-vm-test
$(log_target)
$(SSH) $(TEST_VM) $(TMP_LOC)/$(VMDKOPS_TEST_MODULE).test $(TEST_VERBOSE)
$(SSH) $(TEST_VM) $(TMP_LOC)/$(PLUGNAME).test $(TEST_VERBOSE) \
-v $(TEST_VOL_NAME) \
-H1 $(VM1_DOCKER) -H2 $(VM2_DOCKER)
# test-esx is a quick unittest for ESX Python code.
test-esx:
$(log_target)
$(MAKE) --directory=$(ESX_SRC) $@
testremote: test-esx test-vm
test-all: test e2e-tests testremote
e2e-tests:
$(log_target)
$(SCRIPTS)/build.sh e2e-dkrVolDriver-test "$(ESX)" "$(VM1)" "$(VM2)"
.PHONY: e2e-dkrVolDriver-test
e2e-dkrVolDriver-test:
$(log_target)
$(GO) test $(PLUGIN)/E2E_Tests -cover -v
.PHONY:clean-vm clean-esx clean-all clean-docker
clean-vm:
$(CLEANVM_SH) "$(VMS)" "$(TEST_VOL_NAME)"
clean-esx:
$(CLEANESX_SH) "$(ESX)" esx-vmdkops-service
# rm ALL containers and volumes. Useful for post-failure force cleanup
clean-docker:
-$(SSH) $(TEST_VM) 'docker kill `docker ps -q`'
-$(SSH) $(TEST_VM) 'docker rm `docker ps -a -q`'
-$(SSH) $(TEST_VM) 'docker volume rm `docker volume ls -q`'
clean-all: clean clean-vm clean-esx
# full circle
all: clean-all build-all deploy-all test-all
# if we do not recognize the target, warn and keep going.
.DEFAULT:
@echo "***" Warning: Skipping unsupported target \"$@\"