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