From 3b25aecac171fab5a926e00acde18560cf323024 Mon Sep 17 00:00:00 2001 From: Onur Filiz Date: Fri, 6 Jan 2017 17:36:02 -0800 Subject: [PATCH 1/2] Added Docker managed plugin support --- Dockerfile.cnm | 13 +++++++++++++ Makefile | 35 +++++++++++++++++++++++++++++++++++ cnm/config.json | 15 +++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 Dockerfile.cnm create mode 100644 cnm/config.json diff --git a/Dockerfile.cnm b/Dockerfile.cnm new file mode 100644 index 0000000000..08cf06942e --- /dev/null +++ b/Dockerfile.cnm @@ -0,0 +1,13 @@ +FROM ubuntu:14.04.3 + +# Install dependencies. +RUN apt-get update && apt-get install -y ebtables + +# Create plugins directory. +RUN mkdir -p /run/docker/plugins + +# Install plugin. +COPY ./out/azure-cnm-plugin /usr/bin +WORKDIR /usr/bin + +CMD ["/usr/bin/azure-cnm-plugin"] diff --git a/Makefile b/Makefile index 0cc43d93a6..4001b0f584 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,9 @@ REPO_PATH = /go/src/github.com/Azure/azure-container-networking BUILD_CONTAINER_IMAGE = acn-build BUILD_USER ?= $(shell id -u) +CNM_PLUGIN_IMAGE = ofiliz/azure-cnm-plugin +CNM_PLUGIN_ROOTFS = azure-cnm-plugin-rootfs + VERSION ?= $(shell git describe --tags --always --dirty) ENSURE_OUTPUTDIR_EXISTS := $(shell mkdir -p $(OUTPUTDIR)) @@ -67,3 +70,35 @@ build-containerized: chown -R $(BUILD_USER):$(BUILD_USER) $(OUTPUTDIR) \ ' +# Build the Azure CNM plugin image, installable with "docker plugin install". +.PHONY: azure-cnm-plugin-image +azure-cnm-plugin-image: azure-cnm-plugin + # Build the plugin image, keeping any old image during build for cache, but remove it afterwards. + docker images -q $(CNM_PLUGIN_ROOTFS):$(VERSION) > cid + docker build -f Dockerfile.cnm -t $(CNM_PLUGIN_ROOTFS):$(VERSION) . + $(eval CID := `cat cid`) + docker rmi $(CID) || true + + # Create a container using the image and export its rootfs. + docker create $(CNM_PLUGIN_ROOTFS):$(VERSION) > cid + $(eval CID := `cat cid`) + mkdir -p $(OUTPUTDIR)/$(CID)/rootfs + docker export $(CID) | tar -x -C $(OUTPUTDIR)/$(CID)/rootfs + docker rm -vf $(CID) + + # Copy the plugin configuration and set ownership. + cp cnm/config.json $(OUTPUTDIR)/$(CID) + chgrp -R docker $(OUTPUTDIR)/$(CID) + + # Create the plugin. + docker plugin rm $(CNM_PLUGIN_IMAGE):$(VERSION) || true + docker plugin create $(CNM_PLUGIN_IMAGE):$(VERSION) $(OUTPUTDIR)/$(CID) + + # Cleanup temporary files. + rm -rf $(OUTPUTDIR)/$(CID) + rm cid + +# Publish the Azure CNM plugin image to a Docker registry. +.PHONY: publish-azure-cnm-plugin-image +publish-azure-cnm-plugin-image: + docker plugin push $(CNM_PLUGIN_IMAGE):$(VERSION) diff --git a/cnm/config.json b/cnm/config.json new file mode 100644 index 0000000000..bb00c07e34 --- /dev/null +++ b/cnm/config.json @@ -0,0 +1,15 @@ +{ + "description": "Azure network plugin", + "documentation": "https://github.com/Azure/azure-container-networking/", + "entrypoint": ["/usr/bin/azure-cnm-plugin"], + "interface": { + "types": ["docker.networkdriver/1.0", "docker.ipamdriver/1.0"], + "socket": "azurenet.sock" + }, + "network": { + "type": "host" + }, + "linux": { + "capabilities": ["CAP_SYS_ADMIN", "CAP_NET_ADMIN"] + } +} From 4342cc1becbf6d4260d0c61eee68ac4974403339 Mon Sep 17 00:00:00 2001 From: Onur Filiz Date: Fri, 6 Jan 2017 17:36:44 -0800 Subject: [PATCH 2/2] Added a sample CNI configuration file --- cni/azure.conf | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 cni/azure.conf diff --git a/cni/azure.conf b/cni/azure.conf new file mode 100644 index 0000000000..d8336fb29d --- /dev/null +++ b/cni/azure.conf @@ -0,0 +1,9 @@ +{ + "cniVersion": "0.2.0", + "name": "azure", + "type": "azure-cni-plugin", + "bridge": "azure0", + "ipam": { + "type": "azure-cni-plugin" + } +}