-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
230 lines (166 loc) · 6.18 KB
/
justfile
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
set shell := ["/usr/bin/env", "bash", "-euo", "pipefail", "-c"]
static_version := `cat VERSION.txt`
git_version := `git describe --match="" --always --dirty --abbrev=10`
version_ldflags := "-X 'fardjad.com/dqlite-vip/version.gitVersion=" + git_version + "' -X 'fardjad.com/dqlite-vip/version.staticVersion=" + static_version + "'"
[doc("Show this message")]
help:
just --list
[group("test")]
[doc("Generate mocks with mockery")]
generate-mocks:
#!/usr/bin/env bash
set -euo pipefail
eval $(go env)
rm -rf mocks
mockery --all
go mod tidy
[private]
static-go command *args:
#!/usr/bin/env bash
set -euo pipefail
DIR=$PWD/hack
. $PWD/hack/static-dqlite.sh
go {{ command }} \
-tags libsqlite3 \
-ldflags '-s -w -linkmode "external" -extldflags "-static" {{ version_ldflags }}' \
{{ args }}
[group("build")]
[doc("Build the dqlite-vip binary statically")]
build-static:
#!/usr/bin/env bash
set -euo pipefail
mkdir -p bin/static
just static-go build -o bin/static/dqlite-vip ./
[private]
dynamic-go command *args:
#!/usr/bin/env bash
set -euo pipefail
DIR=$PWD/hack
. $PWD/hack/dynamic-dqlite.sh
go {{ command }} \
-tags libsqlite3 \
-ldflags '-s -w -extldflags "-Wl,-rpath,$ORIGIN/lib -Wl,-rpath,$ORIGIN/../lib" {{ version_ldflags }}' \
{{ args }}
[group("build")]
[doc("Build the dqlite-vip binary")]
build-dynamic go_recipe="dynamic-go":
#!/usr/bin/env bash
set -euo pipefail
mkdir -p bin/dynamic
just {{ go_recipe }} build -o bin/dynamic/dqlite-vip ./
mkdir -p bin/dynamic/lib
cp -r ./hack/.deps/dynamic/lib/*.so* ./bin/dynamic/lib/
[private]
debug-go command *args:
#!/usr/bin/env bash
set -euo pipefail
DIR=$PWD/hack
. $PWD/hack/dynamic-dqlite.sh
go {{ command }} \
-tags libsqlite3 \
-gcflags "all=-N -l" \
-ldflags '-extldflags "-Wl,-rpath,$ORIGIN/lib -Wl,-rpath,$ORIGIN/../lib"' \
{{ args }}
[group("debug")]
build-debug:
@just build-dynamic debug-go
[group("debug")]
build-test-debug *args: build-debug
@just debug-go test -c -o ./bin/dynamic/test {{ args }}
[group("test")]
[doc("Run the tests")]
test *args:
#!/usr/bin/env bash
set -euo pipefail
just dynamic-go test -timeout 10s {{ args }} ./...
[group("debug")]
dlv bin:
#!/usr/bin/env bash
if ! command -v dlv &> /dev/null; then
go install github.com/go-delve/delve/cmd/dlv@latest
fi
eval $(go env)
"${GOPATH}/bin/dlv" --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec {{ bin }}
[group("build")]
[doc("Clean the build artifacts")]
clean:
#!/usr/bin/env bash
set -euo pipefail
rm -rf bin hack/.build hack/.deps
[group("run")]
[doc("Run the dqlite-vip binary")]
dqlite-vip *args:
#!/usr/bin/env bash
set -euo pipefail
just build-static > /dev/null
./bin/static/dqlite-vip {{ args }}
[group("local-cluster")]
[doc("Run a 3-node cluster of dqlite-vip nodes")]
run-cluster:
#!/usr/bin/env bash
set -e
sudo rm -rf /tmp/dqlite-vip
just build-static > /dev/null
sudo ./bin/static/dqlite-vip start --data-dir /tmp/dqlite-vip/1 --bind-cluster 127.0.0.1:8001 --bind-http 127.0.0.1:9901 --iface dummy01 & PID1=$!
sudo ./bin/static/dqlite-vip start --data-dir /tmp/dqlite-vip/2 --bind-cluster 127.0.0.1:8002 --bind-http 127.0.0.1:9902 --join 127.0.0.1:8001 --iface dummy02 & PID2=$!
sudo ./bin/static/dqlite-vip start --data-dir /tmp/dqlite-vip/3 --bind-cluster 127.0.0.1:8003 --bind-http 127.0.0.1:9903 --join 127.0.0.1:8001 --iface dummy03 & PID3=$!
cleanup() {
echo "Shutting down..."
kill -9 $PID1 $PID2 $PID3 2>/dev/null || true
wait $PID1 $PID2 $PID3 2>/dev/null || true
exit
}
trap cleanup EXIT INT TERM
while true; do
if ! kill -0 $PID1 2>/dev/null || ! kill -0 $PID2 2>/dev/null || ! kill -0 $PID3 2>/dev/null; then
echo "One of the processes exited, shutting down all..."
exit 1
fi
sleep 1
done
[group("local-cluster")]
[doc("Run a 3-node cluster of dqlite-vip nodes in a tmux session")]
run-cluster-xpanes:
#!/usr/bin/env bash
set -e
sudo rm -rf /tmp/dqlite-vip
just build-static > /dev/null
history -c
CMD1="sudo ./bin/static/dqlite-vip start --data-dir /tmp/dqlite-vip/1 --bind-cluster 127.0.0.1:8001 --bind-http 127.0.0.1:9901 --iface dummy01"
CMD2="sudo ./bin/static/dqlite-vip start --data-dir /tmp/dqlite-vip/2 --bind-cluster 127.0.0.1:8002 --bind-http 127.0.0.1:9902 --join 127.0.0.1:8001 --iface dummy02"
CMD3="sudo ./bin/static/dqlite-vip start --data-dir /tmp/dqlite-vip/3 --bind-cluster 127.0.0.1:8003 --bind-http 127.0.0.1:9903 --join 127.0.0.1:8001 --iface dummy03"
xpanes --cols=3 --desync -e "$CMD1" "$CMD2" "$CMD3"
[group("local-cluster")]
[doc("Watch the status of the nodes in a tmux session")]
watch-nodes-xpanes:
#!/usr/bin/env bash
set -e
CMD1="viddy -dtn 1 'curl -s 127.0.0.1:9901/status | jq -C'"
CMD2="viddy -dtn 1 'curl -s 127.0.0.1:9902/status | jq -C'"
CMD3="viddy -dtn 1 'curl -s 127.0.0.1:9903/status | jq -C'"
xpanes --cols=3 -e -ss "$CMD1" "$CMD2" "$CMD3"
[group("local-cluster")]
[doc("Set up dummy network interfaces on the host")]
setup-dummy-interfaces: remove-dummy-interfaces
#!/usr/bin/env bash
sudo modprobe dummy
sudo ip link add dummy01 type dummy
sudo ip link add dummy02 type dummy
sudo ip link add dummy03 type dummy
[group("local-cluster")]
[doc("Remove dummy network interfaces on the host")]
remove-dummy-interfaces:
#!/usr/bin/env bash
sudo ip link delete dummy01 2>/dev/null || true
sudo ip link delete dummy02 2>/dev/null || true
sudo ip link delete dummy03 2>/dev/null || true
[group("local-cluster")]
[doc("Watch dummy network interfaces on the host")]
watch-dummy-interfaces:
#!/usr/bin/env bash
viddy -dtn 1 "ip a show dev dummy01; ip a show dev dummy02; ip a show dev dummy03"
[group("local-cluster")]
[doc("Set the VIP of a dqlite-vip node")]
set-vip node_address="127.0.0.1:9901" vip="1.2.3.4/24":
#!/usr/bin/env bash
curl -XPUT -d '{"vip":"{{ vip }}"}' "{{ node_address }}/vip"