@@ -32,6 +32,9 @@ REPO_PATH = /go/src/github.com/Azure/azure-container-networking
3232BUILD_CONTAINER_IMAGE = acn-build
3333BUILD_USER ?= $(shell id -u)
3434
35+ CNM_PLUGIN_IMAGE = ofiliz/azure-cnm-plugin
36+ CNM_PLUGIN_ROOTFS = azure-cnm-plugin-rootfs
37+
3538VERSION ?= $(shell git describe --tags --always --dirty)
3639
3740ENSURE_OUTPUTDIR_EXISTS := $(shell mkdir -p $(OUTPUTDIR ) )
@@ -67,3 +70,35 @@ build-containerized:
6770 chown -R $(BUILD_USER ) :$(BUILD_USER ) $(OUTPUTDIR ) \
6871 '
6972
73+ # Build the Azure CNM plugin image, installable with "docker plugin install".
74+ .PHONY : azure-cnm-plugin-image
75+ azure-cnm-plugin-image : azure-cnm-plugin
76+ # Build the plugin image, keeping any old image during build for cache, but remove it afterwards.
77+ docker images -q $(CNM_PLUGIN_ROOTFS ) :$(VERSION ) > cid
78+ docker build -f Dockerfile.cnm -t $(CNM_PLUGIN_ROOTFS ) :$(VERSION ) .
79+ $(eval CID := `cat cid`)
80+ docker rmi $(CID ) || true
81+
82+ # Create a container using the image and export its rootfs.
83+ docker create $(CNM_PLUGIN_ROOTFS):$(VERSION) > cid
84+ $(eval CID := `cat cid`)
85+ mkdir -p $(OUTPUTDIR)/$(CID)/rootfs
86+ docker export $(CID) | tar -x -C $(OUTPUTDIR)/$(CID)/rootfs
87+ docker rm -vf $(CID)
88+
89+ # Copy the plugin configuration and set ownership.
90+ cp cnm/config.json $(OUTPUTDIR)/$(CID)
91+ chgrp -R docker $(OUTPUTDIR)/$(CID)
92+
93+ # Create the plugin.
94+ docker plugin rm $(CNM_PLUGIN_IMAGE):$(VERSION) || true
95+ docker plugin create $(CNM_PLUGIN_IMAGE):$(VERSION) $(OUTPUTDIR)/$(CID)
96+
97+ # Cleanup temporary files.
98+ rm -rf $(OUTPUTDIR)/$(CID)
99+ rm cid
100+
101+ # Publish the Azure CNM plugin image to a Docker registry.
102+ .PHONY : publish-azure-cnm-plugin-image
103+ publish-azure-cnm-plugin-image :
104+ docker plugin push $(CNM_PLUGIN_IMAGE ) :$(VERSION )
0 commit comments