Skip to content

Commit 2a93dba

Browse files
authored
Merge pull request #1061 from contiv/master
Merge master into release-1.1
2 parents b9fe814 + 92cd1fe commit 2a93dba

File tree

20 files changed

+453
-286
lines changed

20 files changed

+453
-286
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# we want to get the git commit SHA but not all the binary repo data
22
.git/objects/pack
33
bin/
4+
**/*.pyc
45
.vagrant
56
vagrant/
67
docs/
78
scripts/gobgp
9+
# this is the dockerfile for binary compilation, other dockerfiles
10+
# may want archive artifacts, but this one does not
811
*.tar
12+
**/*.tar.gz
913
*.bz2
1014
# export from a docker container, no need to copy into any docker containers
1115
install/v2plugin/rootfs

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ cscope*
4343
.out.vagrant
4444
.etc_hosts
4545

46-
# docker v2 plugin temp files
46+
# docker v2 plugin files
4747
install/v2plugin/rootfs
4848
install/v2plugin/config.json
49+
install/v2plugin/v2plugin-*.tar.gz
4950

5051
# netcontain temporary build files
5152
scripts/netContain/bin

Makefile

+121-54
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
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)
43

54

65
.PHONY: all all-CI build clean default unit-test release tar checks go-version gofmt-src \
76
golint-src govet-src run-build compile-with-docker
87

98
DEFAULT_DOCKER_VERSION := 1.12.6
9+
V2PLUGIN_DOCKER_VERSION := 1.13.1
1010
SHELL := /bin/bash
1111
EXCLUDE_DIRS := bin docs Godeps scripts vagrant vendor install
1212
PKG_DIRS := $(filter-out $(EXCLUDE_DIRS),$(subst /,,$(sort $(dir $(wildcard */)))))
1313
TO_BUILD := ./netplugin/ ./netmaster/ ./netctl/netctl/ ./mgmtfn/k8splugin/contivk8s/ ./mgmtfn/mesosplugin/netcontiv/
1414
HOST_GOBIN := `if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else dirname $$(which go); fi`
1515
HOST_GOROOT := `go env GOROOT`
1616
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")
2219
TAR_EXT := tar.bz2
23-
NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitCommit.sh)
20+
export NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitVersion.sh)
2421
TAR_FILENAME := $(NAME)-$(VERSION).$(TAR_EXT)
2522
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
2725
GO_MIN_VERSION := 1.7
2826
GO_MAX_VERSION := 1.8
2927
GO_VERSION := $(shell go version | cut -d' ' -f3 | sed 's/go//')
3028
CI_HOST_TARGETS ?= "host-unit-test host-integ-test host-build-docker-image"
3129
SYSTEM_TESTS_TO_RUN ?= "00SSH|Basic|Network|Policy|TestTrigger|ACIM|Netprofile"
3230
K8S_SYSTEM_TESTS_TO_RUN ?= "00SSH|Basic|Network|Policy"
3331
ACI_GW_IMAGE ?= "contiv/aci-gw:04-12-2017.2.2_1n"
32+
export CONTIV_V2PLUGIN_NAME ?= contiv/v2plugin:0.1
3433

3534
all: build unit-test system-test ubuntu-tests
3635

@@ -43,7 +42,7 @@ all-CI: stop clean start
4342
&& cd /opt/gopath/src/github.com/contiv/netplugin \
4443
&& make ${CI_HOST_TARGETS}"'
4544
ifdef SKIP_SYSTEM_TEST
46-
echo "Skipping system tests"
45+
@echo "Skipping system tests"
4746
else
4847
make system-test
4948
endif
@@ -95,19 +94,19 @@ checks: go-version govet-src golint-src gofmt-src misspell-src
9594
checks-with-docker:
9695
scripts/code_checks_in_docker.sh $(PKG_DIRS)
9796

97+
# install binaries into GOPATH and update file netplugin-version
9898
compile:
9999
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
103102

104103
# 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
106105

107106
compile-with-docker:
108107
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) \
111110
-t netplugin-build:$(NETPLUGIN_CONTAINER_TAG) .
112111

113112
build-docker-image: start
@@ -290,63 +289,131 @@ host-restart:
290289

