6
6
.PHONY : all all-CI build clean default unit-test release tar checks go-version gofmt-src \
7
7
golint-src govet-src run-build compile-with-docker
8
8
9
- DEFAULT_DOCKER_VERSION := 1.12.6
10
9
SHELL := /bin/bash
11
10
EXCLUDE_DIRS := bin docs Godeps scripts vagrant vendor install
12
11
PKG_DIRS := $(filter-out $(EXCLUDE_DIRS ) ,$(subst /,,$(sort $(dir $(wildcard * /) ) ) ) )
@@ -18,19 +17,24 @@ NAME := netplugin
18
17
# we evaluate and set the value of version once in a file and use it in 'tar'
19
18
# and 'release' targets.
20
19
VERSION_FILE := $(NAME ) -version
20
+ # This is treated as a string literal and is evaluated by bash in targets
21
+ # It allows for compile target to set the version file for other targets
21
22
VERSION := ` cat $( VERSION_FILE) `
23
+ TAR := $(shell command -v gtar || echo command -v tar || echo "Could not find tar")
22
24
TAR_EXT := tar.bz2
23
- NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitCommit.sh)
25
+ export NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitCommit.sh)
24
26
TAR_FILENAME := $(NAME ) -$(VERSION ) .$(TAR_EXT )
25
27
TAR_LOC := .
26
- TAR_FILE := $(TAR_LOC ) /$(TAR_FILENAME )
28
+ export NETPLUGIN_TAR_FILE := $(TAR_LOC ) /$(TAR_FILENAME )
29
+ export V2PLUGIN_TAR_FILENAME := v2plugin-$(VERSION ) .tar.gz
27
30
GO_MIN_VERSION := 1.7
28
31
GO_MAX_VERSION := 1.8
29
32
GO_VERSION := $(shell go version | cut -d' ' -f3 | sed 's/go//')
30
33
CI_HOST_TARGETS ?= "host-unit-test host-integ-test host-build-docker-image"
31
34
SYSTEM_TESTS_TO_RUN ?= "00SSH|Basic|Network|Policy|TestTrigger|ACIM|Netprofile"
32
35
K8S_SYSTEM_TESTS_TO_RUN ?= "00SSH|Basic|Network|Policy"
33
36
ACI_GW_IMAGE ?= "contiv/aci-gw:04-12-2017.2.2_1n"
37
+ export CONTIV_V2PLUGIN_NAME ?= contiv/v2plugin :0.1
34
38
35
39
all : build unit-test system-test ubuntu-tests
36
40
@@ -43,7 +47,7 @@ all-CI: stop clean start
43
47
&& cd /opt/gopath/src/github.com/contiv/netplugin \
44
48
&& make ${CI_HOST_TARGETS} " '
45
49
ifdef SKIP_SYSTEM_TEST
46
- echo "Skipping system tests"
50
+ @ echo "Skipping system tests"
47
51
else
48
52
make system-test
49
53
endif
@@ -95,14 +99,15 @@ checks: go-version govet-src golint-src gofmt-src misspell-src
95
99
checks-with-docker :
96
100
scripts/code_checks_in_docker.sh $(PKG_DIRS )
97
101
102
+ # install binaries into GOPATH and update file netplugin-version
98
103
compile :
99
104
cd $(GOPATH ) /src/github.com/contiv/netplugin && \
100
105
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} BUILD_VERSION=${BUILD_VERSION} \
101
- TO_BUILD=" ${TO_BUILD} " VERSION_FILE=${ VERSION_FILE} \
106
+ TO_BUILD=" ${TO_BUILD} " VERSION_FILE=$( VERSION_FILE ) \
102
107
scripts/build.sh
103
108
104
109
# fully prepares code for pushing to branch, includes building binaries
105
- run-build : deps checks clean compile
110
+ run-build : deps checks clean compile archive
106
111
107
112
compile-with-docker :
108
113
docker build \
@@ -129,7 +134,7 @@ update:
129
134
# setting CONTIV_NODES=<number> while calling 'make demo' can be used to bring
130
135
# up a cluster of <number> nodes. By default <number> = 1
131
136
start :
132
- CONTIV_DOCKER_VERSION= " $$ {CONTIV_DOCKER_VERSION:- $( DEFAULT_DOCKER_VERSION ) } " CONTIV_NODE_OS=${CONTIV_NODE_OS} vagrant up
137
+ CONTIV_NODE_OS=${CONTIV_NODE_OS} vagrant up
133
138
134
139
# ===================================================================
135
140
# kubernetes demo targets
213
218
@vagrant ssh netplugin-node1 -c ' bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin/ && bash"' || echo ' Please run "make demo"'
214
219
215
220
ssh-build : start
216
- vagrant ssh netplugin- node1 -c ' bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make run-build install-shell-completion" '
221
+ $( call make-on- node1, run-build install-shell-completion)
217
222
218
223
unit-test : stop clean
219
224
./scripts/unittests -vagrant
@@ -290,63 +295,121 @@ host-restart:
290
295
291
296
# create the rootfs for v2plugin. this is required for docker plugin create command
292
297
host-pluginfs-create :
293
- @echo dev: creating a docker v2plugin rootfs ...
294
- sh scripts/v2plugin_rootfs.sh
298
+ ./scripts/v2plugin_rootfs.sh
295
299
296
- # if rootfs already exists, copy newly compiled contiv binaries and start plugin on local host
297
- host-plugin-update :
298
- @echo dev: updating docker v2plugin ...
300
+ # remove the v2plugin from docker
301
+ host-plugin-remove :
302
+ @echo dev: removing docker v2plugin ...
299
303
docker plugin disable ${CONTIV_V2PLUGIN_NAME}
300
304
docker plugin rm -f ${CONTIV_V2PLUGIN_NAME}
301
- cp bin/netplugin bin/netmaster bin/netctl install/v2plugin/rootfs
305
+
306
+ # add the v2plugin to docker with the current rootfs
307
+ host-plugin-create :
308
+ @echo Creating docker v2plugin
302
309
docker plugin create ${CONTIV_V2PLUGIN_NAME} install/v2plugin
303
310
docker plugin enable ${CONTIV_V2PLUGIN_NAME}
304
311
305
- # cleanup all containers, plugins and start the v2plugin on all hosts
306
- host-plugin-restart :
312
+ # re-deploy the v2plugin in docker with latest versioned binaries
313
+ host-plugin-update : host-plugin-remove unarchive host-plugin-create
314
+ rm -rf install/v2plugin/rootfs
315
+
316
+ # cleanup all containers, recreate and start the v2plugin on all hosts
317
+ # uses the latest compile binaries
318
+ host-plugin-restart : unarchive
307
319
@echo dev: restarting services...
308
- cp bin/netplugin bin/netmaster bin/netctl install/v2plugin/rootfs
309
- cd $(GOPATH ) /src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./startPlugin.py -nodes ${CLUSTER_NODE_IPS} -plugintype " v2plugin"
310
-
311
- # complete workflow to create rootfs, create/enable plugin and start swarm-mode
312
- demo-v2plugin :
313
- CONTIV_V2PLUGIN_NAME=" $$ {CONTIV_V2PLUGIN_NAME:-contiv/v2plugin:0.1}" CONTIV_DOCKER_VERSION=" $$ {CONTIV_DOCKER_VERSION:-1.13.1}" CONTIV_DOCKER_SWARM=" $$ {CONTIV_DOCKER_SWARM:-swarm_mode}" make ssh-build
314
- vagrant ssh netplugin-node1 -c ' bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-pluginfs-create host-plugin-restart host-swarm-restart"'
315
-
316
- # release a v2 plugin
317
- host-plugin-release :
318
- @echo dev: creating a docker v2plugin ...
319
- sh scripts/v2plugin_rootfs.sh
320
- docker plugin create ${CONTIV_V2PLUGIN_NAME} install/v2plugin
320
+ cd $(GOPATH ) /src/github.com/contiv/netplugin/scripts/python \
321
+ && PYTHONIOENCODING=utf-8 ./startPlugin.py -nodes ${CLUSTER_NODE_IPS} \
322
+ -plugintype " v2plugin"
323
+
324
+ # unpack v2plugin archive created by host-pluginfs-create
325
+ host-pluginfs-unpack :
326
+ # clear out old plugin completely
327
+ sudo rm -rf install/v2plugin/rootfs
328
+ mkdir -p install/v2plugin/rootfs
329
+ sudo tar -xf install/v2plugin/${V2PLUGIN_TAR_FILENAME} \
330
+ -C install/v2plugin/rootfs/ \
331
+ --exclude=usr/share/terminfo --exclude=dev/null \
332
+ --exclude=etc/terminfo/v/vt220
333
+
334
+ # Runs make targets on the first netplugin vagrant node
335
+ # this is used as a macro like $(call make-on-node1, compile checks)
336
+ make-on-node1 = vagrant ssh netplugin-node1 -c '\
337
+ bash -lc "source /etc/profile.d/envvar.sh \
338
+ && cd /opt/gopath/src/github.com/contiv/netplugin && make $(1 ) "'
339
+
340
+ # Calls macro make-on-node1 but can be used as a dependecy by setting
341
+ # the variable "node1-make-targets"
342
+ make-on-node1-dep :
343
+ $(call make-on-node1, $(node1-make-targets ) )
344
+
345
+ # assumes the v2plugin archive is available, installs the v2plugin and resets
346
+ # everything on the vm to clean state
347
+ v2plugin-install :
348
+ @echo Installing v2plugin
349
+ $(call make-on-node1, install-shell-completion host-pluginfs-unpack \
350
+ host-plugin-restart host-swarm-restart)
351
+
352
+ # Just like demo-v2plugin except builds are done locally and cached
353
+ demo-v2plugin-from-local : export CONTIV_DOCKER_VERSION ?= 1.13.1
354
+ demo-v2plugin-from-local : export CONTIV_DOCKER_SWARM := swarm_mode
355
+ demo-v2plugin-from-local : tar host-pluginfs-create start v2plugin-install
356
+
357
+ # demo v2plugin on VMs: creates plugin assets, starts docker swarm
358
+ # then creates and enables v2plugin
359
+ demo-v2plugin : export CONTIV_DOCKER_VERSION ?= 1.13.1
360
+ demo-v2plugin : export CONTIV_DOCKER_SWARM := swarm_mode
361
+ demo-v2plugin : node1-make-targets := host-pluginfs-create
362
+ demo-v2plugin : ssh-build make-on-node1-dep v2plugin-install
363
+
364
+ # release a v2 plugin from the VM
365
+ host-plugin-release : tar host-pluginfs-create host-pluginfs-unpack host-plugin-create
321
366
@echo dev: pushing ${CONTIV_V2PLUGIN_NAME} to docker hub
322
367
@echo dev: need docker login with user in contiv org
323
368
docker plugin push ${CONTIV_V2PLUGIN_NAME}
324
369
370
+ # unarchive versioned binaries to bin, usually as a helper for other targets
371
+ # uses the version stored in file 'netplugin-version' which is produced anytime
372
+ # binaries are compiled (and that version can be set with env var
373
+ # 'BUILD_VERSION'
374
+ unarchive :
375
+ @# $(NETPLUGIN_TAR_FILE) depends on local file netplugin-version (exists in image),
376
+ @# but it is evaluated after we have extracted that file to local disk
377
+ @echo Updating bin/ with binaries versioned $(VERSION )
378
+ tar -xf $(NETPLUGIN_TAR_FILE ) -C bin
379
+
380
+ # pulls netplugin binaries from build container
381
+ binaries-from-container :
382
+ docker rm netplugin-build 2> /dev/null || :
383
+ c_id=$$(docker create --name netplugin-build \
384
+ netplugin-build:$(NETPLUGIN_CONTAINER_TAG ) ) && \
385
+ docker cp \
386
+ $$ {c_id}:/go/src/github.com/contiv/netplugin/netplugin-version ./ && \
387
+ for f in netplugin netmaster netctl contivk8s netcontiv; do \
388
+ docker cp -a $$ {c_id}:/go/bin/$$ f bin/$$ f; done && \
389
+ docker rm $$ {c_id}
390
+
325
391
# #########################
326
392
# # Packaging and Releasing
327
393
# #########################
328
394
329
- # build tarball
330
- tar : compile-with-docker
331
- @# $(TAR_FILE) depends on local file netplugin-version (exists in image),
332
- @# but it is evaluated after we have extracted that file to local disk
333
- docker rm netplugin-build || :
334
- c_id=$$(docker create --name netplugin-build netplugin-build:$(NETPLUGIN_CONTAINER_TAG ) ) && \
335
- docker cp $$ {c_id}:/go/src/github.com/contiv/netplugin/netplugin-version ./ && \
336
- for f in netplugin netmaster netctl contivk8s netcontiv; do \
337
- docker cp $$ {c_id}:/go/bin/$$ f bin/$$ f; done && \
338
- docker rm $$ {c_id}
339
- tar -jcf $(TAR_FILE ) \
395
+ archive :
396
+ $(TAR ) --version | grep -q GNU \
397
+ || (echo Please use GNU tar as \' gtar\' or \' tar\' ; exit 1)
398
+ $(TAR ) --owner=0 --group=0 -jcf $(NETPLUGIN_TAR_FILE ) \
340
399
-C bin netplugin netmaster netctl contivk8s netcontiv \
341
400
-C ../scripts contrib/completion/bash/netctl get-contiv-diags
342
401
402
+ # build versioned archive of netplugin binaries
403
+ tar : compile-with-docker binaries-from-container archive
404
+
343
405
clean-tar :
344
406
@rm -f $(TAR_LOC ) /* .$(TAR_EXT )
345
407
@rm -f ${VERSION_FILE}
408
+ @rm -f install/v2plugin/v2plugin-* .tar.gz
346
409
347
410
# GITHUB_USER and GITHUB_TOKEN are needed be set to run github-release
348
411
release : tar
349
- TAR_FILENAME=$(TAR_FILENAME ) TAR_FILE=$(TAR_FILE ) \
412
+ TAR_FILENAME=$(TAR_FILENAME ) TAR_FILE=$(NETPLUGIN_TAR_FILE ) \
350
413
OLD_VERSION=${OLD_VERSION} BUILD_VERSION=${BUILD_VERSION} \
351
414
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} scripts/release.sh
352
415
@make clean-tar
0 commit comments