Skip to content

Commit ae9facf

Browse files
authored
refactor(docker): use profiles and make the docker-compose more configurable (#659)
1 parent 97492f8 commit ae9facf

File tree

5 files changed

+604
-342
lines changed

5 files changed

+604
-342
lines changed

.github/workflows/docker-publish-bitcoin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
username: ${{ secrets.DOCKERHUB_USERNAME }}
3535
password: ${{ secrets.DOCKERHUB_TOKEN }}
3636

37-
- name: Build and push
37+
- name: Build and push base image
3838
uses: docker/build-push-action@v5
3939
with:
4040
context: .

.github/workflows/docker.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ jobs:
2222
- name: Test taker
2323
run: docker run --rm coinswap/coinswap:latest taker --help
2424

25-
- name: Start Coinswap stack
26-
run: ./docker-setup start --default
27-
2825
- name: Wait for services to be healthy
2926
run: |
3027
echo "Waiting for services to start..."

docker-compose.yml

Lines changed: 107 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,137 @@
11
services:
2+
bitcoind:
3+
image: coinswap/${BITCOIN_IMAGE_NAME:-bitcoin-mutinynet}:${BITCOIN_TAG:-latest}
4+
container_name: coinswap-bitcoind
5+
profiles: ["internal-bitcoind"]
6+
command: >
7+
bitcoind
8+
${BITCOIN_NETWORK_ARG}
9+
-rpcbind=0.0.0.0
10+
-rpcallowip=0.0.0.0/0
11+
ports:
12+
- "${BITCOIN_RPC_PORT:-38332}:${BITCOIN_RPC_PORT:-38332}"
13+
- "${BITCOIN_ZMQ_PORT:-28332}:${BITCOIN_ZMQ_PORT:-28332}"
14+
volumes:
15+
- bitcoin-data:/home/bitcoin/.bitcoin
16+
- ./docs/bitcoin.conf:/home/bitcoin/.bitcoin/bitcoin.conf:ro
17+
restart: unless-stopped
18+
healthcheck:
19+
test: ["CMD", "bitcoin-cli", "-rpcuser=${BITCOIN_RPC_USER:-user}", "-rpcpassword=${BITCOIN_RPC_PASSWORD:-password}", "-rpcport=${BITCOIN_RPC_PORT:-38332}", "getblockchaininfo"]
20+
interval: 30s
21+
timeout: 10s
22+
retries: 5
223

324
tor:
425
image: osminogin/tor-simple
5-
container_name: tor
6-
restart: unless-stopped
7-
ports:
8-
- "${TOR_SOCKS_PORT:-19050}:${TOR_SOCKS_PORT:-19050}"
9-
- "${TOR_CONTROL_PORT:-19051}:${TOR_CONTROL_PORT:-19051}"
10-
- "${MAKER_RPC_PORT:-6113}:${MAKER_RPC_PORT:-6113}"
26+
container_name: coinswap-tor
27+
profiles: ["internal-tor"]
28+
network_mode: "host"
29+
entrypoint: /bin/sh
30+
command:
31+
- -c
32+
- |
33+
HASH=$$(tor --hash-password "$${TOR_AUTH_PASSWORD}" | grep "^16:")
34+
35+
# use /tmp/torrc because the container runs as non-root and cannot write to /etc/tor/
36+
cat > /tmp/torrc << EOF
37+
SocksPort 0.0.0.0:$${TOR_SOCKS_PORT:-9050}
38+
ControlPort 0.0.0.0:$${TOR_CONTROL_PORT:-9051}
39+
DataDirectory /var/lib/tor
40+
HashedControlPassword $$HASH
41+
EOF
42+
echo "Starting Tor with the following configuration:"
43+
cat /tmp/torrc
44+
echo ""
45+
46+
exec tor -f /tmp/torrc
1147
volumes:
12-
- ./torrc:/etc/tor/torrc:ro
1348
- tor-data:/var/lib/tor
49+
ports:
50+
- "127.0.0.1:${TOR_SOCKS_PORT:-9050}:${TOR_SOCKS_PORT:-9050}"
51+
- "127.0.0.1:${TOR_CONTROL_PORT:-9051}:${TOR_CONTROL_PORT:-9051}"
52+
- "${MAKERD_RPC_PORT:-6103}:${MAKERD_RPC_PORT:-6103}"
53+
environment:
54+
- TOR_SOCKS_PORT=${TOR_SOCKS_PORT:-9050}
55+
- TOR_CONTROL_PORT=${TOR_CONTROL_PORT:-9051}
56+
- TOR_AUTH_PASSWORD=${TOR_AUTH_PASSWORD}
57+
restart: unless-stopped
1458

1559
makerd:
16-
image: coinswap/coinswap:master
60+
image: coinswap/${IMAGE_NAME:-coinswap}:latest
1761
container_name: coinswap-makerd
18-
network_mode: "service:tor"
19-
command:
62+
profiles: ["external-tor"]
63+
network_mode: "host"
64+
command: &makerd-command
2065
- sh
2166
- -c
2267
- |
2368
sleep 15
2469
mkdir -p /home/coinswap/.coinswap/maker
25-
printf '%s\n' \
26-
"network_port = ${MAKER_NETWORK_PORT:-6112}" \
27-
"rpc_port = ${MAKER_RPC_PORT:-6113}" \
28-
"socks_port = ${TOR_SOCKS_PORT:-19050}" \
29-
"control_port = ${TOR_CONTROL_PORT:-19051}" \
30-
"tor_auth_password = ${TOR_AUTH_PASSWORD:-coinswap}" \
31-
"min_swap_amount = ${MIN_SWAP_AMOUNT:-10000}" \
32-
"fidelity_amount = ${FIDELITY_AMOUNT:-50000}" \
33-
"fidelity_timelock = ${FIDELITY_TIMELOCK:-13104}" \
34-
"connection_type = TOR" \
35-
"base_fee = ${BASE_FEE:-100}" \
36-
"amount_relative_fee_ppt = ${AMOUNT_RELATIVE_FEE_PPT:-1000}" \
37-
> /home/coinswap/.coinswap/maker/config.toml
38-
makerd -w ${WALLET_NAME} -r ${BITCOIN_RPC_HOST:-172.81.178.3:48332} -a ${BITCOIN_RPC_AUTH:-user:password} --taproot
70+
71+
cat > /home/coinswap/.coinswap/maker/config.toml << EOM
72+
network_port = $${MAKER_NETWORK_PORT:-6102}
73+
rpc_port = $${MAKER_RPC_PORT:-6103}
74+
socks_port = $${TOR_SOCKS_PORT:-9050}
75+
control_port = $${TOR_CONTROL_PORT:-9051}
76+
tor_auth_password = "$${TOR_AUTH_PASSWORD}"
77+
min_swap_amount = $${MIN_SWAP_AMOUNT:-10000}
78+
fidelity_amount = $${FIDELITY_AMOUNT:-50000}
79+
fidelity_timelock = $${FIDELITY_TIMELOCK:-13104}
80+
connection_type = "TOR"
81+
base_fee = $${BASE_FEE:-100}
82+
amount_relative_fee_ppt = $${AMOUNT_RELATIVE_FEE_PPT:-1000}
83+
EOM
84+
85+
WALLET_NAME="$${BITCOIN_WALLET_NAME:-coinswap-maker}"
86+
echo "INFO: Using wallet: $$WALLET_NAME"
87+
88+
echo "[DEBUG] Running: makerd -t \"$${TOR_AUTH_PASSWORD}\" -r $${BITCOIN_RPC_HOST} -a $${BITCOIN_RPC_AUTH} $${MAKERD_EXTRA_ARGS} -w \"$$WALLET_NAME\""
89+
90+
makerd -t "$${TOR_AUTH_PASSWORD}" -r $${BITCOIN_RPC_HOST} -a $${BITCOIN_RPC_AUTH} $${MAKERD_EXTRA_ARGS} -w "$$WALLET_NAME"
91+
ports:
92+
- "${MAKERD_PORT:-6102}:${MAKERD_PORT:-6102}"
93+
- "${MAKERD_RPC_PORT:-6103}:${MAKERD_RPC_PORT:-6103}"
3994
volumes:
4095
- maker-data:/home/coinswap/.coinswap
41-
environment:
96+
environment: &makerd-env
4297
- RUST_LOG=${RUST_LOG:-info}
43-
- TOR_SOCKS_PORT=${TOR_SOCKS_PORT:-19050}
44-
- TOR_CONTROL_PORT=${TOR_CONTROL_PORT:-19051}
45-
- TOR_AUTH_PASSWORD=${TOR_AUTH_PASSWORD:-coinswap}
46-
- MAKER_NETWORK_PORT=${MAKER_NETWORK_PORT:-6112}
47-
- MAKER_RPC_PORT=${MAKER_RPC_PORT:-6113}
98+
- MAKER_NETWORK_PORT=${MAKERD_PORT:-6102}
99+
- MAKER_RPC_PORT=${MAKERD_RPC_PORT:-6103}
100+
- TOR_SOCKS_PORT=${TOR_SOCKS_PORT:-9050}
101+
- TOR_CONTROL_PORT=${TOR_CONTROL_PORT:-9051}
102+
- TOR_AUTH_PASSWORD=${TOR_AUTH_PASSWORD}
48103
- MIN_SWAP_AMOUNT=${MIN_SWAP_AMOUNT:-10000}
49104
- FIDELITY_AMOUNT=${FIDELITY_AMOUNT:-50000}
50105
- FIDELITY_TIMELOCK=${FIDELITY_TIMELOCK:-13104}
51106
- BASE_FEE=${BASE_FEE:-100}
52107
- AMOUNT_RELATIVE_FEE_PPT=${AMOUNT_RELATIVE_FEE_PPT:-1000}
53-
- BITCOIN_RPC_HOST=${BITCOIN_RPC_HOST:-172.81.178.3:48332}
108+
- BITCOIN_RPC_HOST=${BITCOIN_RPC_HOST}
54109
- BITCOIN_RPC_AUTH=${BITCOIN_RPC_AUTH:-user:password}
110+
- MAKERD_EXTRA_ARGS=${MAKERD_EXTRA_ARGS}
111+
- BITCOIN_WALLET_NAME=${BITCOIN_WALLET_NAME:-coinswap-maker}
55112
restart: unless-stopped
56113

114+
makerd-internal:
115+
image: coinswap/${IMAGE_NAME:-coinswap}:latest
116+
container_name: coinswap-makerd
117+
profiles: ["internal-tor"]
118+
network_mode: "host"
119+
command: *makerd-command
120+
volumes:
121+
- maker-data:/home/coinswap/.coinswap
122+
environment: *makerd-env
123+
restart: unless-stopped
124+
depends_on:
125+
- tor
126+
57127
volumes:
128+
bitcoin-data:
129+
driver: local
58130
tor-data:
59131
driver: local
60132
maker-data:
61133
driver: local
134+
135+
networks:
136+
default:
137+
name: coinswap-network

0 commit comments

Comments
 (0)