From 5bbd886e6f195c45035f90805236aac81d6a90be Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 6 Jan 2017 18:08:37 +0000 Subject: [PATCH] Build a 'v2' Docker plugin Redirect output to specific log files, because there doesn't seem to be a 'docker logs' for plugins --- .gitignore | 1 + Makefile | 25 ++++++++++++++-- prog/v2-plugin/config.json | 24 ++++++++++++++++ prog/v2-plugin/launch.sh | 58 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 prog/v2-plugin/config.json create mode 100755 prog/v2-plugin/launch.sh diff --git a/.gitignore b/.gitignore index 3a7f66ad..0e410022 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,4 @@ test/coverage.* *qemu-*-static terraform.tfstate terraform.tfstate.backup +prog/plugin-v2/rootfs/ diff --git a/Makefile b/Makefile index cf3bc69e..e3e5f21e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .DEFAULT: all -.PHONY: all exes testrunner update tests lint publish-one-arch $(PUBLISH) clean clean-bin prerequisites build run-smoketests +.PHONY: all exes testrunner update tests lint publish-one-arch $(PUBLISH) clean clean-bin clean-work-dir prerequisites build run-smoketests # If you can use docker without being root, you can do "make SUDO=" SUDO=$(shell docker info >/dev/null 2>&1 || echo "sudo -E") @@ -107,6 +107,7 @@ BUILD_UPTODATE=.build.uptodate WEAVER_UPTODATE=.weaver$(ARCH_EXT).uptodate WEAVEEXEC_UPTODATE=.weaveexec$(ARCH_EXT).uptodate PLUGIN_UPTODATE=.plugin$(ARCH_EXT).uptodate +PLUGINV2_UPTODATE=.pluginv2$(ARCH_EXT).uptodate WEAVEKUBE_UPTODATE=.weavekube$(ARCH_EXT).uptodate WEAVENPC_UPTODATE=.weavenpc$(ARCH_EXT).uptodate WEAVEDB_UPTODATE=.weavedb.uptodate @@ -121,9 +122,12 @@ WEAVEKUBE_IMAGE=$(DOCKERHUB_USER)/weave-kube$(ARCH_EXT) WEAVENPC_IMAGE=$(DOCKERHUB_USER)/weave-npc$(ARCH_EXT) BUILD_IMAGE=weaveworks/weavebuild WEAVEDB_IMAGE=$(DOCKERHUB_USER)/weavedb +PLUGINV2_IMAGE=$(DOCKERHUB_USER)/pluginv2$(ARCH_EXT) IMAGES=$(WEAVER_IMAGE) $(WEAVEEXEC_IMAGE) $(PLUGIN_IMAGE) $(WEAVEKUBE_IMAGE) $(WEAVENPC_IMAGE) $(WEAVEDB_IMAGE) +PLUGINV2_WORK_DIR="prog/plugin-v2/rootfs" + PUBLISH=publish_weave publish_weaveexec publish_plugin publish_weave-kube publish_weave-npc PUSH_ML=push_ml_weave push_ml_weaveexec push_ml_plugin push_ml_weave-kube push_ml_weave-npc @@ -268,6 +272,20 @@ $(PLUGIN_UPTODATE): prog/plugin/Dockerfile.$(DOCKERHUB_USER) $(PLUGIN_EXE) $(WEA $(SUDO) docker build -f prog/plugin/Dockerfile.$(DOCKERHUB_USER) -t $(PLUGIN_IMAGE) prog/plugin touch $@ +# TODO(mp) cleanup! +pluginv2: prog/plugin-v2/launch.sh prog/plugin-v2/config.json $(PLUGIN_UPTODATE) + -$(SUDO) docker rm -f buildpluginv2 + $(SUDO) docker create --name=buildpluginv2 $(PLUGIN_IMAGE) true + rm -rf $(PLUGINV2_WORK_DIR) + mkdir $(PLUGINV2_WORK_DIR) + docker export buildpluginv2 | tar -x -C $(PLUGINV2_WORK_DIR) + docker rm buildpluginv2 + cp prog/plugin-v2/launch.sh $(PLUGINV2_WORK_DIR)/home/weave/launch.sh + -docker plugin disable $(PLUGINV2_IMAGE) + -docker plugin rm $(PLUGINV2_IMAGE) + docker plugin create $(PLUGINV2_IMAGE) prog/plugin-v2 + #touch $@ + $(WEAVEKUBE_UPTODATE): prog/weave-kube/Dockerfile.$(DOCKERHUB_USER) prog/weave-kube/launch.sh $(KUBEPEERS_EXE) $(WEAVER_UPTODATE) cp $(KUBEPEERS_EXE) prog/weave-kube/ $(SUDO) docker build -f prog/weave-kube/Dockerfile.$(DOCKERHUB_USER) -t $(WEAVEKUBE_IMAGE) prog/weave-kube @@ -345,13 +363,16 @@ ifneq ($(UPDATE_LATEST),false) $(MANIFEST_TOOL_EXE) push from-args --platforms $(ML_PLATFORMS) --template $(DOCKERHUB_USER)/$*-ARCH:latest --target $(DOCKERHUB_USER)/$*:latest endif +clean-work-dir: + rm -rf $(PLUGINV2_WORK_DIR) + clean-bin: -$(SUDO) DOCKER_HOST=$(DOCKER_HOST) docker rmi $(IMAGES) find prog -type f -name "Dockerfile.*" -not -name "Dockerfile.template" -print | xargs rm -f find prog -type f -name "*qemu-*" -print | xargs rm -f rm -rf $(EXES) $(IMAGES_UPTODATE) $(WEAVEDB_UPTODATE) weave*.tar.gz $(DOCKER_DISTRIB) prog/weaveexec/docker .pkg -clean: clean-bin +clean: clean-bin clean-work-dir -$(SUDO) DOCKER_HOST=$(DOCKER_HOST) docker rmi $(BUILD_IMAGE) rm -rf test/tls/*.pem test/coverage.* test/coverage $(BUILD_UPTODATE) $(MANIFEST_TOOL_EXE) diff --git a/prog/v2-plugin/config.json b/prog/v2-plugin/config.json new file mode 100644 index 00000000..7aad2c84 --- /dev/null +++ b/prog/v2-plugin/config.json @@ -0,0 +1,24 @@ +{ + "description": "Weave Net plugin for Docker", + "documentation": "https://weave.works", + "entrypoint": [ + "/home/weave/launch.sh" + ], + "interface": { + "socket": "weave.sock", + "types": [ + "docker.networkdriver/1.0" + ] + }, + "linux": { + "capabilities": [ + "CAP_SYS_ADMIN", + "CAP_NET_ADMIN" + ] + }, + "mounts": [], + "network": { + "type": "host" + }, + "workdir": "" +} diff --git a/prog/v2-plugin/launch.sh b/prog/v2-plugin/launch.sh new file mode 100755 index 00000000..ea2608e2 --- /dev/null +++ b/prog/v2-plugin/launch.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +set -e + +# Default if not supplied - same as weave net default +IPALLOC_RANGE=${IPALLOC_RANGE:-10.32.0.0/12} +HTTP_ADDR=${WEAVE_HTTP_ADDR:-127.0.0.1:6784} +STATUS_ADDR=${WEAVE_STATUS_ADDR:-0.0.0.0:6782} +HOST_ROOT=${HOST_ROOT:-/host} +LOG_FILE=/tmp/weaver.log + +echo "Starting launch.sh" >>$LOG_FILE + +# Check if the IP range overlaps anything existing on the host +/usr/bin/weaveutil netcheck $IPALLOC_RANGE weave + +/home/weave/weave --local create-bridge --force >>$LOG_FILE 2>&1 + +BRIDGE_OPTIONS="--datapath=datapath" +if [ "$(/home/weave/weave --local bridge-type)" = "bridge" ]; then + # TODO: Call into weave script to do this + if ! ip link show vethwe-pcap >/dev/null 2>&1; then + ip link add name vethwe-bridge type veth peer name vethwe-pcap + ip link set vethwe-bridge up + ip link set vethwe-pcap up + ip link set vethwe-bridge master weave + fi + BRIDGE_OPTIONS="--iface=vethwe-pcap" +fi + +if [ -z "$IPALLOC_INIT" ]; then + # ideally we would know the peer count + IPALLOC_INIT="consensus" +fi + +/home/weave/weaver $EXTRA_ARGS --port=6783 $BRIDGE_OPTIONS \ + --http-addr=$HTTP_ADDR --status-addr=$STATUS_ADDR --docker-api='' --no-dns \ + --ipalloc-range=$IPALLOC_RANGE \ + --ipalloc-init $IPALLOC_INIT \ + --nickname "$(hostname)" \ + >>$LOG_FILE 2>&1 & +WEAVE_PID=$! + +# Wait for weave process to become responsive +while true; do + curl $HTTP_ADDR/status >/dev/null 2>&1 && break + if ! kill -0 $WEAVE_PID >/dev/null 2>&1; then + echo Weave process has died >&2 + exit 1 + fi + sleep 1 +done + +/home/weave/plugin --meshsocket='' --docker-api='' >/tmp/plugin.log 2>&1 & + +echo "End of launch.sh" >>$LOG_FILE + +wait $WEAVE_PID