-
Notifications
You must be signed in to change notification settings - Fork 45
/
Makefile
204 lines (180 loc) · 7.23 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
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
# Build settings.
GOOS ?= linux
GOARCH ?= amd64
CGO_ENABLED = 0
# Build directories.
CUR_DIR = $(shell pwd)
BUILD_ROOT_DIR = build
BUILD_DIR = $(BUILD_ROOT_DIR)/$(GOOS)_$(GOARCH)
CREATE_BUILD_ROOT_DIR := $(shell mkdir -p $(BUILD_DIR))
# Git repo version.
GIT_TAG ?= $(shell git describe --tags --always --dirty)
GIT_SHORT_HASH ?= $(shell git rev-parse --short HEAD 2> /dev/null)
ifeq ($(strip $(GIT_SHORT_HASH)),)
GIT_SHORT_HASH=unknown
endif
# Build version.
BUILD_VERSION ?= $(shell echo $(GIT_TAG) | sed 's/^v\([0-9]\)/\1/')
BUILD_TIMESTAMP = $(shell date +%Y-%m-%dT%H:%M:%S%z)
BUILD_RELEASE_FLAGS = -a
BUILD_FLAGS ?= $(BUILD_RELEASE_FLAGS)
LINKER_FLAGS = "\
-X github.com/aws/amazon-vpc-cni-plugins/version.Version=$(BUILD_VERSION) \
-X github.com/aws/amazon-vpc-cni-plugins/version.GitShortHash=$(GIT_SHORT_HASH) \
-X github.com/aws/amazon-vpc-cni-plugins/version.BuildTime=$(BUILD_TIMESTAMP) \
-s"
# Source files.
COMMON_SOURCE_FILES = $(wildcard capabilities/* cni/* logger/* network/*/* version/*)
VPC_ENI_PLUGIN_SOURCE_FILES = $(shell find plugins/vpc-eni -type f)
VPC_BRANCH_ENI_PLUGIN_SOURCE_FILES = $(shell find plugins/vpc-branch-eni -type f)
VPC_BRIDGE_PLUGIN_SOURCE_FILES = $(shell find plugins/vpc-bridge -type f)
VPC_TUNNEL_PLUGIN_SOURCE_FILES = $(shell find plugins/vpc-tunnel -type f)
AWS_APPMESH_PLUGIN_SOURCE_FILES = $(shell find plugins/aws-appmesh -type f)
ECS_SERVICECONNECT_PLUGIN_SOURCE_FILES = $(shell find plugins/ecs-serviceconnect -type f)
NETNSEXEC_TOOL_SOURCE_FILES = $(shell find tools/netnsexec -type f)
ALL_SOURCE_FILES := $(shell find . -name '*.go')
# Shorthand build targets.
vpc-eni: $(BUILD_DIR)/vpc-eni
vpc-branch-eni: $(BUILD_DIR)/vpc-branch-eni
vpc-bridge: $(BUILD_DIR)/vpc-bridge
vpc-tunnel: $(BUILD_DIR)/vpc-tunnel
aws-appmesh: $(BUILD_DIR)/aws-appmesh
ecs-serviceconnect: $(BUILD_DIR)/ecs-serviceconnect
netnsexec: $(BUILD_DIR)/netnsexec
all-plugins: vpc-eni vpc-branch-eni vpc-bridge vpc-tunnel aws-appmesh ecs-serviceconnect
all-tools: netnsexec
all-binaries: all-plugins all-tools
build: all-binaries unit-test
# Build the vpc-eni CNI plugin.
$(BUILD_DIR)/vpc-eni: $(VPC_ENI_PLUGIN_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
$(BUILD_FLAGS) \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/vpc-eni \
github.com/aws/amazon-vpc-cni-plugins/plugins/vpc-eni
@echo "Built vpc-eni plugin."
# Build the vpc-branch-eni CNI plugin.
$(BUILD_DIR)/vpc-branch-eni: $(VPC_BRANCH_ENI_PLUGIN_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
$(BUILD_FLAGS) \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/vpc-branch-eni \
github.com/aws/amazon-vpc-cni-plugins/plugins/vpc-branch-eni
@echo "Built vpc-branch-eni plugin."
# Build the vpc-bridge CNI plugin.
$(BUILD_DIR)/vpc-bridge: $(VPC_BRIDGE_PLUGIN_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
$(BUILD_FLAGS) \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/vpc-bridge \
github.com/aws/amazon-vpc-cni-plugins/plugins/vpc-bridge
@echo "Built vpc-bridge plugin."
# Build the vpc-tunnel CNI plugin.
$(BUILD_DIR)/vpc-tunnel: $(VPC_TUNNEL_PLUGIN_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
$(BUILD_FLAGS) \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/vpc-tunnel \
github.com/aws/amazon-vpc-cni-plugins/plugins/vpc-tunnel
@echo "Built vpc-tunnel plugin."
# Build the aws-appmesh CNI plugin.
$(BUILD_DIR)/aws-appmesh: $(AWS_APPMESH_PLUGIN_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
$(BUILD_FLAGS) \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/aws-appmesh \
github.com/aws/amazon-vpc-cni-plugins/plugins/aws-appmesh
@echo "Built aws-appmesh plugin."
# Build the ecs-serviceconnect CNI plugin.
$(BUILD_DIR)/ecs-serviceconnect: $(ECS_SERVICECONNECT_PLUGIN_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
$(BUILD_FLAGS) \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/ecs-serviceconnect \
github.com/aws/amazon-vpc-cni-plugins/plugins/ecs-serviceconnect
@echo "Built ecs-serviceconnect plugin."
# Build the netnsexec tool.
$(BUILD_DIR)/netnsexec: $(NETNSEXEC_TOOL_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
$(BUILD_FLAGS) \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/netnsexec \
github.com/aws/amazon-vpc-cni-plugins/tools/netnsexec
@echo "Built netnsexec tool."
# List of go packages to be tested by test targets.
PACKAGES_TO_TEST = \
./capabilities/... \
./cni/... \
./logger/... \
./network/... \
./version/... \
./plugins/... \
./tools/...
# Run all unit tests.
.PHONY: unit-test
unit-test:
go test -v -tags unit_test -cover -race -timeout 10s $(PACKAGES_TO_TEST)
# Run aws-appmesh unit tests.
.PHONY: appmesh-unit-test
appmesh-unit-test:
go test -v -tags unit_test -cover -race -timeout 10s ./plugins/aws-appmesh/...
# Run ecs-serviceconnect unit tests.
.PHONY: ecs-serviceconnect-unit-test
ecs-serviceconnect-unit-test:
go test -v -tags unit_test -cover -race -timeout 10s ./plugins/ecs-serviceconnect/...
# Run all e2e tests.
.PHONY: e2e-test
e2e-test: $(ALL_SOURCE_FILES) all-binaries
sudo -E CNI_PATH=$(CUR_DIR)/$(BUILD_DIR) go test -v -tags e2e_test -race -timeout 120s $(PACKAGES_TO_TEST)
.PHONY: vpc-eni-e2e-tests
vpc-eni-e2e-tests: $(ALL_SOURCE_FILES) vpc-eni
sudo -E CNI_PATH=$(CUR_DIR)/$(BUILD_DIR) go test -v -tags e2e_test -race -timeout 60s ./plugins/vpc-eni/e2eTests/
.PHONY: vpc-branch-eni-e2e-tests
vpc-branch-eni-e2e-tests: $(ALL_SOURCE_FILES) vpc-branch-eni
sudo -E CNI_PATH=$(CUR_DIR)/$(BUILD_DIR) go test -v -tags e2e_test -race -timeout 60s ./plugins/vpc-branch-eni/e2eTests/
.PHONY: vpc-tunnel-e2e-tests
vpc-tunnel-e2e-tests: $(ALL_SOURCE_FILES) vpc-tunnel
sudo -E CNI_PATH=$(CUR_DIR)/$(BUILD_DIR) go test -v -tags e2e_test -race -timeout 60s ./plugins/vpc-tunnel/e2eTests/
.PHONY: appmesh-e2e-test
appmesh-e2e-test: $(ALL_SOURCE_FILES) aws-appmesh
sudo -E CNI_PATH=$(CUR_DIR)/$(BUILD_DIR) go test -v -tags e2e_test -race -timeout 120s ./plugins/aws-appmesh/e2eTests/
.PHONY: ecs-serviceconnect-e2e-test
ecs-serviceconnect-e2e-test: $(ALL_SOURCE_FILES) ecs-serviceconnect
sudo -E CNI_PATH=$(CUR_DIR)/$(BUILD_DIR) go test -v -tags e2e_test -race -timeout 120s ./plugins/ecs-serviceconnect/e2eTests/
# Clean all build artifacts.
.PHONY: clean
clean:
rm -rf ${BUILD_ROOT_DIR} ||: