2016-12-08 04:52:45 +03:00
|
|
|
# Source files common to all targets.
|
|
|
|
COREFILES = \
|
2016-10-07 02:34:47 +03:00
|
|
|
$(wildcard common/*.go) \
|
|
|
|
$(wildcard ebtables/*.go) \
|
|
|
|
$(wildcard ipam/*.go) \
|
|
|
|
$(wildcard log/*.go) \
|
|
|
|
$(wildcard netlink/*.go) \
|
|
|
|
$(wildcard network/*.go) \
|
2017-01-21 03:21:41 +03:00
|
|
|
$(wildcard platform/*.go) \
|
2016-10-07 02:34:47 +03:00
|
|
|
$(wildcard store/*.go)
|
|
|
|
|
2016-12-08 04:52:45 +03:00
|
|
|
# Source files for building CNM plugin.
|
|
|
|
CNMFILES = \
|
|
|
|
$(wildcard cnm/*.go) \
|
|
|
|
$(wildcard cnm/ipam/*.go) \
|
|
|
|
$(wildcard cnm/network/*.go) \
|
|
|
|
$(wildcard cnm/plugin/*.go) \
|
|
|
|
$(COREFILES)
|
|
|
|
|
|
|
|
# Source files for building CNI plugin.
|
|
|
|
CNIFILES = \
|
|
|
|
$(wildcard cni/*.go) \
|
|
|
|
$(wildcard cni/ipam/*.go) \
|
2017-01-20 03:37:57 +03:00
|
|
|
$(wildcard cni/ipam/plugin/*.go) \
|
2016-12-08 04:52:45 +03:00
|
|
|
$(wildcard cni/network/*.go) \
|
2017-01-20 03:37:57 +03:00
|
|
|
$(wildcard cni/network/plugin/*.go) \
|
2016-12-08 04:52:45 +03:00
|
|
|
$(COREFILES)
|
|
|
|
|
2018-02-22 23:57:03 +03:00
|
|
|
CNSFILES = \
|
|
|
|
$(wildcard cns/*.go) \
|
2018-07-07 02:08:36 +03:00
|
|
|
$(wildcard cns/cnsclient/*.go) \
|
2018-02-22 23:57:03 +03:00
|
|
|
$(wildcard cns/common/*.go) \
|
2018-02-24 01:36:12 +03:00
|
|
|
$(wildcard cns/dockerclient/*.go) \
|
|
|
|
$(wildcard cns/imdsclient/*.go) \
|
|
|
|
$(wildcard cns/ipamclient/*.go) \
|
|
|
|
$(wildcard cns/restserver/*.go) \
|
|
|
|
$(wildcard cns/routes/*.go) \
|
|
|
|
$(wildcard cns/service/*.go) \
|
2018-02-22 23:57:03 +03:00
|
|
|
$(COREFILES) \
|
|
|
|
$(CNMFILES)
|
|
|
|
|
2018-07-20 00:23:11 +03:00
|
|
|
NPMFILES = \
|
|
|
|
$(wildcard npm/*.go) \
|
|
|
|
$(wildcard npm/ipsm/*.go) \
|
|
|
|
$(wildcard npm/iptm/*.go) \
|
|
|
|
$(wildcard npm/util/*.go) \
|
|
|
|
$(wildcard npm/plugin/*.go) \
|
|
|
|
$(COREFILES)
|
|
|
|
|
2017-03-11 03:49:07 +03:00
|
|
|
# Build defaults.
|
|
|
|
GOOS ?= linux
|
|
|
|
GOARCH ?= amd64
|
|
|
|
|
|
|
|
# Build directories.
|
2017-05-06 04:12:40 +03:00
|
|
|
CNM_DIR = cnm/plugin
|
2017-01-20 03:37:57 +03:00
|
|
|
CNI_NET_DIR = cni/network/plugin
|
|
|
|
CNI_IPAM_DIR = cni/ipam/plugin
|
2018-02-22 23:57:03 +03:00
|
|
|
CNS_DIR = cns/service
|
2018-07-20 00:23:11 +03:00
|
|
|
NPM_DIR = npm/plugin
|
2017-02-21 23:18:11 +03:00
|
|
|
OUTPUT_DIR = output
|
|
|
|
BUILD_DIR = $(OUTPUT_DIR)/$(GOOS)_$(GOARCH)
|
2017-05-06 04:12:40 +03:00
|
|
|
CNM_BUILD_DIR = $(BUILD_DIR)/cnm
|
|
|
|
CNI_BUILD_DIR = $(BUILD_DIR)/cni
|
2018-07-07 02:08:36 +03:00
|
|
|
CNI_MULTITENANCY_BUILD_DIR = $(BUILD_DIR)/cni-multitenancy
|
2018-02-22 23:57:03 +03:00
|
|
|
CNS_BUILD_DIR = $(BUILD_DIR)/cns
|
2018-07-20 00:23:11 +03:00
|
|
|
NPM_BUILD_DIR = $(BUILD_DIR)/npm
|
2017-01-05 03:21:14 +03:00
|
|
|
|
2017-01-12 05:05:54 +03:00
|
|
|
# Containerized build parameters.
|
2017-01-05 03:21:14 +03:00
|
|
|
BUILD_CONTAINER_IMAGE = acn-build
|
2017-01-12 05:05:54 +03:00
|
|
|
BUILD_CONTAINER_NAME = acn-builder
|
|
|
|
BUILD_CONTAINER_REPO_PATH = /go/src/github.com/Azure/azure-container-networking
|
2017-01-05 03:21:14 +03:00
|
|
|
BUILD_USER ?= $(shell id -u)
|
2016-10-07 02:34:47 +03:00
|
|
|
|
2017-06-29 22:01:28 +03:00
|
|
|
# Target OS specific parameters.
|
|
|
|
ifeq ($(GOOS),linux)
|
|
|
|
# Linux.
|
|
|
|
ARCHIVE_CMD = tar -czvf
|
|
|
|
ARCHIVE_EXT = tgz
|
|
|
|
else
|
|
|
|
# Windows.
|
|
|
|
ARCHIVE_CMD = zip -9lq
|
|
|
|
ARCHIVE_EXT = zip
|
|
|
|
EXE_EXT = .exe
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Archive file names.
|
|
|
|
CNM_ARCHIVE_NAME = azure-vnet-cnm-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
|
|
|
|
CNI_ARCHIVE_NAME = azure-vnet-cni-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
|
2018-07-07 02:08:36 +03:00
|
|
|
CNI_MULTITENANCY_ARCHIVE_NAME = azure-vnet-cni-multitenancy-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
|
2018-02-22 23:57:03 +03:00
|
|
|
CNS_ARCHIVE_NAME = azure-cns-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
|
2018-07-20 02:06:11 +03:00
|
|
|
NPM_ARCHIVE_NAME = azure-npm-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
|
2017-03-30 06:42:35 +03:00
|
|
|
|
|
|
|
# Docker libnetwork (CNM) plugin v2 image parameters.
|
2017-05-20 02:31:08 +03:00
|
|
|
CNM_PLUGIN_IMAGE ?= microsoft/azure-vnet-plugin
|
2017-05-06 04:12:40 +03:00
|
|
|
CNM_PLUGIN_ROOTFS = azure-vnet-plugin-rootfs
|
2017-01-07 04:36:02 +03:00
|
|
|
|
2018-07-20 00:23:11 +03:00
|
|
|
# Azure network policy manager parameters.
|
|
|
|
AZURE_NPM_IMAGE = containernetworking/azure-npm
|
|
|
|
|
2016-10-07 02:34:47 +03:00
|
|
|
VERSION ?= $(shell git describe --tags --always --dirty)
|
2018-07-20 00:23:11 +03:00
|
|
|
AZURE_NPM_VERSION = VERSION
|
2016-10-07 02:34:47 +03:00
|
|
|
|
2017-02-21 23:18:11 +03:00
|
|
|
ENSURE_OUTPUT_DIR_EXISTS := $(shell mkdir -p $(OUTPUT_DIR))
|
2016-10-12 01:53:41 +03:00
|
|
|
|
2016-10-07 02:34:47 +03:00
|
|
|
# Shorthand target names for convenience.
|
2017-06-29 22:01:28 +03:00
|
|
|
azure-cnm-plugin: $(CNM_BUILD_DIR)/azure-vnet-plugin$(EXE_EXT) cnm-archive
|
|
|
|
azure-vnet: $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT)
|
|
|
|
azure-vnet-ipam: $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT)
|
|
|
|
azure-cni-plugin: azure-vnet azure-vnet-ipam cni-archive
|
2018-07-20 00:23:11 +03:00
|
|
|
azure-cns: $(CNS_BUILD_DIR)/azure-cns$(EXE_EXT) cns-archive
|
2018-07-20 04:20:01 +03:00
|
|
|
# Azure-NPM only supports Linux for now.
|
|
|
|
ifeq ($(GOOS),linux)
|
2018-07-20 02:06:11 +03:00
|
|
|
azure-npm: $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT) npm-archive
|
2018-07-20 04:20:01 +03:00
|
|
|
endif
|
2018-07-20 00:23:11 +03:00
|
|
|
|
2018-07-20 04:20:01 +03:00
|
|
|
ifeq ($(GOOS),linux)
|
2018-07-20 00:23:11 +03:00
|
|
|
all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns azure-npm
|
2018-07-20 04:20:01 +03:00
|
|
|
else
|
|
|
|
all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns
|
|
|
|
endif
|
2016-10-07 02:34:47 +03:00
|
|
|
|
|
|
|
# Clean all build artifacts.
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2017-02-21 23:18:11 +03:00
|
|
|
rm -rf $(OUTPUT_DIR)
|
2016-10-07 02:34:47 +03:00
|
|
|
|
|
|
|
# Build the Azure CNM plugin.
|
2017-06-29 22:01:28 +03:00
|
|
|
$(CNM_BUILD_DIR)/azure-vnet-plugin$(EXE_EXT): $(CNMFILES)
|
|
|
|
go build -v -o $(CNM_BUILD_DIR)/azure-vnet-plugin$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(CNM_DIR)/*.go
|
2016-10-12 01:53:41 +03:00
|
|
|
|
2017-01-20 03:37:57 +03:00
|
|
|
# Build the Azure CNI network plugin.
|
2017-06-29 22:01:28 +03:00
|
|
|
$(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT): $(CNIFILES)
|
|
|
|
go build -v -o $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(CNI_NET_DIR)/*.go
|
2017-01-20 03:37:57 +03:00
|
|
|
|
|
|
|
# Build the Azure CNI IPAM plugin.
|
2017-06-29 22:01:28 +03:00
|
|
|
$(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT): $(CNIFILES)
|
|
|
|
go build -v -o $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(CNI_IPAM_DIR)/*.go
|
2016-10-07 02:34:47 +03:00
|
|
|
|
2018-02-22 23:57:03 +03:00
|
|
|
# Build the Azure CNS Service.
|
|
|
|
$(CNS_BUILD_DIR)/azure-cns$(EXE_EXT): $(CNSFILES)
|
|
|
|
go build -v -o $(CNS_BUILD_DIR)/azure-cns$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(CNS_DIR)/*.go
|
|
|
|
|
2018-07-20 00:23:11 +03:00
|
|
|
# Build the Azure NPM plugin.
|
2018-07-20 04:20:01 +03:00
|
|
|
$(NPM_BUILD_DIR)/azure-npm$(EXE_EXT): $(NPMFILES)
|
|
|
|
go build -v -o $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(NPM_DIR)/*.go
|
2018-07-20 00:23:11 +03:00
|
|
|
|
2017-01-05 03:21:14 +03:00
|
|
|
# Build all binaries in a container.
|
2017-02-21 23:18:11 +03:00
|
|
|
.PHONY: all-binaries-containerized
|
|
|
|
all-binaries-containerized:
|
2017-01-12 01:22:51 +03:00
|
|
|
pwd && ls -l
|
2017-01-05 03:21:14 +03:00
|
|
|
docker build -f Dockerfile.build -t $(BUILD_CONTAINER_IMAGE):$(VERSION) .
|
2017-01-12 05:05:54 +03:00
|
|
|
docker run --name $(BUILD_CONTAINER_NAME) \
|
2017-01-05 03:21:14 +03:00
|
|
|
$(BUILD_CONTAINER_IMAGE):$(VERSION) \
|
|
|
|
bash -c '\
|
2017-01-12 01:22:51 +03:00
|
|
|
pwd && ls -l && \
|
2017-02-21 23:18:11 +03:00
|
|
|
export GOOS=$(GOOS) && \
|
|
|
|
export GOARCH=$(GOARCH) && \
|
2017-01-05 03:21:14 +03:00
|
|
|
make all-binaries && \
|
2017-02-21 23:18:11 +03:00
|
|
|
chown -R $(BUILD_USER):$(BUILD_USER) $(BUILD_DIR) \
|
2017-01-05 03:21:14 +03:00
|
|
|
'
|
2017-02-21 23:18:11 +03:00
|
|
|
docker cp $(BUILD_CONTAINER_NAME):$(BUILD_CONTAINER_REPO_PATH)/$(BUILD_DIR) $(OUTPUT_DIR)
|
2017-01-12 05:05:54 +03:00
|
|
|
docker rm $(BUILD_CONTAINER_NAME)
|
|
|
|
docker rmi $(BUILD_CONTAINER_IMAGE):$(VERSION)
|
2017-01-05 03:21:14 +03:00
|
|
|
|
2017-01-07 04:36:02 +03:00
|
|
|
# Build the Azure CNM plugin image, installable with "docker plugin install".
|
2017-05-06 04:12:40 +03:00
|
|
|
.PHONY: azure-vnet-plugin-image
|
|
|
|
azure-vnet-plugin-image: azure-cnm-plugin
|
2017-01-07 04:36:02 +03:00
|
|
|
# Build the plugin image, keeping any old image during build for cache, but remove it afterwards.
|
|
|
|
docker images -q $(CNM_PLUGIN_ROOTFS):$(VERSION) > cid
|
2017-02-21 23:18:11 +03:00
|
|
|
docker build \
|
|
|
|
-f Dockerfile.cnm \
|
|
|
|
-t $(CNM_PLUGIN_ROOTFS):$(VERSION) \
|
2017-05-06 04:12:40 +03:00
|
|
|
--build-arg CNM_BUILD_DIR=$(CNM_BUILD_DIR) \
|
2017-02-21 23:18:11 +03:00
|
|
|
.
|
2017-01-07 04:36:02 +03:00
|
|
|
$(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`)
|
2017-02-21 23:18:11 +03:00
|
|
|
mkdir -p $(OUTPUT_DIR)/$(CID)/rootfs
|
|
|
|
docker export $(CID) | tar -x -C $(OUTPUT_DIR)/$(CID)/rootfs
|
2017-01-07 04:36:02 +03:00
|
|
|
docker rm -vf $(CID)
|
|
|
|
|
|
|
|
# Copy the plugin configuration and set ownership.
|
2017-02-21 23:18:11 +03:00
|
|
|
cp cnm/config.json $(OUTPUT_DIR)/$(CID)
|
|
|
|
chgrp -R docker $(OUTPUT_DIR)/$(CID)
|
2017-01-07 04:36:02 +03:00
|
|
|
|
|
|
|
# Create the plugin.
|
|
|
|
docker plugin rm $(CNM_PLUGIN_IMAGE):$(VERSION) || true
|
2017-02-21 23:18:11 +03:00
|
|
|
docker plugin create $(CNM_PLUGIN_IMAGE):$(VERSION) $(OUTPUT_DIR)/$(CID)
|
2017-01-07 04:36:02 +03:00
|
|
|
|
|
|
|
# Cleanup temporary files.
|
2017-02-21 23:18:11 +03:00
|
|
|
rm -rf $(OUTPUT_DIR)/$(CID)
|
2017-01-07 04:36:02 +03:00
|
|
|
rm cid
|
|
|
|
|
|
|
|
# Publish the Azure CNM plugin image to a Docker registry.
|
2017-05-06 04:12:40 +03:00
|
|
|
.PHONY: publish-azure-vnet-plugin-image
|
|
|
|
publish-azure-vnet-plugin-image:
|
2017-01-07 04:36:02 +03:00
|
|
|
docker plugin push $(CNM_PLUGIN_IMAGE):$(VERSION)
|
2017-02-21 23:18:11 +03:00
|
|
|
|
2018-07-20 00:23:11 +03:00
|
|
|
# Build the Azure NPM image.
|
|
|
|
.PHONY: azure-npm-image
|
|
|
|
azure-npm-image: azure-npm
|
|
|
|
# Build the plugin image.
|
|
|
|
docker build \
|
|
|
|
-f npm/Dockerfile \
|
|
|
|
-t $(AZURE_NPM_IMAGE):$(AZURE_NPM_VERSION) \
|
|
|
|
--build-arg NPM_BUILD_DIR=$(NPM_BUILD_DIR) \
|
|
|
|
.
|
|
|
|
|
|
|
|
# Publish the Azure NPM image to a Docker registry
|
|
|
|
.PHONY: publish-azure-npm-image
|
|
|
|
publish-azure-npm-image:
|
|
|
|
docker push $(AZURE_NPM_IMAGE):$(AZURE_NPM_VERSION)
|
|
|
|
|
2017-06-29 22:01:28 +03:00
|
|
|
# Create a CNI archive for the target platform.
|
|
|
|
.PHONY: cni-archive
|
|
|
|
cni-archive:
|
2018-01-31 03:54:52 +03:00
|
|
|
cp cni/azure-$(GOOS).conflist $(CNI_BUILD_DIR)/10-azure.conflist
|
2017-06-29 22:01:28 +03:00
|
|
|
chmod 0755 $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT)
|
2018-01-12 02:53:09 +03:00
|
|
|
cd $(CNI_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) 10-azure.conflist
|
2017-06-29 22:01:28 +03:00
|
|
|
chown $(BUILD_USER):$(BUILD_USER) $(CNI_BUILD_DIR)/$(CNI_ARCHIVE_NAME)
|
2018-07-07 02:08:36 +03:00
|
|
|
mkdir -p $(CNI_MULTITENANCY_BUILD_DIR)
|
|
|
|
cp cni/azure-$(GOOS)-multitenancy.conflist $(CNI_MULTITENANCY_BUILD_DIR)/10-azure.conflist
|
|
|
|
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_MULTITENANCY_BUILD_DIR)
|
|
|
|
chmod 0755 $(CNI_MULTITENANCY_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_MULTITENANCY_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT)
|
|
|
|
cd $(CNI_MULTITENANCY_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_MULTITENANCY_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) 10-azure.conflist
|
|
|
|
chown $(BUILD_USER):$(BUILD_USER) $(CNI_MULTITENANCY_BUILD_DIR)/$(CNI_MULTITENANCY_ARCHIVE_NAME)
|
2017-06-29 22:01:28 +03:00
|
|
|
|
|
|
|
# Create a CNM archive for the target platform.
|
|
|
|
.PHONY: cnm-archive
|
|
|
|
cnm-archive:
|
|
|
|
chmod 0755 $(CNM_BUILD_DIR)/azure-vnet-plugin$(EXE_EXT)
|
|
|
|
cd $(CNM_BUILD_DIR) && $(ARCHIVE_CMD) $(CNM_ARCHIVE_NAME) azure-vnet-plugin$(EXE_EXT)
|
|
|
|
chown $(BUILD_USER):$(BUILD_USER) $(CNM_BUILD_DIR)/$(CNM_ARCHIVE_NAME)
|
2018-02-22 23:57:03 +03:00
|
|
|
|
|
|
|
# Create a CNS archive for the target platform.
|
|
|
|
.PHONY: cns-archive
|
|
|
|
cns-archive:
|
|
|
|
chmod 0755 $(CNS_BUILD_DIR)/azure-cns$(EXE_EXT)
|
|
|
|
cd $(CNS_BUILD_DIR) && $(ARCHIVE_CMD) $(CNS_ARCHIVE_NAME) azure-cns$(EXE_EXT)
|
2018-07-20 02:06:11 +03:00
|
|
|
chown $(BUILD_USER):$(BUILD_USER) $(CNS_BUILD_DIR)/$(CNS_ARCHIVE_NAME)
|
|
|
|
|
2018-07-20 04:20:01 +03:00
|
|
|
# Create a NPM archive for the target platform. Only Linux is supported for now.
|
2018-07-20 02:06:11 +03:00
|
|
|
.PHONY: npm-archive
|
|
|
|
npm-archive:
|
|
|
|
ifeq ($(GOOS),linux)
|
|
|
|
chmod 0755 $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT)
|
|
|
|
cd $(NPM_BUILD_DIR) && $(ARCHIVE_CMD) $(NPM_ARCHIVE_NAME) azure-npm$(EXE_EXT)
|
|
|
|
chown $(BUILD_USER):$(BUILD_USER) $(NPM_BUILD_DIR)/$(NPM_ARCHIVE_NAME)
|
|
|
|
endif
|