-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTaskfile.yml
More file actions
348 lines (291 loc) · 11.9 KB
/
Taskfile.yml
File metadata and controls
348 lines (291 loc) · 11.9 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
version: "3"
vars:
DEV_DB_OWNER: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf"
DEV_CHAIN_ID: "trufnetwork-dev"
DEV_NODE_1_ADDRESS: "tn-db-1:8484"
DEV_NODE_2_ADDRESS: "tn-db-2:8484"
DEV_NODE_1_RPC_ENDPOINT: "http://{{.DEV_NODE_1_ADDRESS}}"
# Collection variables for compose files
SINGLE_STACK_FILES:
- compose.yaml
DEVNET_STACK_FILES:
- deployments/dev-net/devnet-compose.yaml
- deployments/dev-gateway/dev-gateway-compose.yaml
- deployments/indexer/dev-indexer-compose.yaml
DEVNET_GATEWAY_FILES:
- deployments/dev-gateway/dev-gateway-compose.yaml
DEVNET_INDEXER_FILES:
- deployments/indexer/dev-indexer-compose.yaml
DEVNET_OBSERVER_FILES:
- deployments/observer/dev-observer-compose.yml
BINARIES: [ kwild, kwil-cli ]
tasks:
default:
desc: List all available tasks (same as task -l)
cmds:
- task -l
# ─── build ───────────────────────────────────────────────────────────────────
build:bin:
internal: true
env:
TARGET: ./.build
cmds:
- for: { var: BINARIES }
cmd: "SOURCE=./cmd/{{.ITEM}} ./scripts/build/binary {{.ITEM}}"
build:
desc: Build all kwil binaries
deps: [ build:bin ] # Depends on the loop task
build:debug:
desc: Build kwild binary with debug flags
cmds:
- go build -gcflags "all=-N -l" -o ./.build/kwild ./cmd/kwild/main.go
build:binaries:
desc: Download pre-built helper binaries required by compose stacks
cmds:
- ./scripts/download-binaries.sh
sources:
- ./scripts/download-binaries.sh
build:binaries:dev:
desc: Fetch dev-only helper binaries
deps:
- build:binaries
cmds:
- ./scripts/download-binaries-dev.sh
sources:
- ./scripts/download-binaries-dev.sh
build:benchmark:
desc: Build benchmark binaries
cmds:
- go test -v -c -timeout 0 ./internal/benchmark -o ./.build/benchmark
# ─── docker ──────────────────────────────────────────────────────────────────
docker:build:local:
desc: Build Docker image for local development (no version args needed)
cmds:
- docker build -f deployments/Dockerfile -t ghcr.io/trufnetwork/node:local .
# ─── host ─────────────────────────────────────────────────────────────────────
host:kwild:start:
desc: Run kwild server
cmds:
- .build/kwild start --autogen
host:kwild:clean:
desc: Clean kwild server
cmds:
- rm -rf ~/.kwild
host:postgres:start:
desc: Run a postgres container
cmds:
- docker start kwil-postgres || docker run -d -p 5432:5432 --name kwil-postgres -e "POSTGRES_HOST_AUTH_METHOD=trust" ghcr.io/trufnetwork/kwil-postgres:latest
host:indexer:start:
desc: Run the indexer
cmds:
- ./deployments/indexer/kwil-indexer run
# ─── compose ───────────────────────────────────────────────────────────────────
# Internal helper task to abstract docker-compose commands.
# It takes a list of compose FILES and an ACTION (like 'up -d' or 'down')
# and applies the action to each file in the list.
_compose:
internal: true
requires: { vars: [FILES, ACTION] }
# common deps
deps: [ build:binaries ] # Assuming 'build:binaries' fetches necessary external binaries
cmds:
- for: { var: FILES }
cmd: docker compose -f {{.ITEM}} {{.ACTION}}
single:env:
desc: Set environment variables for devnet
internal: true
env:
SETUP_DB_OWNER: "{{.DEV_DB_OWNER}}"
SETUP_CHAIN_ID: "{{.DEV_CHAIN_ID}}"
DB_OWNER: "{{.DEV_DB_OWNER}}"
CHAIN_ID: "{{.DEV_CHAIN_ID}}"
requires: { vars: [ DEV_DB_OWNER, DEV_CHAIN_ID ] }
single:start:
desc: Run docker-compose locally (single node stack)
deps: [ single:env, build:binaries ]
env:
SETUP_DB_OWNER: "{{.DEV_DB_OWNER}}"
SETUP_CHAIN_ID: "{{.DEV_CHAIN_ID}}"
DB_OWNER: "{{.DEV_DB_OWNER}}"
CHAIN_ID: "{{.DEV_CHAIN_ID}}"
cmds:
- sh -c 'docker compose -f compose.yaml up -d'
single:stop:
desc: Shutdown single node environment
deps: [ single:env ]
cmds:
- task: _compose
vars:
ACTION: down
FILES: { ref: .SINGLE_STACK_FILES }
# The devnet environment variables are set here and consumed by compose files.
devnet:env:
internal: true
env:
BACKENDS: "{{.DEV_NODE_1_ADDRESS}},{{.DEV_NODE_2_ADDRESS}}"
NODE_RPC_ENDPOINT: "{{.DEV_NODE_1_RPC_ENDPOINT}}"
SETUP_CHAIN_ID: "{{.DEV_CHAIN_ID}}"
SETUP_DB_OWNER: "{{.DEV_DB_OWNER}}"
CHAIN_ID: "{{.DEV_CHAIN_ID}}"
DB_OWNER: "{{.DEV_DB_OWNER}}"
requires: { vars: [ DEV_NODE_1_ADDRESS, DEV_NODE_2_ADDRESS, DEV_CHAIN_ID, DEV_DB_OWNER ] } # Added requires guard for all used vars
devnet:start:
desc: Run docker-compose locally with dev configuration, 2 nodes, gateway, and indexer services
deps: [ devnet:env, build:binaries ]
env:
SETUP_DB_OWNER: "{{.DEV_DB_OWNER}}"
SETUP_CHAIN_ID: "{{.DEV_CHAIN_ID}}"
DB_OWNER: "{{.DEV_DB_OWNER}}"
CHAIN_ID: "{{.DEV_CHAIN_ID}}"
BACKENDS: "{{.DEV_NODE_1_ADDRESS}},{{.DEV_NODE_2_ADDRESS}}"
NODE_RPC_ENDPOINT: "{{.DEV_NODE_1_RPC_ENDPOINT}}"
cmds:
- task: _compose
vars:
ACTION: up -d
FILES: { ref: .DEVNET_STACK_FILES }
devnet:stop:
desc: Shutdown dev 2 nodes, gateway, and indexer services
deps: [ devnet:env ]
env:
SETUP_DB_OWNER: "{{.DEV_DB_OWNER}}"
SETUP_CHAIN_ID: "{{.DEV_CHAIN_ID}}"
DB_OWNER: "{{.DEV_DB_OWNER}}"
CHAIN_ID: "{{.DEV_CHAIN_ID}}"
BACKENDS: "{{.DEV_NODE_1_ADDRESS}},{{.DEV_NODE_2_ADDRESS}}"
NODE_RPC_ENDPOINT: "{{.DEV_NODE_1_RPC_ENDPOINT}}"
cmds:
- task: _compose
vars:
ACTION: down
FILES: { ref: .DEVNET_STACK_FILES }
# These tasks use specific subsets of the devnet compose files (defined in vars)
# to allow starting/stopping individual components like the gateway or indexer.
devnet:gateway:start:
desc: The gateway is not needed for development. However, you might want to test its configuration.
deps: [ devnet:env, build:binaries ]
cmds:
- task: _compose
vars:
ACTION: up -d
FILES: { ref: .DEVNET_GATEWAY_FILES }
devnet:gateway:stop:
desc: Shutdown the gateway
deps: [ devnet:env ]
cmds:
- task: _compose
vars:
ACTION: down
FILES: { ref: .DEVNET_GATEWAY_FILES }
devnet:indexer:start:
desc: Run the indexer against local devnet
deps: [ devnet:env, build:binaries ]
cmds:
- task: _compose
vars:
ACTION: up -d
FILES: { ref: .DEVNET_INDEXER_FILES }
devnet:indexer:stop:
desc: Shutdown the indexer
deps: [ devnet:env ]
cmds:
- task: _compose
vars:
ACTION: down
FILES: { ref: .DEVNET_INDEXER_FILES }
devnet:observer:start:
desc: Run the observer development services (vector, prometheus, grafana)
deps: [ devnet:env ]
cmds:
- task: _compose
vars:
ACTION: up -d
FILES: { ref: .DEVNET_OBSERVER_FILES }
devnet:observer:stop:
desc: Shutdown the observer
deps: [ devnet:env ]
cmds:
- task: _compose
vars:
ACTION: down
FILES: { ref: .DEVNET_OBSERVER_FILES }
# ─── tools ───────────────────────────────────────────────────────────────────
tools:
desc: Install tools
cmds:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v2.2.1
- go install github.com/vektra/mockery/v2@v2.42.1
# ─── ci ───────────────────────────────────────────────────────────────────────
ci:cleanup:
desc: Cleanup any lingering Kwil DB containers/processes (for CI retries)
cmds:
- bash ./scripts/ci-cleanup.sh
mockery:
desc: Generate mocks
cmds:
- mockery --all
lint:
desc: Run linter
cmds:
- golangci-lint run
# ─── setup ───────────────────────────────────────────────────────────────────
# After generating the certs, you need to trust them in your local machine by running the task setup:local-cert (linux) or setup:local-cert-darwin (macOS)
# leave the fields empty and press enter to use the default values
setup:local-cert:
desc: Generate a new local cert
cmds:
- sudo openssl req -x509 -nodes -days 365 -addext "subjectAltName = DNS:localhost" -newkey rsa:2048 -keyout ./deployments/dev-gateway/certs/localhost.key -out ./deployments/dev-gateway/certs/localhost.crt
setup:trust-local-cert:
desc: Trust local certs for development
cmds:
- sudo cp ./deployments/dev-gateway/certs/localhost.crt /usr/local/share/ca-certificates/localhost.crt
- sudo update-ca-certificates
setup:local-cert-darwin:
desc: Trust local certs for development in Darwin
cmds:
- sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./deployments/dev-gateway/certs/localhost.crt
# ─── tests ───────────────────────────────────────────────────────────────────
test:unit:
desc: Run unit tests
cmds:
- go test ./internal/contracts/tests/...
coverage:
desc: Generate HTML & CLI coverage report via scripts/coverage.sh
cmds:
- bash ./scripts/coverage.sh
benchmark:
desc: Compile & run Go micro-benchmark suite, regenerating ./internal/benchmark report
cmds:
- go test -v -timeout 0 ./internal/benchmark
get-genesis:
desc: Pull genesis.json from truf-node-operator (needs READ_TOKEN in .env)
dotenv: ['.env']
cmds:
- |
curl -f -H "Authorization: token ${READ_TOKEN}" --create-dirs -o ./deployments/network/staging/genesis.json https://raw.githubusercontent.com/trufnetwork/truf-node-operator/main/configs/network/v2/genesis.json
# ─── actions ───────────────────────────────────────────────────────────────────
action:migrate:
desc: Run the migration action for all SQL files. Environment variables should be set in the environment.
vars:
PRIVATE_KEY: "{{.PRIVATE_KEY}}"
PROVIDER: "{{.PROVIDER}}"
cmds:
- bash ./scripts/migrate.sh
env:
PRIVATE_KEY: "{{.PRIVATE_KEY}}"
PROVIDER: "{{.PROVIDER}}"
SYNC: "{{.SYNC}}"
ADMIN_WALLET: "{{.ADMIN_WALLET}}"
requires: { vars: [PRIVATE_KEY, PROVIDER] }
action:migrate:dev:
desc: Run the migration action for all SQL files in a local network
vars:
PRIVATE_KEY: "0000000000000000000000000000000000000000000000000000000000000001"
PROVIDER: "http://localhost:8484"
cmds:
- task: action:migrate
vars:
PRIVATE_KEY: "{{.PRIVATE_KEY}}"
PROVIDER: "{{.PROVIDER}}"
ADMIN_WALLET: "{{.DEV_DB_OWNER}}"
- kwil-cli exec-action grant_roles text:system text:network_writer text[]:{{.DEV_DB_OWNER}} --private-key {{.PRIVATE_KEY}} --provider {{.PROVIDER}} --sync