forked from aws/amazon-vpc-cni-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (117 loc) · 4.65 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
# 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 --iso-8601=seconds)
BUILD_RELEASE_FLAGS = "-a"
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 cni/*.go, logger/*.go, network/*.go, version/*.go)
VPC_SHARED_ENI_PLUGIN_SOURCE_FILES = $(shell find plugins/vpc-shared-eni -type f)
VPC_BRANCH_ENI_PLUGIN_SOURCE_FILES = $(shell find plugins/vpc-branch-eni -type f)
VPC_BRANCH_PAT_ENI_PLUGIN_SOURCE_FILES = $(shell find plugins/vpc-branch-pat-eni -type f)
AWS_APPMESH_PLUGIN_SOURCE_FILES = $(shell find plugins/aws-appmesh -type f)
ALL_SOURCE_FILES := $(shell find . -name '*.go')
# Shorthand build targets.
vpc-shared-eni: $(BUILD_DIR)/vpc-shared-eni
vpc-branch-eni: $(BUILD_DIR)/vpc-branch-eni
vpc-branch-pat-eni: $(BUILD_DIR)/vpc-branch-pat-eni
aws-appmesh: $(BUILD_DIR)/aws-appmesh
all-binaries: vpc-shared-eni vpc-branch-eni vpc-branch-pat-eni aws-appmesh
build: all-binaries unit-test
# Build the vpc-shared-eni CNI plugin.
$(BUILD_DIR)/vpc-shared-eni: $(VPC_SHARED_ENI_PLUGIN_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
-a \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/vpc-shared-eni \
github.com/aws/amazon-vpc-cni-plugins/plugins/vpc-shared-eni
@echo "Built vpc-shared-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 \
-a \
-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-branch-pat-eni CNI plugin.
$(BUILD_DIR)/vpc-branch-pat-eni: $(VPC_BRANCH_PAT_ENI_PLUGIN_SOURCE_FILES) $(COMMON_SOURCE_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) \
go build \
-installsuffix cgo \
-v \
-a \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/vpc-branch-pat-eni \
github.com/aws/amazon-vpc-cni-plugins/plugins/vpc-branch-pat-eni
@echo "Built vpc-branch-pat-eni 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 \
-a \
-ldflags $(LINKER_FLAGS) \
-o $(BUILD_DIR)/aws-appmesh \
github.com/aws/amazon-vpc-cni-plugins/plugins/aws-appmesh
@echo "Built aws-appmesh plugin."
# Run all unit tests.
.PHONY: unit-test
unit-test: $(ALL_SOURCE_FILES)
go test -v -cover -race -timeout 10s ./...
# Run aws-appmesh unit tests.
.PHONY: appmesh-unit-test
appmesh-unit-test:
go test -v -cover -race -timeout 10s ./plugins/aws-appmesh/...
# Run all integration tests.
.PHONY: integration-test
integration-test: $(ALL_SOURCE_FILES)
go test -v -tags integration_test -race -timeout 10s ./...
# 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 ./...
.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 vpc_branch_eni" -race -timeout 60s ./plugins/vpc-branch-eni/e2eTests/
# Clean all build artifacts.
.PHONY: clean
clean:
rm -rf ${BUILD_ROOT_DIR} ||: