-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yaml
More file actions
162 lines (149 loc) · 5.09 KB
/
Copy pathdocker-compose.yaml
File metadata and controls
162 lines (149 loc) · 5.09 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
services:
# ============================================================================
# SETUP SERVICE (Ephemeral)
# ============================================================================
# This service runs once to generate keys and configuration files for the
# cluster. It saves them to the shared 'witness-config' volume.
setup:
build:
context: .
target: witness-node
volumes:
- witness-config:/data
entrypoint: ["/bin/bash", "-c"]
# Script to generate keys for 3 witnesses and create network.json
command:
- |
if [ -f /data/network.json ]; then
echo "✅ Configuration already exists. Skipping setup."
exit 0
fi
echo "🔧 Generating Witness Keys..."
# Helper to generate node config and return pubkey,auth token
gen_config() {
ID=$1
# Generate keypair using the binary
OUT=$$(witness-node --generate-key)
PRIV=$$(echo "$$OUT" | grep "Private key:" | awk '{print $$3}')
PUB=$$(echo "$$OUT" | grep "Public key:" | awk '{print $$3}')
TOKEN=$$(od -An -N32 -tx1 /dev/urandom | tr -d ' \n')
# Write Node Config
echo "{\"id\": \"witness-$$ID\", \"private_key\": \"$$PRIV\", \"port\": 3000, \"host\": \"0.0.0.0\", \"network_id\": \"docker-net\", \"max_clock_skew\": 300, \"signing_auth_token\": \"$$TOKEN\"}" > /data/witness$$ID.json
echo "$$PUB,$$TOKEN"
}
W1=$$(gen_config 1)
W2=$$(gen_config 2)
W3=$$(gen_config 3)
IFS=',' read -r PUB1 TOKEN1 <<< "$$W1"
IFS=',' read -r PUB2 TOKEN2 <<< "$$W2"
IFS=',' read -r PUB3 TOKEN3 <<< "$$W3"
echo "📝 Creating network.json..."
cat > /data/network.json <<EOF
{
"id": "docker-net",
"threshold": 2,
"witnesses": [
{ "id": "witness-1", "pubkey": "$$PUB1", "endpoint": "http://witness-1:3000", "auth_token": "$$TOKEN1" },
{ "id": "witness-2", "pubkey": "$$PUB2", "endpoint": "http://witness-2:3000", "auth_token": "$$TOKEN2" },
{ "id": "witness-3", "pubkey": "$$PUB3", "endpoint": "http://witness-3:3000", "auth_token": "$$TOKEN3" }
],
"federation_peers": [],
"external_anchors": { "enabled": false, "providers": [] }
}
EOF
echo "✅ Setup complete."
# ============================================================================
# WITNESS NODES
# ============================================================================
witness-1:
build:
context: .
target: witness-node
depends_on:
setup:
condition: service_completed_successfully
volumes:
- witness-config:/data
command: ["witness-node", "--config", "/data/witness1.json", "--host", "0.0.0.0"]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 5s
networks:
- witness-net
witness-2:
build:
context: .
target: witness-node
depends_on:
setup:
condition: service_completed_successfully
volumes:
- witness-config:/data
command: ["witness-node", "--config", "/data/witness2.json", "--host", "0.0.0.0"]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 5s
networks:
- witness-net
witness-3:
build:
context: .
target: witness-node
depends_on:
setup:
condition: service_completed_successfully
volumes:
- witness-config:/data
command: ["witness-node", "--config", "/data/witness3.json", "--host", "0.0.0.0"]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 5s
networks:
- witness-net
# ============================================================================
# GATEWAY
# ============================================================================
gateway:
build:
context: .
target: witness-gateway
depends_on:
setup:
condition: service_completed_successfully
witness-1:
condition: service_healthy
witness-2:
condition: service_healthy
witness-3:
condition: service_healthy
ports:
- "8080:8080"
volumes:
- witness-config:/config
- gateway-data:/data
environment:
- RUST_LOG=info,witness_gateway=debug
# Point config to the shared volume, and db to the persistence volume
command: ["witness-gateway", "--config", "/config/network.json", "--host", "0.0.0.0", "--port", "8080", "--database", "/data/gateway.db"]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 10s
networks:
- witness-net
volumes:
witness-config: # Shared keys and network.json
gateway-data: # SQLite database persistence
networks:
witness-net: