forked from Azure/azure-container-networking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
384 lines (337 loc) · 14.3 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# Source files common to all targets.
COREFILES = \
$(wildcard common/*.go) \
$(wildcard ebtables/*.go) \
$(wildcard ipam/*.go) \
$(wildcard log/*.go) \
$(wildcard netlink/*.go) \
$(wildcard network/*.go) \
$(wildcard telemetry/*.go) \
$(wildcard aitelemetry/*.go) \
$(wildcard network/epcommon/*.go) \
$(wildcard network/policy/*.go) \
$(wildcard platform/*.go) \
$(wildcard store/*.go) \
$(wildcard ovsctl/*.go) \
$(wildcard network/ovssnat*.go) \
$(wildcard network/ovsinfravnet*.go)
# 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) \
$(wildcard cni/ipam/plugin/*.go) \
$(wildcard cni/network/*.go) \
$(wildcard cni/network/plugin/*.go) \
$(wildcard cni/telemetry/service/*.go) \
$(COREFILES)
CNSFILES = \
$(wildcard cns/*.go) \
$(wildcard cns/cnsclient/*.go) \
$(wildcard cns/common/*.go) \
$(wildcard cns/configuration/*.go) \
$(wildcard cns/dockerclient/*.go) \
$(wildcard cns/imdsclient/*.go) \
$(wildcard cns/ipamclient/*.go) \
$(wildcard cns/hnsclient/*.go) \
$(wildcard cns/logger/*.go) \
$(wildcard cns/nmagentclient/*.go) \
$(wildcard cns/restserver/*.go) \
$(wildcard cns/routes/*.go) \
$(wildcard cns/service/*.go) \
$(wildcard cns/networkcontainers/*.go) \
$(COREFILES) \
$(CNMFILES)
CNMSFILES = \
$(wildcard cnms/*.go) \
$(wildcard cnms/service/*.go) \
$(wildcard cnms/cnmspackage/*.go) \
$(COREFILES)
NPMFILES = \
$(wildcard npm/*.go) \
$(wildcard npm/ipsm/*.go) \
$(wildcard npm/iptm/*.go) \
$(wildcard npm/util/*.go) \
$(wildcard npm/plugin/*.go) \
$(COREFILES)
# Build defaults.
GOOS ?= linux
GOARCH ?= amd64
# Build directories.
ROOT_DIR = $(shell pwd)
CNM_DIR = cnm/plugin
CNI_NET_DIR = cni/network/plugin
CNI_IPAM_DIR = cni/ipam/plugin
CNI_IPAMV6_DIR = cni/ipam/pluginv6
CNI_TELEMETRY_DIR = cni/telemetry/service
TELEMETRY_CONF_DIR = telemetry
CNS_DIR = cns/service
CNMS_DIR = cnms/service
NPM_DIR = npm/plugin
OUTPUT_DIR = output
BUILD_DIR = $(OUTPUT_DIR)/$(GOOS)_$(GOARCH)
CNM_BUILD_DIR = $(BUILD_DIR)/cnm
CNI_BUILD_DIR = $(BUILD_DIR)/cni
CNI_MULTITENANCY_BUILD_DIR = $(BUILD_DIR)/cni-multitenancy
CNS_BUILD_DIR = $(BUILD_DIR)/cns
CNMS_BUILD_DIR = $(BUILD_DIR)/cnms
NPM_BUILD_DIR = $(BUILD_DIR)/npm
NPM_TELEMETRY_DIR = $(NPM_BUILD_DIR)/telemetry
CNI_AI_ID = 5515a1eb-b2bc-406a-98eb-ba462e6f0411
NPM_AI_ID = 014c22bd-4107-459e-8475-67909e96edcb
ACN_PACKAGE_PATH = github.com/Azure/azure-container-networking
# Containerized build parameters.
BUILD_CONTAINER_IMAGE = acn-build
BUILD_CONTAINER_NAME = acn-builder
BUILD_CONTAINER_REPO_PATH = /go/src/github.com/Azure/azure-container-networking
BUILD_USER ?= $(shell id -u)
# 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)
CNI_MULTITENANCY_ARCHIVE_NAME = azure-vnet-cni-multitenancy-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNS_ARCHIVE_NAME = azure-cns-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNMS_ARCHIVE_NAME = azure-cnms-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
NPM_ARCHIVE_NAME = azure-npm-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
NPM_IMAGE_ARCHIVE_NAME = azure-npm-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
TELEMETRY_IMAGE_ARCHIVE_NAME = azure-vnet-telemetry-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNS_IMAGE_ARCHIVE_NAME = azure-cns-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
# Docker libnetwork (CNM) plugin v2 image parameters.
CNM_PLUGIN_IMAGE ?= microsoft/azure-vnet-plugin
CNM_PLUGIN_ROOTFS = azure-vnet-plugin-rootfs
# Azure network policy manager parameters.
AZURE_NPM_IMAGE = containernetworking.azurecr.io/public/containernetworking/azure-npm
# Azure vnet telemetry image parameters.
AZURE_VNET_TELEMETRY_IMAGE = containernetworking.azurecr.io/public/containernetworking/azure-vnet-telemetry
# Azure container networking service image paramters.
AZURE_CNS_IMAGE = containernetworking.azurecr.io/public/containernetworking/azure-cns
VERSION ?= $(shell git describe --tags --always --dirty)
CNS_AI_ID = ce672799-8f08-4235-8c12-08563dc2acef
cnsaipath=github.com/Azure/azure-container-networking/cns/logger.aiMetadata
ENSURE_OUTPUT_DIR_EXISTS := $(shell mkdir -p $(OUTPUT_DIR))
# Shorthand target names for convenience.
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-vnet-ipamv6: $(CNI_BUILD_DIR)/azure-vnet-ipamv6$(EXE_EXT)
azure-cni-plugin: azure-vnet azure-vnet-ipam azure-vnet-ipamv6 azure-vnet-telemetry cni-archive
azure-cns: $(CNS_BUILD_DIR)/azure-cns$(EXE_EXT) cns-archive
azure-vnet-telemetry: $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT)
# Azure-NPM only supports Linux for now.
ifeq ($(GOOS),linux)
azure-cnms: $(CNMS_BUILD_DIR)/azure-cnms$(EXE_EXT) cnms-archive
azure-npm: $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT) npm-archive
endif
ifeq ($(GOOS),linux)
all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns azure-cnms azure-npm
else
all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns
endif
ifeq ($(GOOS),linux)
all-images: azure-npm-image azure-vnet-telemetry-image
else
all-images:
@echo "Nothing to build. Skip."
endif
# Clean all build artifacts.
.PHONY: clean
clean:
rm -rf $(OUTPUT_DIR)
# Build the Azure CNM plugin.
$(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
# Build the Azure CNI network plugin.
$(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
# Build the Azure CNI IPAM plugin.
$(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
# Build the Azure CNI IPAMV6 plugin.
$(CNI_BUILD_DIR)/azure-vnet-ipamv6$(EXE_EXT): $(CNIFILES)
go build -v -o $(CNI_BUILD_DIR)/azure-vnet-ipamv6$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(CNI_IPAMV6_DIR)/*.go
# Build the Azure CNI telemetry plugin.
$(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT): $(CNIFILES)
go build -v -o $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -X $(ACN_PACKAGE_PATH)/telemetry.aiMetadata=$(CNI_AI_ID) -s -w" $(CNI_TELEMETRY_DIR)/*.go
# 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) -X $(cnsaipath)=$(CNS_AI_ID) -s -w" $(CNS_DIR)/*.go
# Build the Azure CNMS Service.
$(CNMS_BUILD_DIR)/azure-cnms$(EXE_EXT): $(CNMSFILES)
go build -v -o $(CNMS_BUILD_DIR)/azure-cnms$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(CNMS_DIR)/*.go
# Build the Azure NPM plugin.
$(NPM_BUILD_DIR)/azure-npm$(EXE_EXT): $(NPMFILES)
go build -v -o $(NPM_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(CNI_TELEMETRY_DIR)/*.go
go build -v -o $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -X $(ACN_PACKAGE_PATH)/npm.aiMetadata=$(NPM_AI_ID) -s -w" $(NPM_DIR)/*.go
# Build all binaries in a container.
.PHONY: all-containerized
all-containerized:
pwd && ls -l
docker build -f Dockerfile.build -t $(BUILD_CONTAINER_IMAGE):$(VERSION) .
docker run --name $(BUILD_CONTAINER_NAME) \
-v /usr/bin/docker:/usr/bin/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
$(BUILD_CONTAINER_IMAGE):$(VERSION) \
bash -c '\
pwd && ls -l && \
export GOOS=$(GOOS) && \
export GOARCH=$(GOARCH) && \
make all-binaries && \
make all-images && \
chown -R $(BUILD_USER):$(BUILD_USER) $(BUILD_DIR) \
'
docker cp $(BUILD_CONTAINER_NAME):$(BUILD_CONTAINER_REPO_PATH)/$(BUILD_DIR) $(OUTPUT_DIR)
docker rm $(BUILD_CONTAINER_NAME)
docker rmi $(BUILD_CONTAINER_IMAGE):$(VERSION)
# Build the Azure CNM plugin image, installable with "docker plugin install".
.PHONY: azure-vnet-plugin-image
azure-vnet-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) \
--build-arg CNM_BUILD_DIR=$(CNM_BUILD_DIR) \
.
$(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 $(OUTPUT_DIR)/$(CID)/rootfs
docker export $(CID) | tar -x -C $(OUTPUT_DIR)/$(CID)/rootfs
docker rm -vf $(CID)
# Copy the plugin configuration and set ownership.
cp cnm/config.json $(OUTPUT_DIR)/$(CID)
chgrp -R docker $(OUTPUT_DIR)/$(CID)
# Create the plugin.
docker plugin rm $(CNM_PLUGIN_IMAGE):$(VERSION) || true
docker plugin create $(CNM_PLUGIN_IMAGE):$(VERSION) $(OUTPUT_DIR)/$(CID)
# Cleanup temporary files.
rm -rf $(OUTPUT_DIR)/$(CID)
rm cid
# Publish the Azure CNM plugin image to a Docker registry.
.PHONY: publish-azure-vnet-plugin-image
publish-azure-vnet-plugin-image:
docker plugin push $(CNM_PLUGIN_IMAGE):$(VERSION)
# Build the Azure NPM image.
.PHONY: azure-npm-image
azure-npm-image: azure-npm
ifeq ($(GOOS),linux)
docker build \
-f npm/Dockerfile \
-t $(AZURE_NPM_IMAGE):$(VERSION) \
--build-arg NPM_BUILD_DIR=$(NPM_BUILD_DIR) \
.
docker save $(AZURE_NPM_IMAGE):$(VERSION) | gzip -c > $(NPM_BUILD_DIR)/$(NPM_IMAGE_ARCHIVE_NAME)
endif
# Publish the Azure NPM image to a Docker registry
.PHONY: publish-azure-npm-image
publish-azure-npm-image:
docker push $(AZURE_NPM_IMAGE):$(VERSION)
# Build the Azure vnet telemetry image
.PHONY: azure-vnet-telemetry-image
azure-vnet-telemetry-image: azure-vnet-telemetry
docker build \
-f cni/telemetry/Dockerfile \
-t $(AZURE_VNET_TELEMETRY_IMAGE):$(VERSION) \
--build-arg TELEMETRY_BUILD_DIR=$(NPM_BUILD_DIR) \
--build-arg TELEMETRY_CONF_DIR=$(TELEMETRY_CONF_DIR) \
.
docker save $(AZURE_VNET_TELEMETRY_IMAGE):$(VERSION) | gzip -c > $(NPM_BUILD_DIR)/$(TELEMETRY_IMAGE_ARCHIVE_NAME)
# Publish the Azure vnet telemetry image to a Docker registry
.PHONY: publish-azure-vnet-telemetry-image
publish-azure-vnet-telemetry-image:
docker push $(AZURE_VNET_TELEMETRY_IMAGE):$(VERSION)
# Build the Azure CNS image.
.PHONY: azure-cns-image
azure-cns-image: azure-cns
ifeq ($(GOOS),linux)
docker build \
-f cns/Dockerfile \
-t $(AZURE_CNS_IMAGE):$(VERSION) \
--build-arg CNS_BUILD_ARCHIVE=$(CNS_BUILD_DIR)/$(CNS_IMAGE_ARCHIVE_NAME) \
.
docker save $(AZURE_CNS_IMAGE):$(VERSION) | gzip -c > $(CNS_BUILD_DIR)/$(CNS_IMAGE_ARCHIVE_NAME)
endif
# Publish the Azure NPM image to a Docker registry
.PHONY: publish-azure-cns-image
publish-azure-cns-image:
docker push $(AZURE_CNS_IMAGE):$(VERSION)
# Create a CNI archive for the target platform.
.PHONY: cni-archive
cni-archive:
cp cni/azure-$(GOOS).conflist $(CNI_BUILD_DIR)/10-azure.conflist
cp telemetry/azure-vnet-telemetry.config $(CNI_BUILD_DIR)/azure-vnet-telemetry.config
chmod 0755 $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipamv6$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT)
cd $(CNI_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) azure-vnet-ipamv6$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config
chown $(BUILD_USER):$(BUILD_USER) $(CNI_BUILD_DIR)/$(CNI_ARCHIVE_NAME)
mkdir -p $(CNI_MULTITENANCY_BUILD_DIR)
cp cni/azure-$(GOOS)-multitenancy.conflist $(CNI_MULTITENANCY_BUILD_DIR)/10-azure.conflist
cp telemetry/azure-vnet-telemetry.config $(CNI_MULTITENANCY_BUILD_DIR)/azure-vnet-telemetry.config
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-telemetry$(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) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config
chown $(BUILD_USER):$(BUILD_USER) $(CNI_MULTITENANCY_BUILD_DIR)/$(CNI_MULTITENANCY_ARCHIVE_NAME)
# 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)
# Create a CNS archive for the target platform.
.PHONY: cns-archive
cns-archive:
cp cns/configuration/cns_config.json $(CNS_BUILD_DIR)/cns_config.json
chmod 0755 $(CNS_BUILD_DIR)/azure-cns$(EXE_EXT)
cd $(CNS_BUILD_DIR) && $(ARCHIVE_CMD) $(CNS_ARCHIVE_NAME) azure-cns$(EXE_EXT) cns_config.json
chown $(BUILD_USER):$(BUILD_USER) $(CNS_BUILD_DIR)/$(CNS_ARCHIVE_NAME)
# Create a CNMS archive for the target platform. Only Linux is supported for now.
.PHONY: cnms-archive
cnms-archive:
ifeq ($(GOOS),linux)
chmod 0755 $(CNMS_BUILD_DIR)/azure-cnms$(EXE_EXT)
cd $(CNMS_BUILD_DIR) && $(ARCHIVE_CMD) $(CNMS_ARCHIVE_NAME) azure-cnms$(EXE_EXT)
chown $(BUILD_USER):$(BUILD_USER) $(CNMS_BUILD_DIR)/$(CNMS_ARCHIVE_NAME)
endif
# Create a NPM archive for the target platform. Only Linux is supported for now.
.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
# run all tests
.PHONY: test-all
test-all:
go test -v -race -covermode atomic -coverprofile=coverage.out \
./ipam/ \
./log/ \
./netlink/ \
./network/ \
./store/ \
./telemetry/ \
./aitelemetry/ \
./cnm/network/ \
./cni/ipam/ \
./cns/ipamclient/ \
./cns/requestcontroller/kubecontroller/ \
./cnms/service/ \
./npm/iptm/ \
./npm/ipsm/