-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMakefile
More file actions
299 lines (263 loc) · 9.04 KB
/
Copy pathMakefile
File metadata and controls
299 lines (263 loc) · 9.04 KB
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
SHELL := /bin/bash
.ONESHELL:
.SHELLFLAGS += -x -e -o pipefail
.PHONY: web
PWD = $(shell pwd)
UID = $(shell id -u)
GID = $(shell id -g)
VERSION = "0.33.0"
LD_FLAGS = -X beryju.io/gravity/pkg/extconfig.Version=${VERSION}
GO_FLAGS = -ldflags "${LD_FLAGS}" -v
SCHEMA_FILE = schema.yml
TEST_COUNT = 1
TEST_FLAGS =
TEST_OUTPUT = ${PWD}/.test-output
GEN_API_TS = "gen-ts-api"
GEN_API_GO = "api"
GEN_ED_GO = "pkg/externaldns/generated/"
ci--env:
echo "sha=${GITHUB_SHA}" >> ${GITHUB_OUTPUT}
echo "build=${GITHUB_RUN_ID}" >> ${GITHUB_OUTPUT}
echo "timestamp=$(shell date +%s)" >> ${GITHUB_OUTPUT}
echo "version=${VERSION}" >> ${GITHUB_OUTPUT}
docker-build: internal/resources/macoui internal/resources/blocky internal/resources/tftp
go build \
-ldflags "${LD_FLAGS} -X beryju.io/gravity/pkg/extconfig.BuildHash=${GIT_BUILD_HASH}" \
${GO_BUILD_FLAGS} \
-v -a -o gravity ${PWD}/cmd/server/main
docker-build-external-dns:
go build \
-ldflags "${LD_FLAGS} -X beryju.io/gravity/pkg/extconfig.BuildHash=${GIT_BUILD_HASH}" \
${GO_BUILD_FLAGS} \
-v -a -o gravity-external-dns ${PWD}/cmd/external-dns/main
clean:
rm -rf ${PWD}/data/
rm -rf ${PWD}/bin/
rm -rf ${PWD}/tests/coverage-*/
run: internal/resources/macoui internal/resources/blocky internal/resources/tftp
export INSTANCE_LISTEN=0.0.0.0
export DEBUG=true
export LISTEN_ONLY=true
$(eval LD_FLAGS := -X beryju.io/gravity/pkg/extconfig.Version=${VERSION} -X beryju.io/gravity/pkg/extconfig.BuildHash=dev-$(shell git rev-parse HEAD))
go run \
${GO_FLAGS} \
${PWD}/cmd/server/main \
server
# Web
web: web-lint web-build
web-install:
cd ${PWD}/web
npm ci
npm version ${VERSION} || true
web-build:
cd ${PWD}/web
npm run build
web-watch:
cd ${PWD}/web
npm run watch
web-lint:
cd ${PWD}/web
npm run prettier
npm run lint
npm run tsc
npm run lit-analyse
# CLI
bin/gravity-cli:
$(eval LD_FLAGS := -X beryju.io/gravity/pkg/extconfig.Version=${VERSION} -X beryju.io/gravity/pkg/extconfig.BuildHash=dev-$(shell git rev-parse HEAD))
mkdir -p ${PWD}/bin/
go build ${GO_FLAGS} -o ${PWD}/bin/gravity-cli ${PWD}/cmd/cli/main/
# Website
website-watch:
cd ${PWD}/docs
open http://localhost:1313/ && hugo server --noBuildLock
internal/resources/macoui:
mkdir -p ${PWD}/internal/resources/macoui
tshark -G manuf > ${PWD}/internal/resources/macoui/db.txt
internal/resources/blocky:
mkdir -p ${PWD}/internal/resources/blocky
curl -L https://adaway.org/hosts.txt -o ${PWD}/internal/resources/blocky/adaway.org.txt
curl -L https://big.oisd.nl/domainswild -o ${PWD}/internal/resources/blocky/big.oisd.nl.txt
curl -L https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -o ${PWD}/internal/resources/blocky/StevenBlack.hosts.txt
curl -L https://v.firebog.net/hosts/AdguardDNS.txt -o ${PWD}/internal/resources/blocky/AdguardDNS.txt
curl -L https://v.firebog.net/hosts/Easylist.txt -o ${PWD}/internal/resources/blocky/Easylist.txt
curl -L https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt -o ${PWD}/internal/resources/blocky/AdGuardSDNSFilter.txt
internal/resources/tftp:
mkdir -p ${PWD}/internal/resources/tftp
curl -L https://boot.ipxe.org/ipxe.efi -o ${PWD}/internal/resources/tftp/ipxe.efi
curl -L https://boot.ipxe.org/undionly.kpxe -o ${PWD}/internal/resources/tftp/ipxe.undionly.kpxe
curl -L https://boot.netboot.xyz/ipxe/netboot.xyz.kpxe -o ${PWD}/internal/resources/tftp/netboot.xyz.kpxe
curl -L https://boot.netboot.xyz/ipxe/netboot.xyz-undionly.kpxe -o ${PWD}/internal/resources/tftp/netboot.xyz-undionly.kpxe
curl -L https://boot.netboot.xyz/ipxe/netboot.xyz.efi -o ${PWD}/internal/resources/tftp/netboot.xyz.efi
gen-build:
export DEBUG=true
export CI=false
go run \
${GO_FLAGS} \
${PWD}/cmd/server/main \
generateSchema ${SCHEMA_FILE}
git add ${SCHEMA_FILE}
gen-proto:
protoc \
--proto_path ${PWD} \
--go_out ${PWD} \
${PWD}/protobuf/**
gen-clean:
rm -rf ${PWD}/${GEN_API_TS}/
rm -rf ${PWD}/${GEN_ED_GO}/
rm -rf ${PWD}/${GEN_API_GO}/api/
rm -rf ${PWD}/${GEN_API_GO}/docs/
rm -rf ${PWD}/${GEN_API_GO}/test/
rm -rf ${PWD}/${GEN_API_GO}/*.go
gen-tag:
git add Makefile
cd ${PWD}
git commit -m "release version v${VERSION}"
git tag v${VERSION}
git push
git push --tags
gen-client-go:
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
openapitools/openapi-generator-cli:v7.22.0 generate \
--git-host beryju.io \
--git-user-id gravity \
--git-repo-id api \
--additional-properties=packageName=api \
-i /local/schema.yml \
-g go \
-o /local/${GEN_API_GO} \
-c /local/${GEN_API_GO}/config.yaml
cd ${PWD}/${GEN_API_GO}/
rm -rf .travis.yml go.mod go.sum test/
go get
go fmt ${PWD}/${GEN_API_GO}/
go tool mvdan.cc/gofumpt -l -w ${PWD}/${GEN_API_GO}/
git add ${PWD}/${GEN_API_GO}/
gen-client-ts:
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
openapitools/openapi-generator-cli:v7.15.0 generate \
-i /local/${SCHEMA_FILE} \
-g typescript-fetch \
-o /local/${GEN_API_TS} \
--additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=gravity-api,npmVersion=${VERSION} \
--git-user-id BeryJu \
--git-repo-id gravity
cd ${PWD}/${GEN_API_TS} && npm i
\cp -rf ${PWD}/${GEN_API_TS}/* ${PWD}/web/node_modules/gravity-api
gen-client-ts-publish: gen-client-ts
cd ${PWD}/${GEN_API_TS}
npm publish
@echo "Waiting for NPM package to become available"
sleep 30
cd ${PWD}/web
npm i gravity-api@${VERSION}
npm version ${VERSION} || true
git add package*.json
gen-external-dns:
wget https://kubernetes-sigs.github.io/external-dns/v0.21.0/api/webhook.yaml -O pkg/externaldns/schema.yaml
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
openapitools/openapi-generator-cli:v7.22.0 generate \
--git-host beryju.io \
--git-user-id gravity \
--git-repo-id api \
--additional-properties=packageName=externaldnsapi \
--additional-properties=sourceFolder=externaldnsapi \
-i /local/pkg/externaldns/schema.yaml \
-g go-server \
-o /local/${GEN_ED_GO} \
-c /local/${GEN_API_GO}/config.yaml
cd ${PWD}/${GEN_ED_GO}/
sed -i 's|application/json; charset=UTF-8|application/external.dns.webhook+json;version=1|g' externaldnsapi/*
rm -f .travis.yml go.mod go.sum main.go Dockerfile
go fmt ${PWD}/${GEN_ED_GO}/externaldnsapi
go tool mvdan.cc/gofumpt -l -w ${PWD}/${GEN_ED_GO}/
git add ${PWD}/${GEN_ED_GO}/
gen-go-tidy:
go mod tidy
git add go.mod go.sum
release: gen-build gen-clean gen-client-go gen-external-dns gen-go-tidy gen-client-ts-publish gen-tag
lint: web-lint
golangci-lint run -v --timeout 5000s
test-env-start:
cd ${PWD}/hack/tests/
docker compose --project-name gravity-test-env up -d
test-env-stop:
cd ${PWD}/hack/tests/
docker compose --project-name gravity-test-env down -v
install-deps:
sudo apt-get update
sudo apt-get install -y nmap libpcap-dev tshark
sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
$(MAKE) internal/resources/macoui internal/resources/blocky internal/resources/tftp
test-local:
$(eval TEST_COUNT := 100)
$(eval TEST_FLAGS := -shuffle=on -failfast)
test: internal/resources/macoui internal/resources/blocky internal/resources/tftp
export BOOTSTRAP_ROLES="dns;dhcp;api;discovery;backup;debug;tsdb;tftp"
export ETCD_ENDPOINT="localhost:2385"
export DEBUG="true"
export LISTEN_ONLY="true"
export CI="true"
go test \
-p 1 \
-v \
-coverprofile=${PWD}/coverage.txt \
-covermode=atomic \
-count=${TEST_COUNT} \
-json \
${TEST_FLAGS} \
$(shell go list ./... | grep -v beryju.io/gravity/api | grep -v beryju.io/gravity/cmd | grep -v beryju.io/gravity/pkg/externaldns/generated) \
2>&1 | tee ${TEST_OUTPUT}
go tool cover \
-html ${PWD}/coverage.txt \
-o ${PWD}/coverage.html
test-e2e-container-build:
docker build \
--build-arg=GRAVITY_BUILD_ARGS=GO_BUILD_FLAGS=-cover \
-t gravity:e2e-test \
${PWD}
test-e2e: test-e2e-container-build
export CI="true"
go test \
-p 1 \
-v \
-coverprofile=${PWD}/coverage.txt \
-covermode=atomic \
-count=${TEST_COUNT} \
-timeout=300s \
-json \
-tags=e2e \
${TEST_FLAGS} \
beryju.io/gravity/tests \
2>&1 | tee ${TEST_OUTPUT}
go tool covdata textfmt \
-i ${PWD}/tests/coverage/ \
--pkg $(shell go list ./... | grep -v beryju.io/gravity/api | grep -v beryju.io/gravity/cmd | grep -v beryju.io/gravity/pkg/externaldns/generated | xargs | sed 's/ /,/g') \
-o ${PWD}/coverage_in_container.txt
go tool cover \
-html ${PWD}/coverage_in_container.txt \
-o ${PWD}/coverage_in_container.html
bench: internal/resources/macoui internal/resources/blocky internal/resources/tftp
export BOOTSTRAP_ROLES="dns;dhcp;api;discovery;backup;debug;tsdb;tftp"
export ETCD_ENDPOINT="localhost:2385"
export LISTEN_ONLY="true"
export LOG_LEVEL="FATAL"
export CI="true"
go test \
-run=^$$ \
-bench=^Benchmark \
-coverprofile=${PWD}/coverage.txt \
-covermode=atomic \
-benchmem \
$(shell go list ./... | grep -v beryju.io/gravity/api | grep -v beryju.io/gravity/cmd | grep -v beryju.io/gravity/pkg/externaldns/generated) \
2>&1 | tee ${TEST_OUTPUT}
go tool cover \
-html ${PWD}/coverage.txt \
-o ${PWD}/coverage.html
test-convert:
go tool github.com/jstemmer/go-junit-report/v2 -parser gojson -in ${TEST_OUTPUT} -out ${PWD}/junit.xml