291290
# create the rootfs for v2plugin. this is required for docker plugin create command
292291
host-pluginfs-create:
293-
@echo dev: creating a docker v2plugin rootfs ...
294-
sh scripts/v2plugin_rootfs.sh
292+
./scripts/v2plugin_rootfs.sh
295293

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 ...
299297
docker plugin disable ${CONTIV_V2PLUGIN_NAME}
300298
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
302303
docker plugin create ${CONTIV_V2PLUGIN_NAME} install/v2plugin
303304
docker plugin enable ${CONTIV_V2PLUGIN_NAME}
304305

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
307320
@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
321368
@echo dev: pushing ${CONTIV_V2PLUGIN_NAME} to docker hub
322369
@echo dev: need docker login with user in contiv org
370+
@echo "dev: docker login --username <username>"
323371
docker plugin push ${CONTIV_V2PLUGIN_NAME}
324372

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+
325387
##########################
326388
## Packaging and Releasing
327389
##########################
328390

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) \
340395
-C bin netplugin netmaster netctl contivk8s netcontiv \
341396
-C ../scripts contrib/completion/bash/netctl get-contiv-diags
342397

398+
# build versioned archive of netplugin binaries
399+
tar: compile-with-docker binaries-from-container archive
400+
343401
clean-tar:
344402
@rm -f $(TAR_LOC)/*.$(TAR_EXT)
345-
@rm -f ${VERSION_FILE}
403+
@rm -f install/v2plugin/v2plugin-*.tar.gz
346404

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} \
351408
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} scripts/release.sh
352409
@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

RELEASE.md

+3-15
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,9 @@ You'll find a few examples below:
3838

3939
Please keep in mind that the release notes can be updated on GitHub manually.
4040

41-
BUILD_VERSION can be used to override the version specified in
42-
version/CURRENT_VERSION. This variable should be used to avoid changing
43-
the version for every single beta/rc release.
44-
45-
BUILD_VERSION shouln't be used to override the version for actual
41+
BUILD_VERSION will not override the version for actual
4642
releases (1.0, 1.0.1, 1.1.0 and so on).
4743

48-
Automated nightly releases use the version from version/CURRENT_VERSION.
49-
These nightly releases also append a timestamp to the version found in
50-
that file.
51-
5244
The release process can be found below.
5345

5446
1. Check out the right branch and the right commit. This is necessary
@@ -61,20 +53,16 @@ release isn't made from the HEAD of master.
6153
git push origin 1.0.1
6254
```
6355

64-
3. Write down the BUILD_VERSION or update version/CURRENT_VERSION. This
65-
will be needed for the next steps. Please refer to the explanation
66-
related to BUILD_VERSION and version/CURRENT_VERSION above.
56+
3. Update version/CURRENT_VERSION. This will be needed for the next steps.
6757

6858
4. Make sure GITHUB_USER and GITHUB_TOKEN variables are exported in your environment.
6959

7060
5. Make the release to GitHub.
7161
```
72-
# BUILD_VERSION is used to override version/CURRENT_VERSION
73-
OLD_VERSION=1.1.0-beta.1 BUILD_VERSION=1.1.0-beta.2 make release
62+
OLD_VERSION=1.1.0-beta.1 make release
7463
```
7564

7665
```
77-
# version/CURRENT_VERSION is used for a new stable release
7866
# version/CURRENT_VERSION is 1.1.1
7967
OLD_VERSION=1.1.0 make release
8068
```

install/v2plugin/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ RUN mkdir -p /run/docker/plugins /etc/openvswitch /var/run/contiv/log \
1010
&& wget https://github.com/andyshinn/alpine-pkg-glibc/releases/download/2.23-r1/glibc-2.23-r1.apk \
1111
&& apk --no-cache add glibc-2.23-r1.apk
1212

13-
COPY netplugin netmaster netctl startcontiv.sh /
13+
# copy in binaries and scripts
14+
ARG TAR_FILE
15+
ADD ${TAR_FILE} /
16+
COPY startcontiv.sh /
1417

18+
# this container is never run, it is exported for docker to run as a plugin,
19+
# the startcontiv.sh script and the netplugin binaries are copied into the
20+
# plugin's rootfs after export, this avoids copying into and out of container
1521
ENTRYPOINT ["/startcontiv.sh"]

0 commit comments

Comments
 (0)