-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
251 lines (219 loc) · 7.29 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
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
SHELL := /bin/bash
.ONESHELL:
.SHELLFLAGS += -x -e -o pipefail
.PHONY: web
PWD = $(shell pwd)
UID = $(shell id -u)
GID = $(shell id -g)
VERSION = "0.26.1"
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 =
GEN_API_TS = "gen-ts-api"
GEN_API_GO = "api"
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
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 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 internal/resources/macoui
curl -L https://raw.githubusercontent.com/wireshark/wireshark/6885d787fda5f74a2d1f9eeea443fecf8dd58528/manuf -o ${PWD}/internal/resources/macoui/db.txt
internal/resources/blocky:
mkdir -p 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 internal/resources/tftp
curl -L http://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
go run \
${GO_FLAGS} \
${PWD}/cmd/server/main \
generateSchema ${SCHEMA_FILE}
git add ${SCHEMA_FILE}
gen-proto:
protoc \
--proto_path . \
--go_out ${PWD} \
protobuf/**
gen-clean:
rm -rf ${PWD}/${GEN_API_TS}/
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}
gen-client-go:
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
openapitools/openapi-generator-cli:v6.6.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 -f .travis.yml go.mod go.sum
go get
go fmt ${PWD}/${GEN_API_GO}/
go mod tidy
gofumpt -l -w ${PWD}/${GEN_API_GO}/ || true
git add ${PWD}/${GEN_API_GO}/
gen-client-ts:
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
openapitools/openapi-generator-cli:v6.6.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-repo-id BeryJu \
--git-user-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
cd ${PWD}/web
npm i gravity-api@${VERSION}
npm version ${VERSION} || true
git add package*.json
release: gen-build gen-clean gen-client-go 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: internal/resources/macoui internal/resources/blocky internal/resources/tftp
sudo apt-get install -y nmap libpcap-dev
sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
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} \
${TEST_FLAGS} \
$(shell go list ./... | grep -v beryju.io/gravity/api | grep -v beryju.io/gravity/cmd) \
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 \
.
test-e2e: test-e2e-container-build
cd ${PWD}/tests
go get .
go test \
-p 1 \
-v \
-coverprofile=${PWD}/coverage.txt \
-covermode=atomic \
-count=${TEST_COUNT} \
${TEST_FLAGS} \
beryju.io/gravity/tests \
2>&1 | tee test-output
cd ${PWD}
go tool covdata textfmt \
-i ${PWD}/tests/coverage/ \
--pkg $(shell go list ./... | grep -v beryju.io/gravity/api | grep -v beryju.io/gravity/cmd | xargs | sed 's/ /,/g') \
-o ${PWD}/coverage_in_container.txt
go tool cover \
-html ${PWD}/coverage_in_container.txt \
-o ${PWD}/coverage.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) \
| tee test-output
go tool cover \
-html ${PWD}/coverage.txt \
-o ${PWD}/coverage.html