1
- # make BUILD_VERSION=1.2.3 [compile-with-docker] will set netplugin -version output
2
- # make BUILD_VERSION=1.2.3 tar will set the tar filename
3
- # default naming will otherwise be value of version/CURRENT_VERSION
1
+ # BUILD_VERSION will affect archive filenames as well as -version
2
+ # default version will be based on $(git describe --tags --always)
4
3
5
4
6
5
.PHONY : all all-CI build clean default unit-test release tar checks go-version gofmt-src \
7
6
golint-src govet-src run-build compile-with-docker
8
7
9
8
DEFAULT_DOCKER_VERSION := 1.12.6
9
+ V2PLUGIN_DOCKER_VERSION := 1.13.1
10
10
SHELL := /bin/bash
11
11
EXCLUDE_DIRS := bin docs Godeps scripts vagrant vendor install
12
12
PKG_DIRS := $(filter-out $(EXCLUDE_DIRS ) ,$(subst /,,$(sort $(dir $(wildcard * /) ) ) ) )
13
13
TO_BUILD := ./netplugin/ ./netmaster/ ./netctl/netctl/ ./mgmtfn/k8splugin/contivk8s/ ./mgmtfn/mesosplugin/netcontiv/
14
14
HOST_GOBIN := ` if [ -n " $$ (go env GOBIN)" ]; then go env GOBIN; else dirname $$ (which go); fi `
15
15
HOST_GOROOT := ` go env GOROOT `
16
16
NAME := netplugin
17
- # We are using date based versioning, so for consistent version during a build
18
- # we evaluate and set the value of version once in a file and use it in 'tar'
19
- # and 'release' targets.
20
- VERSION_FILE := $(NAME ) -version
21
- VERSION := ` cat $( VERSION_FILE) `
17
+ VERSION := $(shell scripts/getGitVersion.sh)
18
+ TAR := $(shell command -v gtar || echo command -v tar || echo "Could not find tar")
22
19
TAR_EXT := tar.bz2
23
- NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitCommit .sh)
20
+ export NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitVersion .sh)
24
21
TAR_FILENAME := $(NAME ) -$(VERSION ) .$(TAR_EXT )
25
22
TAR_LOC := .
26
- TAR_FILE := $(TAR_LOC ) /$(TAR_FILENAME )
23
+ export TAR_FILE := $(TAR_LOC ) /$(TAR_FILENAME )
24
+ export V2PLUGIN_TAR_FILENAME := v2plugin-$(VERSION ) .tar.gz
27
25
GO_MIN_VERSION := 1.7
28
26
GO_MAX_VERSION := 1.8
29
27
GO_VERSION := $(shell go version | cut -d' ' -f3 | sed 's/go//')
30
28
CI_HOST_TARGETS ?= "host-unit-test host-integ-test host-build-docker-image"
31
29
SYSTEM_TESTS_TO_RUN ?= "00SSH|Basic|Network|Policy|TestTrigger|ACIM|Netprofile"
32
30
K8S_SYSTEM_TESTS_TO_RUN ?= "00SSH|Basic|Network|Policy"
33
31
ACI_GW_IMAGE ?= "contiv/aci-gw:04-12-2017.2.2_1n"
32
+ export CONTIV_V2PLUGIN_NAME ?= contiv/v2plugin :0.1
34
33
35
34
all : build unit-test system-test ubuntu-tests
36
35
@@ -43,7 +42,7 @@ all-CI: stop clean start
43
42
&& cd /opt/gopath/src/github.com/contiv/netplugin \
44
43
&& make ${CI_HOST_TARGETS} " '
45
44
ifdef SKIP_SYSTEM_TEST
46
- echo "Skipping system tests"
45
+ @ echo "Skipping system tests"
47
46
else
48
47
make system-test
49
48
endif
@@ -95,19 +94,19 @@ checks: go-version govet-src golint-src gofmt-src misspell-src
95
94
checks-with-docker :
96
95
scripts/code_checks_in_docker.sh $(PKG_DIRS )
97
96
97
+ # install binaries into GOPATH and update file netplugin-version
98
98
compile :
99
99
cd $(GOPATH ) /src/github.com/contiv/netplugin && \
100
- NIGHTLY_RELEASE=${NIGHTLY_RELEASE} BUILD_VERSION=${BUILD_VERSION} \
101
- TO_BUILD=" ${TO_BUILD} " VERSION_FILE=${VERSION_FILE} \
102
- scripts/build.sh
100
+ NIGHTLY_RELEASE=${NIGHTLY_RELEASE} TO_BUILD=" ${TO_BUILD} " \
101
+ BUILD_VERSION=$(VERSION ) scripts/build.sh
103
102
104
103
# fully prepares code for pushing to branch, includes building binaries
105
- run-build : deps checks clean compile
104
+ run-build : deps checks clean compile archive
106
105
107
106
compile-with-docker :
108
107
docker build \
109
- --build-arg NIGHTLY_RELEASE=${ NIGHTLY_RELEASE} \
110
- --build-arg BUILD_VERSION=${BUILD_VERSION} \
108
+ --build-arg NIGHTLY_RELEASE=$( NIGHTLY_RELEASE ) \
109
+ --build-arg BUILD_VERSION=$( VERSION ) \
111
110
-t netplugin-build:$(NETPLUGIN_CONTAINER_TAG ) .
112
111
113
112
build-docker-image : start
@@ -290,63 +289,131 @@ host-restart:
290
289
291
290
# create the rootfs for v2plugin. this is required for docker plugin create command
292
291
host-pluginfs-create :
293
- @echo dev: creating a docker v2plugin rootfs ...
294
- sh scripts/v2plugin_rootfs.sh
292
+ ./scripts/v2plugin_rootfs.sh
295
293
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 ...
294
+ # remove the v2plugin from docker
295
+ host-plugin-remove :
296
+ @echo dev: removing docker v2plugin ...
299
297
docker plugin disable ${CONTIV_V2PLUGIN_NAME}
300
298
docker plugin rm -f ${CONTIV_V2PLUGIN_NAME}
301
- cp bin/netplugin bin/netmaster bin/netctl install/v2plugin/rootfs
299
+
300
+ # add the v2plugin to docker with the current rootfs
301
+ host-plugin-create :
302
+ @echo Creating docker v2plugin
302
303
docker plugin create ${CONTIV_V2PLUGIN_NAME} install/v2plugin
303
304
docker plugin enable ${CONTIV_V2PLUGIN_NAME}
304
305
305
- # cleanup all containers, plugins and start the v2plugin on all hosts
306
- host-plugin-restart :
306
+ # Shortcut for an existing v2plugin cluster to update the netplugin
307
+ # binaries.
308
+ # Recommended process after updating netplugin source:
309
+ # make compile archive host-plugin-update
310
+ # Note: only updates a single host
311
+ # Note: only applies to v2plugin (which implies docker 1.13+)
312
+ host-plugin-update : host-plugin-remove unarchive host-plugin-create
313
+ # same behavior as host-plugin-update but runs locally with docker 1.13+
314
+ plugin-update : tar
315
+ $(call make-on-node1, host-plugin-update)
316
+
317
+ # cleanup all containers, recreate and start the v2plugin on all hosts
318
+ # uses the latest compiled binaries
319
+ host-plugin-restart : unarchive
307
320
@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
321
+ cd $(GOPATH ) /src/github.com/contiv/netplugin/scripts/python \
322
+ && PYTHONIOENCODING=utf-8 ./startPlugin.py -nodes ${CLUSTER_NODE_IPS} \
323
+ -plugintype " v2plugin"
324
+
325
+ # unpack v2plugin archive created by host-pluginfs-create
326
+ # Note: do not unpack locally to share with VM, unpack on the target machine
327
+ host-pluginfs-unpack :
328
+ # clear out old plugin completely
329
+ sudo rm -rf install/v2plugin/rootfs
330
+ mkdir -p install/v2plugin/rootfs
331
+ sudo tar -xf install/v2plugin/${V2PLUGIN_TAR_FILENAME} \
332
+ -C install/v2plugin/rootfs/ \
333
+ --exclude=usr/share/terminfo --exclude=dev/null \
334
+ --exclude=etc/terminfo/v/vt220
335
+
336
+ # Runs make targets on the first netplugin vagrant node
337
+ # this is used as a macro like $(call make-on-node1, compile checks)
338
+ make-on-node1 = vagrant ssh netplugin-node1 -c '\
339
+ bash -lc "source /etc/profile.d/envvar.sh \
340
+ && cd /opt/gopath/src/github.com/contiv/netplugin && make $(1 ) "'
341
+
342
+ # Calls macro make-on-node1 but can be used as a dependecy by setting
343
+ # the variable "node1-make-targets"
344
+ make-on-node1-dep :
345
+ $(call make-on-node1, $(node1-make-targets ) )
346
+
347
+ # assumes the v2plugin archive is available, installs the v2plugin and resets
348
+ # everything on the vm to clean state
349
+ v2plugin-install :
350
+ @echo Installing v2plugin
351
+ $(call make-on-node1, install-shell-completion host-pluginfs-unpack \
352
+ host-plugin-restart host-swarm-restart)
353
+
354
+ # Just like demo-v2plugin except builds are done locally and cached
355
+ demo-v2plugin-from-local : export CONTIV_DOCKER_VERSION ?= $(V2PLUGIN_DOCKER_VERSION )
356
+ demo-v2plugin-from-local : export CONTIV_DOCKER_SWARM := swarm_mode
357
+ demo-v2plugin-from-local : tar host-pluginfs-create start v2plugin-install
358
+
359
+ # demo v2plugin on VMs: creates plugin assets, starts docker swarm
360
+ # then creates and enables v2plugin
361
+ demo-v2plugin : export CONTIV_DOCKER_VERSION ?= $(V2PLUGIN_DOCKER_VERSION )
362
+ demo-v2plugin : export CONTIV_DOCKER_SWARM := swarm_mode
363
+ demo-v2plugin : node1-make-targets := host-pluginfs-create
364
+ demo-v2plugin : ssh-build make-on-node1-dep v2plugin-install
365
+
366
+ # release a v2 plugin from the VM
367
+ host-plugin-release : tar host-pluginfs-create host-pluginfs-unpack host-plugin-create
321
368
@echo dev: pushing ${CONTIV_V2PLUGIN_NAME} to docker hub
322
369
@echo dev: need docker login with user in contiv org
370
+ @echo " dev: docker login --username <username>"
323
371
docker plugin push ${CONTIV_V2PLUGIN_NAME}
324
372
373
+ # unarchive versioned binaries to bin, usually as a helper for other targets
374
+ unarchive :
375
+ @echo Updating bin/ with binaries versioned $(VERSION )
376
+ tar -xf $(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
+ for f in netplugin netmaster netctl contivk8s netcontiv; do \
384
+ docker cp -a $$ {c_id}:/go/bin/$$ f bin/$$ f; done && \
385
+ docker rm $$ {c_id}
386
+
325
387
# #########################
326
388
# # Packaging and Releasing
327
389
# #########################
328
390
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 ) \
391
+ archive :
392
+ $(TAR ) --version | grep -q GNU \
393
+ || (echo Please use GNU tar as \' gtar\' or \' tar\' ; exit 1)
394
+ $(TAR ) --owner=0 --group=0 -jcf $(TAR_FILE ) \
340
395
-C bin netplugin netmaster netctl contivk8s netcontiv \
341
396
-C ../scripts contrib/completion/bash/netctl get-contiv-diags
342
397
398
+ # build versioned archive of netplugin binaries
399
+ tar : compile-with-docker binaries-from-container archive
400
+
343
401
clean-tar :
344
402
@rm -f $(TAR_LOC ) /* .$(TAR_EXT )
345
- @rm -f ${VERSION_FILE}
403
+ @rm -f install/v2plugin/v2plugin- * .tar.gz
346
404
347
- # GITHUB_USER and GITHUB_TOKEN are needed be set to run github-release
348
- release : tar
349
- TAR_FILENAME=$(TAR_FILENAME ) TAR_FILE=$(TAR_FILE ) \
350
- OLD_VERSION=${OLD_VERSION} BUILD_VERSION=${BUILD_VERSION} \
405
+ # do not run directly, use "release" target
406
+ release-built-version : tar
407
+ TAR_FILENAME=$(TAR_FILENAME ) TAR_FILE=$(TAR_FILE ) OLD_VERSION=${OLD_VERSION} \
351
408
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} scripts/release.sh
352
409
@make clean-tar
410
+
411
+ # The first "release" below is not a target, it is a "target-specific variable"
412
+ # and sets (and in this case exports) a variable to the target's environment
413
+ # The second release runs make as a subshell but with BUILD_VERSION set
414
+ # to write the correct version for assets everywhere
415
+ #
416
+ # GITHUB_USER and GITHUB_TOKEN are needed be set (used by github-release)
417
+ release : export BUILD_VERSION=$(shell cat version/CURRENT_VERSION)
418
+ release :
419
+ @make release-built-version
0 commit comments