forked from buildonspark/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
157 lines (144 loc) · 4.38 KB
/
docker-compose.yml
File metadata and controls
157 lines (144 loc) · 4.38 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
x-operator-common: &operator-common
image: spark-operator:local
pull_policy: never
depends_on:
postgres:
condition: service_healthy
bitcoin-init:
condition: service_completed_successfully
cert-init:
condition: service_completed_successfully
restart: unless-stopped
entrypoint: ["/bin/sh", "-c"]
volumes:
- ./docker/entrypoint.sh:/opt/spark/entrypoint.sh:ro
- ./docker/config.json:/opt/spark/config.json:ro
- ./docker/operator.config.yaml:/opt/spark/operator.config.yaml:ro
- ./docker/keys:/opt/spark/keys:ro
- tls-certs:/opt/spark/tls:ro
services:
cert-init:
image: alpine:3.20
restart: "no"
entrypoint: ["/bin/sh", "-c"]
command:
- |
set -e
apk add --no-cache openssl > /dev/null
for i in 0 1 2; do
KEY="/tls/server_$${i}.key"
CERT="/tls/server_$${i}.crt"
if [ -f "$$KEY" ] && [ -f "$$CERT" ]; then
echo "TLS key/cert for operator $$i already exist, skipping"
continue
fi
echo "Generating TLS key/cert for operator $$i..."
openssl genrsa -out "$$KEY" 2048 2>/dev/null
openssl req -new -x509 \
-key "$$KEY" -out "$$CERT" \
-days 3650 \
-subj "/CN=spark-operator-$${i}" \
-addext "subjectAltName = DNS:spark-operator-$${i},DNS:localhost"
done
echo "TLS certificates ready"
volumes:
- tls-certs:/tls
postgres:
image: postgres:16-bookworm
environment:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
- ./docker/init-databases.sh:/docker-entrypoint-initdb.d/init-databases.sh
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 2s
timeout: 5s
retries: 10
bitcoind:
image: lncm/bitcoind:v28.0
command:
- -conf=/bitcoin.conf
ports:
- "8332:8332"
- "28332:28332"
- "28333:28333"
volumes:
- bitcoind-data:/data/.bitcoin
- ./docker/bitcoin.conf:/bitcoin.conf:ro
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=testutil", "-rpcpassword=testutilpassword", "-rpcport=8332", "getblockchaininfo"]
interval: 2s
timeout: 5s
retries: 15
bitcoin-init:
image: lncm/bitcoind:v28.0
depends_on:
bitcoind:
condition: service_healthy
restart: "no"
entrypoint: ["/bin/sh", "-c"]
command:
- |
set -e
CLI="bitcoin-cli -regtest -rpcuser=testutil -rpcpassword=testutilpassword -rpcconnect=bitcoind -rpcport=8332"
# Create wallet if it doesn't exist
if ! $$CLI listwallets | grep -q default; then
$$CLI createwallet default false false '' false true
fi
# Fund wallet if balance is low (mine 101 blocks for maturity)
BALANCE=$$($$CLI -rpcwallet=default getbalance)
case "$$BALANCE" in
0|0.00000000) NEEDS_FUND=1 ;;
*) NEEDS_FUND=0 ;;
esac
if [ "$$NEEDS_FUND" = "1" ]; then
ADDRESS=$$($$CLI -rpcwallet=default getnewaddress)
$$CLI generatetoaddress 101 "$$ADDRESS" > /dev/null
echo "Funded wallet with 101 blocks"
fi
echo "Bitcoin wallet ready"
bitcoin-miner:
image: lncm/bitcoind:v28.0
depends_on:
bitcoin-init:
condition: service_completed_successfully
restart: unless-stopped
entrypoint: ["/bin/sh", "-c"]
command:
- |
CLI="bitcoin-cli -regtest -rpcuser=testutil -rpcpassword=testutilpassword -rpcconnect=bitcoind -rpcport=8332"
while true; do
ADDRESS=$$($$CLI -rpcwallet=default getnewaddress 2>&1) || { sleep 30; continue; }
$$CLI generatetoaddress 1 "$$ADDRESS" > /dev/null 2>&1 && \
echo "$$(date): Mined 1 block" || \
echo "$$(date): ERROR: Failed to mine block"
sleep 30
done
spark-operator-0:
<<: *operator-common
build:
context: .
dockerfile: Dockerfile
command:
- /opt/spark/entrypoint.sh 0
ports:
- "8535:8535"
spark-operator-1:
<<: *operator-common
command:
- /opt/spark/entrypoint.sh 1
ports:
- "8536:8535"
spark-operator-2:
<<: *operator-common
command:
- /opt/spark/entrypoint.sh 2
ports:
- "8537:8535"
volumes:
postgres-data:
bitcoind-data:
tls-certs: