-
Notifications
You must be signed in to change notification settings - Fork 0
327 lines (303 loc) · 13.1 KB
/
docker-publish.yml
File metadata and controls
327 lines (303 loc) · 13.1 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
name: Docker Publish
on:
push:
branches: [main]
tags: ["v*"]
jobs:
publish:
name: Build & Push Images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- image: settla-server
dockerfile: deploy/docker/settla-server.Dockerfile
- image: settla-node
dockerfile: deploy/docker/settla-node.Dockerfile
- image: settla-gateway
dockerfile: deploy/docker/gateway.Dockerfile
- image: settla-webhook
dockerfile: deploy/docker/webhook.Dockerfile
steps:
- uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/intellect4all/${{ matrix.image }}
tags: |
type=sha,prefix=
type=ref,event=branch
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
smoke-test:
name: Smoke Test
runs-on: ubuntu-latest
needs: [publish]
# Only run smoke tests on main branch pushes (not version tags which go to production)
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull published images
run: |
SHA=${{ github.sha }}
docker pull ghcr.io/intellect4all/settla-server:${SHA}
docker pull ghcr.io/intellect4all/settla-node:${SHA}
docker pull ghcr.io/intellect4all/settla-gateway:${SHA}
docker pull ghcr.io/intellect4all/settla-webhook:${SHA}
docker tag ghcr.io/intellect4all/settla-server:${SHA} settla-server:smoke
docker tag ghcr.io/intellect4all/settla-node:${SHA} settla-node:smoke
docker tag ghcr.io/intellect4all/settla-gateway:${SHA} settla-gateway:smoke
docker tag ghcr.io/intellect4all/settla-webhook:${SHA} settla-webhook:smoke
- name: Start infrastructure
run: |
docker network create settla-smoke
# Start postgres with the primary DB; additional DBs are created below.
docker run -d --name smoke-postgres \
--network settla-smoke \
-e POSTGRES_USER=settla \
-e POSTGRES_PASSWORD=settla \
-e POSTGRES_DB=settla_transfer \
postgres:16-alpine
docker run -d --name smoke-redis \
--network settla-smoke \
redis:7.2-alpine
docker run -d --name smoke-nats \
--network settla-smoke \
nats:2.10-alpine -js
# Wait for postgres to be ready before creating additional DBs.
for i in $(seq 1 30); do
if docker exec smoke-postgres pg_isready -U settla -d settla_transfer >/dev/null 2>&1; then
echo "postgres ready"
break
fi
sleep 1
done
docker exec smoke-postgres psql -U settla -c "CREATE DATABASE settla_ledger;"
docker exec smoke-postgres psql -U settla -c "CREATE DATABASE settla_treasury;"
- name: Run database migrations
run: |
# Run migrations by piping each *.up.sql file to psql in numeric order.
# We use the settla owner role (BYPASSRLS) so all RLS migrations work.
for DB in transfer ledger treasury; do
echo "=== Running migrations for settla_${DB} ==="
for f in $(ls db/migrations/${DB}/*.up.sql 2>/dev/null | sort -V); do
echo " applying: $f"
docker exec -i smoke-postgres psql -U settla -d "settla_${DB}" < "$f"
done
done
- name: Seed smoke test data
run: |
# API key: "sk_test_smoke_ci_key_lemfi_001"
# Key hash is SHA-256 of the raw key.
SMOKE_API_KEY="sk_test_smoke_ci_key_lemfi_001"
SMOKE_KEY_HASH=$(printf '%s' "$SMOKE_API_KEY" | sha256sum | awk '{print $1}')
echo "Seeding tenant with key_hash=${SMOKE_KEY_HASH:0:16}..."
# Seed Lemfi tenant in transfer DB
docker exec smoke-postgres psql -U settla -d settla_transfer -c "
INSERT INTO tenants (
id, name, slug, status, fee_schedule, settlement_model,
daily_limit_usd, per_transfer_limit, kyb_status, kyb_verified_at
) VALUES (
'a0000000-0000-0000-0000-000000000001',
'Lemfi Smoke', 'lemfi', 'ACTIVE',
'{\"on_ramp_bps\": 40, \"off_ramp_bps\": 35}',
'PREFUNDED',
9999999999.00, 1000000.00,
'VERIFIED', now()
) ON CONFLICT (id) DO NOTHING;
"
docker exec smoke-postgres psql -U settla -d settla_transfer -c "
INSERT INTO api_keys (
id, tenant_id, key_hash, key_prefix, environment, name, is_active
) VALUES (
gen_random_uuid(),
'a0000000-0000-0000-0000-000000000001',
'${SMOKE_KEY_HASH}',
'sk_test_smoke', 'TEST', 'smoke-ci', true
) ON CONFLICT (key_hash) DO NOTHING;
"
# Seed GBP treasury position for Lemfi in treasury DB
docker exec smoke-postgres psql -U settla -d settla_treasury -c "
INSERT INTO positions (
id, tenant_id, currency, location, balance, locked
) VALUES (
gen_random_uuid(),
'a0000000-0000-0000-0000-000000000001',
'GBP', 'bank:gbp',
999999999.00, 0.00
) ON CONFLICT (tenant_id, currency, location) DO NOTHING;
"
echo "Seed complete."
- name: Start settla-server
run: |
docker run -d --name smoke-server \
--network settla-smoke \
-p 8080:8080 \
-e SETTLA_ENV=test \
-e SETTLA_HTTP_PORT=8080 \
-e SETTLA_GRPC_PORT=9090 \
-e SETTLA_TRANSFER_DB_URL="postgres://settla:settla@smoke-postgres:5432/settla_transfer?sslmode=disable" \
-e SETTLA_LEDGER_DB_URL="postgres://settla:settla@smoke-postgres:5432/settla_ledger?sslmode=disable" \
-e SETTLA_TREASURY_DB_URL="postgres://settla:settla@smoke-postgres:5432/settla_treasury?sslmode=disable" \
-e SETTLA_REDIS_URL=smoke-redis:6379 \
-e SETTLA_NATS_URL=nats://smoke-nats:4222 \
-e SETTLA_TIGERBEETLE_ADDRESSES='' \
-e SETTLA_MOCK_PROVIDERS=true \
-e SETTLA_MOCK_DELAY_MS=1 \
settla-server:smoke || true
- name: Start settla-node
run: |
docker run -d --name smoke-node \
--network settla-smoke \
-e SETTLA_ENV=test \
-e SETTLA_TRANSFER_DB_URL="postgres://settla:settla@smoke-postgres:5432/settla_transfer?sslmode=disable" \
-e SETTLA_LEDGER_DB_URL="postgres://settla:settla@smoke-postgres:5432/settla_ledger?sslmode=disable" \
-e SETTLA_TREASURY_DB_URL="postgres://settla:settla@smoke-postgres:5432/settla_treasury?sslmode=disable" \
-e SETTLA_REDIS_URL=smoke-redis:6379 \
-e SETTLA_NATS_URL=nats://smoke-nats:4222 \
-e SETTLA_TIGERBEETLE_ADDRESSES='' \
-e SETTLA_MOCK_PROVIDERS=true \
-e SETTLA_MOCK_DELAY_MS=1 \
settla-node:smoke || true
- name: Start gateway
run: |
docker run -d --name smoke-gateway \
--network settla-smoke \
-p 3000:3000 \
-e NODE_ENV=test \
-e GATEWAY_PORT=3000 \
-e GRPC_SERVER_ADDRESS=smoke-server:9090 \
-e REDIS_URL=redis://smoke-redis:6379 \
settla-gateway:smoke || true
- name: Wait for services
run: |
echo "Waiting for settla-server..."
for i in $(seq 1 40); do
if curl -sf http://localhost:8080/health >/dev/null 2>&1; then
echo "settla-server healthy"
break
fi
sleep 2
done
echo "Waiting for gateway..."
for i in $(seq 1 40); do
if curl -sf http://localhost:3000/health >/dev/null 2>&1; then
echo "gateway healthy"
break
fi
sleep 2
done
- name: Health check — settla-server
run: |
STATUS=$(curl -sf -o /dev/null -w "%{http_code}" http://localhost:8080/health)
if [ "$STATUS" != "200" ]; then
echo "FAIL: settla-server /health returned HTTP $STATUS"
docker logs smoke-server
exit 1
fi
echo "PASS: settla-server /health returned 200"
- name: Health check — gateway
run: |
STATUS=$(curl -sf -o /dev/null -w "%{http_code}" http://localhost:3000/health)
if [ "$STATUS" != "200" ]; then
echo "FAIL: gateway /health returned HTTP $STATUS"
docker logs smoke-gateway
exit 1
fi
echo "PASS: gateway /health returned 200"
- name: Transfer smoke test — create and complete a GBP→NGN transfer
run: |
set -euo pipefail
SMOKE_API_KEY="sk_test_smoke_ci_key_lemfi_001"
GW="http://localhost:3000"
AUTH="Authorization: Bearer ${SMOKE_API_KEY}"
echo "--- Step 1: Create quote ---"
QUOTE_RESP=$(curl -sf -X POST "${GW}/v1/quotes" \
-H "${AUTH}" \
-H "Content-Type: application/json" \
-d '{"source_currency":"GBP","source_amount":"100","dest_currency":"NGN"}')
echo "Quote response: ${QUOTE_RESP}"
QUOTE_ID=$(echo "$QUOTE_RESP" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
if [ -z "$QUOTE_ID" ]; then
echo "FAIL: no quote ID in response"
exit 1
fi
echo "PASS: quote created — id=${QUOTE_ID}"
echo "--- Step 2: Create transfer ---"
IDEMPOTENCY_KEY="smoke-$(date +%s%N)"
TRANSFER_RESP=$(curl -sf -X POST "${GW}/v1/transfers" \
-H "${AUTH}" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: ${IDEMPOTENCY_KEY}" \
-d "{
\"quote_id\": \"${QUOTE_ID}\",
\"external_ref\": \"smoke-test-${IDEMPOTENCY_KEY}\",
\"sender\": {\"name\":\"Smoke Test\",\"country\":\"GB\"},
\"recipient\": {\"name\":\"Smoke Recipient\",\"country\":\"NG\",\"bank_name\":\"Test Bank\",\"account_number\":\"0123456789\"}
}")
echo "Transfer response: ${TRANSFER_RESP}"
TRANSFER_ID=$(echo "$TRANSFER_RESP" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
if [ -z "$TRANSFER_ID" ]; then
echo "FAIL: no transfer ID in response"
exit 1
fi
echo "PASS: transfer created — id=${TRANSFER_ID}"
echo "--- Step 3: Poll until COMPLETED (max 120s) ---"
DEADLINE=$(($(date +%s) + 120))
while [ "$(date +%s)" -lt "$DEADLINE" ]; do
STATUS_RESP=$(curl -sf "${GW}/v1/transfers/${TRANSFER_ID}" -H "${AUTH}")
TRANSFER_STATUS=$(echo "$STATUS_RESP" | python3 -c "import sys,json; print(json.load(sys.stdin).get('status','UNKNOWN'))")
echo " transfer status: ${TRANSFER_STATUS}"
if [ "$TRANSFER_STATUS" = "COMPLETED" ]; then
echo "PASS: transfer COMPLETED — smoke test passed"
exit 0
fi
if [ "$TRANSFER_STATUS" = "FAILED" ]; then
echo "FAIL: transfer entered FAILED state"
echo "Full response: ${STATUS_RESP}"
docker logs smoke-server 2>&1 | tail -50
docker logs smoke-node 2>&1 | tail -50
exit 1
fi
sleep 2
done
echo "FAIL: transfer did not reach COMPLETED within 120s (last status: ${TRANSFER_STATUS})"
docker logs smoke-server 2>&1 | tail -50
docker logs smoke-node 2>&1 | tail -50
exit 1
- name: Dump logs on failure
if: failure()
run: |
echo "=== smoke-server logs ===" && docker logs smoke-server 2>&1 || true
echo "=== smoke-node logs ===" && docker logs smoke-node 2>&1 || true
echo "=== smoke-gateway logs ===" && docker logs smoke-gateway 2>&1 || true
- name: Cleanup
if: always()
run: |
docker rm -f smoke-postgres smoke-redis smoke-nats smoke-gateway smoke-server smoke-node 2>/dev/null || true
docker network rm settla-smoke 2>/dev/null || true