-
Notifications
You must be signed in to change notification settings - Fork 16
/
justfile
308 lines (249 loc) · 9.78 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
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
export RUST_LOG := "info"
export ROCKET_PROFILE := "test"
alias b := build
alias t := test
alias r := run
cargo := "cargo --locked"
[private]
default:
just --list
# Build all server deployable containers
server-deployable:
docker buildx bake server
# Build API deployable container
api-deployable:
docker buildx bake api
# Build WSM deployable containers
wsm-deployable:
docker buildx bake wsm
# Build the WSM nitro CLI container
nitro-cli:
docker buildx bake nitro-cli
# Build the WSM enclave eif image
wsm-enclave-eif:
docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $PWD/src/wsm/build:/build \
nitro-cli:latest \
sh -c "nitro-cli build-enclave --docker-uri wsm-enclave:latest \
--output-file /build/wsm-enclave.eif \
--private-key /usr/local/nitro-enclave-codesigning-key-staging.priv.pem \
--signing-certificate /usr/local/nitro-enclave-codesigning-cert-staging.pem || \
(cat /var/log/nitro_enclaves/*.log && exit 1)"
@echo Image created at $PWD/src/wsm/build/wsm-enclave.eif
# Start sidecars (inc. dynamodb, jaeger, mysql, ...) in background
sidecars:
docker compose -f docker-compose-sidecars.yml up --wait
src/wsm/scripts/setup_wsm_local_ddb.sh
curl -X DELETE -s -o /dev/null http://localhost:8001/tables-purge
# Stop sidecars
stop-sidecars:
docker compose -f docker-compose-sidecars.yml down
# Build all (inc. api, wsm, ...)
build:
{{cargo}} build --features partnerships
# Build all binaries
build-bins:
{{cargo}} build --bins --features partnerships
# Run DDB migrations locally
run-migrations:
ROCKET_CONFIG=src/api/Rocket.toml {{cargo}} run --bin server -- migrate
# Run all tests
test: sidecars
RUST_MIN_STACK=4194304 {{cargo}} nextest run --all-features
# Run all tests
test-ci: sidecars
RUST_MIN_STACK=4194304 {{cargo}} nextest run --all-features --profile ci
# Run server tests
test-server: sidecars
{{cargo}} test --exclude 'wsm*' --workspace
# Run wsm tests
test-wsm: sidecars
{{cargo}} test --package 'wsm*' --workspace
# Run specific tests
test-some path: sidecars
CARGO_LOG=debug {{cargo}} nextest run --all-features "{{path}}" --no-fail-fast
# Start sidecars and run the server in debug mode
run: sidecars run-server
# Run the server in debug mode
run-server *args:
#!/bin/bash
if [[ -z "$LAUNCHDARKLY_SDK_KEY" ]]; then
export LAUNCHDARKLY_SDK_KEY=$(AWS_PROFILE=bitkey-development--admin aws secretsmanager get-secret-value --region us-west-2 --secret-id fromagerie/launchdarkly/sdk_key | jq -r .SecretString)
fi
ROCKET_CONFIG=src/api/Rocket.toml ROCKET_PROFILE=debug {{cargo}} run --bin server --features partnerships -- server {{args}}
grind-signet-coins:
ROCKET_CONFIG=src/api/Rocket.toml {{cargo}} run --bin server -- cron coin-grinder
# Run the server in debug mode
migrate-from-unified-keysets:
ROCKET_CONFIG=src/api/Rocket.toml {{cargo}} run --bin server -- worker migrate-from-unified-keyset
revert-to-unified-keysets:
ROCKET_CONFIG=src/api/Rocket.toml {{cargo}} run --bin server -- worker revert-to-unified-keyset
# Run wsm-api in debug mode
run-wsm-api *args:
{{cargo}} run --bin wsm-api -- {{args}}
# Run wsm-enclave in debug mode
run-wsm-enclave *args:
{{cargo}} run --bin wsm-enclave -- {{args}}
[private]
clippy *args:
{{cargo}} clippy {{args}}
# Run the CI clippy lint commands
clippy-ci:
just clippy
# Format and lint
fmt:
{{cargo}} fmt --all
just clippy --fix --allow-dirty --allow-staged --all-features
# Run the CI format commands
fmt-ci:
just fmt
git diff --exit-code
# Multiple opentelemetry crates in the same object have caused propagation erros in the past. Assert the invariant
# that we should only have one.
cargo-lock-check:
matchcount=$(grep -c "name = \"opentelemetry\"" "Cargo.lock"); \
if [ $matchcount -gt 1 ]; then \
echo "Error: More than one opentelemetry crate. Check dependencies."; \
exit 1; \
fi
# Open VSCode
vscode:
code {{justfile_directory()}}
# Run the entire integrated server cluster (inc. api, wsm, ...)
run-integration: _integration
goreman start
# Start the integrated server cluster (inc. api, wsm, ...) in background
start-integration: _integration
nohup -- goreman start &
curl --fail --retry 10 --retry-all-errors http://localhost:8080
# Stop the integrated server cluster
stop-integration:
goreman run stop-all
# Create a named stack
stack-up stack_name=env_var('USER'):
./scripts/create_named_env.sh {{ stack_name }}
# Tear down a named stack
stack-down stack_name=env_var('USER'):
./scripts/tear_down_named_env.sh {{ stack_name }}
compose_file := "docker-compose-integration.yml"
compose_backends := "docker compose -f " + compose_file
start-backend $TAG="latest" $PRINT_LOGS="0":
#!/bin/bash
set -e
if [[ -z "$AWS_ACCESS_KEY_ID" ]]; then
echo "🔒 Logging into ECR"
AWS_PROFILE=bitkey-development--admin aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 000000000000.dkr.ecr.us-west-2.amazonaws.com
fi
export WALLET_API_IMAGE_REPO="000000000000.dkr.ecr.us-west-2.amazonaws.com/wallet-api"
export WSM_ENCLAVE_IMAGE_REPO="000000000000.dkr.ecr.us-west-2.amazonaws.com/wsm-enclave"
export WSM_API_IMAGE_REPO="000000000000.dkr.ecr.us-west-2.amazonaws.com/wsm-api"
echo "⬇️ Downloading images with tag \"$TAG\""
if [[ -z "$LAUNCHDARKLY_SDK_KEY" ]]; then
export LAUNCHDARKLY_SDK_KEY=$(AWS_PROFILE=bitkey-development--admin aws secretsmanager get-secret-value --region us-west-2 --secret-id fromagerie/launchdarkly/sdk_key | jq -r .SecretString)
fi
{{ compose_backends }} pull fromagerie wsm-enclave wsm-api
set +e
{{ compose_backends }} up --wait
status=$?
[[ "$PRINT_LOGS" -eq 1 ]] && {{ compose_backends }} logs
# If starting the containers failed, print debug instructions and exit
if [[ $status -ne 0 ]]; then
echo ""
echo "❌ Failed to start containers. View logs by running"
echo ""
echo " docker-compose -f $PWD/{{ compose_file }} logs"
echo ""
echo " View logs for a specific container by running"
echo ""
echo " docker-compose -f $PWD/{{ compose_file }} logs <container-name>"
exit 1
fi
set -e
just _setup-treasury
start-backend-local-build $PRINT_LOGS="0":
#!/bin/bash
set -e
echo "⚙️ Building images. This will take a while (>10 minutes)"
echo ""
docker buildx bake api wsm-api wsm-enclave
export WALLET_API_IMAGE_REPO="api"
export WSM_ENCLAVE_IMAGE_REPO="wsm-enclave"
export WSM_API_IMAGE_REPO="wsm-api"
export TAG="latest"
if [[ -z "$LAUNCHDARKLY_SDK_KEY" ]]; then
export LAUNCHDARKLY_SDK_KEY=$(AWS_PROFILE=bitkey-development--admin aws secretsmanager get-secret-value --region us-west-2 --secret-id fromagerie/launchdarkly/sdk_key | jq -r .SecretString)
fi
set +e
{{ compose_backends }} up --wait
status=$?
[[ "$PRINT_LOGS" -eq 1 ]] && {{ compose_backends }} logs
# If starting the containers failed, print debug instructions and exit
if [[ $status -ne 0 ]]; then
echo ""
echo "❌ Failed to start containers. View logs by running"
echo ""
echo " docker-compose -f $PWD/{{ compose_file }} logs"
echo ""
echo " View logs for a specific container by running"
echo ""
echo " docker-compose -f $PWD/{{ compose_file }} logs <container-name>"
exit 1
fi
set -e
just _setup-treasury
bitcoincli := "docker exec server-bitcoind-1 bitcoin-cli -regtest -rpcuser=test -rpcpassword=test"
_setup-treasury:
#!/bin/bash
echo "🔧 Setting up the treasury"
logfile=$(mktemp)
{{ bitcoincli }} -named createwallet wallet_name=testwallet blank=true >> $logfile 2>&1
status=$?
if [[ $status -eq 4 ]]; then
echo "✅ Treasury wallet already exists, skipping descriptor import"
echo "🔍 Loading wallet..."
{{ bitcoincli }} loadwallet testwallet
elif [[ $status -ne 0 ]]; then
echo "❌ Failed to create wallet"
cat $logfile
exit 1
else
{{ bitcoincli }} -rpcwallet=testwallet importdescriptors '[
{
"desc": "wpkh(tprv8h8PWPocKYoPkajXdGQhTwnqb9sSBiT6vGif5zJongZoAXKmWxkTcqZpRPNmtzzFojgN4k7DFdeMUY2cHFQCwEyQRyejXcs2RKjnbZTPMj3/84h/1h/0h/0/*)#hhlcx0nt",
"timestamp": "now",
"active": true,
"internal": false
},
{
"desc": "wpkh(tprv8h8PWPocKYoPkajXdGQhTwnqb9sSBiT6vGif5zJongZoAXKmWxkTcqZpRPNmtzzFojgN4k7DFdeMUY2cHFQCwEyQRyejXcs2RKjnbZTPMj3/84h/1h/0h/1/*)#xr6em6rn",
"timestamp": "now",
"active": true,
"internal": true
}
]' >> $logfile
[[ $? -ne 0 ]] && echo "❌ Failed to import descriptors" && cat $logfile && exit 1 || true
echo "✅ Created treasury wallet"
fi
addr=$({{ bitcoincli }} -rpcwallet=testwallet getnewaddress | xargs)
echo "⛏️ Mining 101 blocks to the treasury address \"$addr\""
{{ bitcoincli }} generatetoaddress 101 $addr >> $logfile
[[ $? -ne 0 ]] && echo "❌ Failed to mine a block" && cat $logfile && exit 1 || true
stop-backend:
{{ compose_backends }} down --volumes --timeout=1
get-regtest-funds address amount:
{{ bitcoincli }} -named sendtoaddress address={{ address }} amount={{ amount }} fee_rate=1
@echo
@echo sent {{ amount }} BTC to {{ address }}
_run-wsm-enclave $ROCKET_ADDRESS="localhost" $ROCKET_PORT="7446":
cd src/wsm && ../../target/debug/wsm-enclave
_run-wsm-api $ROCKET_PORT="9090" $AWS_DEFAULT_REGION="us-west-2" $AWS_ACCESS_KEY_ID="fakeKeyId" $AWS_SECRET_ACCESS_KEY="fakeSecretAccessKey":
cd src/wsm && ../../target/debug/wsm-api
_run-api $ROCKET_PORT="8080" $ROCKET_PROFILE="localprod":
#!/bin/bash
set -e
if [[ -z "$LAUNCHDARKLY_SDK_KEY" ]]; then
export LAUNCHDARKLY_SDK_KEY=$(AWS_PROFILE=bitkey-development--admin aws secretsmanager get-secret-value --region us-west-2 --secret-id fromagerie/launchdarkly/sdk_key | jq -r .SecretString)
fi
cd src/api && ../../target/debug/server server
_integration: build-bins sidecars