forked from submariner-io/submariner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
138 lines (101 loc) · 5.01 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
BASE_BRANCH ?= devel
PROTOC_VERSION=3.17.3
export BASE_BRANCH
export restart ?= all
# Define LOCAL_BUILD to build directly on the host and not inside a Dapper container
ifdef LOCAL_BUILD
DAPPER_HOST_ARCH ?= $(shell go env GOHOSTARCH)
SHIPYARD_DIR ?= ../shipyard
SCRIPTS_DIR ?= $(SHIPYARD_DIR)/scripts/shared
export DAPPER_HOST_ARCH
export SHIPYARD_DIR
export SCRIPTS_DIR
endif
ifneq (,$(DAPPER_HOST_ARCH))
# Running in Dapper
IMAGES ?= submariner-gateway submariner-route-agent submariner-globalnet submariner-networkplugin-syncer
PRELOAD_IMAGES = $(IMAGES) submariner-operator
ifneq (,$(filter ovn,$(_using)))
SETTINGS ?= $(DAPPER_SOURCE)/.shipyard.e2e.ovn.yml
else
SETTINGS ?= $(DAPPER_SOURCE)/.shipyard.e2e.yml
endif
include $(SHIPYARD_DIR)/Makefile.inc
TARGETS := $(shell ls -p scripts | grep -v -e /)
override BUILD_ARGS += --ldflags '-X main.VERSION=$(VERSION)'
ifneq (,$(filter external-net,$(_using)))
override E2E_ARGS += --testdir test/external
override DEPLOY_ARGS += --plugin scripts/e2e/external/hook
override CLEANUP_ARGS += --plugin scripts/e2e/external/hook
endif
override E2E_ARGS += cluster2 cluster1
override UNIT_TEST_ARGS += test
override VALIDATE_ARGS += --skip-dirs pkg/client
# When cross-building, we need to map Go architectures and operating systems to Docker buildx platforms:
# Docker buildx platform | Fedora support? | Go
# --------------------------------------------------
# linux/amd64 | Yes (amd64) | linux/amd64
# linux/arm64 | Yes (arm64v8) | linux/arm64
# linux/riscv64 | No | linux/riscv64
# linux/ppc64le | Yes (ppc64le) | linux/ppc64le
# linux/s390x | Yes (s390x) | linux/s390x
# linux/386 | No | linux/386
# linux/arm/v7 | Yes (arm32v7) | linux/arm
# linux/arm/v6 | No | N/A
#
# References: https://github.com/golang/go/blob/master/src/go/build/syslist.go
gotodockerarch = $(patsubst arm,arm/v7,$(1))
dockertogoarch = $(patsubst arm/v7,arm,$(1))
# Targets to make
deploy: images
e2e: vendor/modules.txt
golangci-lint: pkg/natdiscovery/proto/natdiscovery.pb.go
unit: pkg/natdiscovery/proto/natdiscovery.pb.go
%.pb.go: %.proto bin/protoc-gen-go bin/protoc
PATH="$(CURDIR)/bin:$$PATH" protoc --go_out=$$(go env GOPATH)/src $<
bin/protoc-gen-go: vendor/modules.txt
mkdir -p $(@D)
GOFLAGS="" GOBIN="$(CURDIR)/bin" go install google.golang.org/protobuf/cmd/protoc-gen-go@$(shell awk '/google.golang.org\/protobuf/ {print $$2}' go.mod)
bin/protoc:
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip
sha256sum -c scripts/protoc.sha256
unzip protoc-$(PROTOC_VERSION)-linux-x86_64.zip 'bin/*' 'include/*'
rm -f protoc-$(PROTOC_VERSION)-linux-x86_64.zip
bin/%/submariner-gateway: vendor/modules.txt main.go $(shell find pkg -not \( -path 'pkg/globalnet*' -o -path 'pkg/routeagent*' \)) pkg/natdiscovery/proto/natdiscovery.pb.go
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ . $(BUILD_ARGS)
bin/%/submariner-route-agent: vendor/modules.txt $(shell find pkg/routeagent_driver)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/routeagent_driver $(BUILD_ARGS)
bin/%/submariner-globalnet: vendor/modules.txt $(shell find pkg/globalnet)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/globalnet $(BUILD_ARGS)
bin/%/submariner-networkplugin-syncer: vendor/modules.txt $(shell find pkg/networkplugin-syncer)
GOARCH=$(call dockertogoarch,$(patsubst bin/linux/%/,%,$(dir $@))) ${SCRIPTS_DIR}/compile.sh $@ ./pkg/networkplugin-syncer $(BUILD_ARGS)
nullstring :=
space := $(nullstring) # end of the line
comma := ,
# Single-architecture only for now (we need to support manifests in Shipyard)
# This can be overridden to build for other supported architectures; the reference is the Go architecture,
# so "make images ARCHES=arm" will build a linux/arm/v7 image
ARCHES ?= amd64
BINARIES = submariner-gateway submariner-route-agent submariner-globalnet submariner-networkplugin-syncer
ARCH_BINARIES := $(foreach arch,$(subst $(comma),$(space),$(ARCHES)),$(foreach binary,$(BINARIES),bin/linux/$(call gotodockerarch,$(arch))/$(binary)))
IMAGES_ARGS = --platform $(subst $(space),$(comma),$(foreach arch,$(subst $(comma),$(space),$(ARCHES)),linux/$(call gotodockerarch,$(arch))))
build: $(ARCH_BINARIES)
licensecheck: BUILD_ARGS=--debug
licensecheck: $(ARCH_BINARIES) bin/lichen
bin/lichen -c .lichen.yaml $(ARCH_BINARIES)
bin/lichen: vendor/modules.txt
mkdir -p $(@D)
go build -o $@ github.com/uw-labs/lichen
ci: validate unit build images
$(TARGETS): vendor/modules.txt
./scripts/$@
.PHONY: $(TARGETS) build ci images unit validate licensecheck
else
# Not running in Dapper
Makefile.dapper:
@echo Downloading $@
@curl -sfLO https://raw.githubusercontent.com/submariner-io/shipyard/$(BASE_BRANCH)/$@
include Makefile.dapper
endif
# Disable rebuilding Makefile
Makefile Makefile.inc: ;