-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
167 lines (134 loc) · 5.2 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
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
BUILDARGS ?=
DEB_BUILD_CONTAINER ?= golang:1.20-bookworm
ifneq ("$(wildcard ./version)","")
METALBOND_VERSION ?= $(shell cat ./version)
else ifeq ($(shell git describe --exact-match --tags 2> /dev/null),)
METALBOND_VERSION ?= $(shell git rev-parse --short HEAD)
else
METALBOND_VERSION ?= $(shell (git describe --exact-match --tags 2> /dev/null | cut -dv -f2))
endif
METALBOND_LDFLAGS = "-X github.com/ironcore-dev/metalbond.METALBOND_VERSION=$(METALBOND_VERSION)"
ARCHITECTURE = $(shell dpkg --print-architecture)
.PHONY: all
all: $(ARCHITECTURE)
cp ./target/metalbond_$(ARCHITECTURE) ./target/metalbond
.PHONY: amd64
amd64: target_html
cd cmd && go build -buildvcs=false -ldflags $(METALBOND_LDFLAGS) -o ../target/metalbond_amd64
.PHONY: arm64
arm64: target_html
cd cmd && env GOOS=linux GOARCH=arm64 go build -buildvcs=false -ldflags $(METALBOND_LDFLAGS) -o ../target/metalbond_arm64
target:
mkdir -p target
.PHONY: target_html
target_html: | target
rm -rf target/html
cp -ra html target
.PHONY: tarball
tarball: | target
rsync -a ./* target/metalbond-$(METALBOND_VERSION)/ --exclude target/
# echo $(METALBOND_VERSION) > target/metalbond-$(METALBOND_VERSION)/version
cd target && tar -czf metalbond_$(METALBOND_VERSION).orig.tar.gz metalbond-$(METALBOND_VERSION)
rm -rf target/metalbond-$(METALBOND_VERSION)/
.PHONY: run-server
run-server: all
cd target && ./metalbond server \
--listen [::]:4711 \
--http [::]:4712 \
--keepalive 3
.PHONY: run-client1
run-client1: all
cd target && sudo ./metalbond client \
--server [::1]:4711 \
--keepalive 2 \
--subscribe 23 \
--announce 23#2001:db8:1::/48#2001:db8::cafe \
--announce 23#192.168.0.0/16#2001:db8::cafe \
--install-routes 23#100 \
--tun overlay-tun
.PHONY: run-client1b
run-client1b: all
cd target && ./metalbond client \
--server [::1]:4711 \
--keepalive 2 \
--subscribe 23 \
--announce 23#2001:db8:1::/48#2001:db8::cafe \
--announce 23#192.168.0.0/16#2001:db8::cafe
.PHONY: run-client2
run-client2: all
cd target && ./metalbond client \
--server [::1]:4711 \
--keepalive 2 \
--subscribe 23 \
--subscribe 42 \
--announce 23#2001:db8:1::/48#2001:db8::cafb \
--announce 23#2001:db8:2::/48#2001:db8::2:beef \
--announce 23#2001:db8:3::/48#2001:db8::3:beef \
--announce 23#2001:db8:4::/48#2001:db8::4:beef \
--announce 23#2001:db8:4::/48#2001:db8::4a:beef \
--announce 23#2001:db8:4::/48#2001:db8::4b:beef \
--announce 23#2001:db8:4::/48#2001:db8::4c:beef \
--announce 42#10.0.0.0/8#2001:db8::beef
.PHONY: proto
proto:
protoc -I ./pb --go_out=. ./pb/metalbond.proto
.PHONY: clean
clean:
rm -rf target
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker build $(BUILDARGS) -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
.PHONY: deb
deb:
docker run --rm -v "$(PWD):/workdir" -e "METALBOND_VERSION=$(METALBOND_VERSION)" -e "ARCHITECTURE=amd64" $(DEB_BUILD_CONTAINER) bash -c "cd /workdir && debian/make-deb.sh"
docker run --rm -v "$(PWD):/workdir" -e "METALBOND_VERSION=$(METALBOND_VERSION)" -e "ARCHITECTURE=arm64" $(DEB_BUILD_CONTAINER) bash -c "cd /workdir && debian/make-deb.sh"
.PHONY: unit-test
unit-test:
go test -v
.PHONY: fmt
fmt: goimports ## Run goimports against code.
$(GOIMPORTS) -w .
.PHONY: add-license
add-license: addlicense ## Add license headers to all go files.
find . -name '*.go' -exec $(ADDLICENSE) -f hack/license-header.txt {} +
.PHONY: check-license
check-license: addlicense ## Check that every file has a license header present.
find . -name '*.go' -exec $(ADDLICENSE) -check -c 'IronCore authors' {} +
.PHONY: lint
lint: golangci-lint ## Run golangci-lint on the code.
$(GOLANGCI_LINT) run ./...
test:
go test ./... -coverprofile cover.out
check: manifests generate fmt check-license lint test ## Lint and run tests.
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Tools
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
ADDLICENSE ?= $(LOCALBIN)/addlicense
GOIMPORTS ?= $(LOCALBIN)/goimports
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
## Tool Versions
ADDLICENSE_VERSION ?= v1.1.1
GOIMPORTS_VERSION ?= v0.13.0
GOLANGCI_LINT_VERSION ?= v1.55.2
.PHONY: addlicense
addlicense: $(ADDLICENSE) ## Download addlicense locally if necessary.
$(ADDLICENSE): $(LOCALBIN)
test -s $(LOCALBIN)/addlicense || GOBIN=$(LOCALBIN) go install github.com/google/addlicense@$(ADDLICENSE_VERSION)
.PHONY: goimports
goimports: $(GOIMPORTS) ## Download goimports locally if necessary.
$(GOIMPORTS): $(LOCALBIN)
test -s $(LOCALBIN)/goimports || GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)