Start isolated docker setup.

This commit is contained in:
tecnovert 2020-12-27 21:39:10 +02:00
parent a6ead83fd2
commit d2ded157f8
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
20 changed files with 332 additions and 42 deletions

View file

@ -576,6 +576,7 @@ class BasicSwap(BaseApp):
if self.coin_clients[coin]['connection_type'] == 'rpc':
if coin == Coins.XMR:
self.coin_clients[coin]['walletrpchost'] = chain_client_settings.get('walletrpchost', 'localhost')
self.coin_clients[coin]['walletrpcport'] = chain_client_settings.get('walletrpcport', chainparams[coin][self.chain]['walletrpcport'])
if 'walletrpcpassword' in chain_client_settings:
self.coin_clients[coin]['walletrpcauth'] = (chain_client_settings['walletrpcuser'], chain_client_settings['walletrpcpassword'])

View file

@ -113,7 +113,7 @@ class BTCInterface(CoinInterface):
def __init__(self, coin_settings, network):
super().__init__()
self.rpc_callback = make_rpc_func(coin_settings['rpcport'], coin_settings['rpcauth'])
self.rpc_callback = make_rpc_func(coin_settings['rpcport'], coin_settings['rpcauth'], host=coin_settings['rpchost'])
self.txoType = CTxOut
self._network = network
self.blocks_confirmed = coin_settings['blocks_confirmed']

View file

@ -32,7 +32,7 @@ class PARTInterface(BTCInterface):
return 0xa0
def __init__(self, coin_settings, network):
self.rpc_callback = make_rpc_func(coin_settings['rpcport'], coin_settings['rpcauth'])
self.rpc_callback = make_rpc_func(coin_settings['rpcport'], coin_settings['rpcauth'], host=coin_settings['rpchost'])
self.txoType = CTxOutPart
self._network = network
self.blocks_confirmed = coin_settings['blocks_confirmed']

View file

@ -91,9 +91,9 @@ class Jsonrpc():
raise
def callrpc(rpc_port, auth, method, params=[], wallet=None):
def callrpc(rpc_port, auth, method, params=[], wallet=None, host='127.0.0.1'):
try:
url = 'http://%s@127.0.0.1:%d/' % (auth, rpc_port)
url = 'http://{}@{}:{}/'.format(auth, host, rpc_port)
if wallet is not None:
url += 'wallet/' + urllib.parse.quote(wallet)
x = Jsonrpc(url)
@ -129,12 +129,13 @@ def callrpc_cli(bindir, datadir, chain, cmd, cli_bin='particl-cli'):
return r
def make_rpc_func(port, auth, wallet=None):
def make_rpc_func(port, auth, wallet=None, host='127.0.0.1'):
port = port
auth = auth
wallet = wallet
host = host
def rpc_func(method, params=None, wallet_override=None):
nonlocal port, auth, wallet
return callrpc(port, auth, method, params, wallet if wallet_override is None else wallet_override)
nonlocal port, auth, wallet, host
return callrpc(port, auth, method, params, wallet if wallet_override is None else wallet_override, host)
return rpc_func

View file

@ -4,10 +4,10 @@ import json
import requests
def callrpc_xmr(rpc_port, auth, method, params=[], path='json_rpc'):
def callrpc_xmr(rpc_port, auth, method, params=[], rpc_host='127.0.0.1', path='json_rpc'):
# auth is a tuple: (username, password)
try:
url = 'http://127.0.0.1:{}/{}'.format(rpc_port, path)
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, path)
request_body = {
'method': method,
'params': params,
@ -51,20 +51,6 @@ def callrpc_xmr_na(rpc_port, method, params=[], rpc_host='127.0.0.1', path='json
return r['result']
def callrpc_xmr2(rpc_port, method, params=[]):
try:
url = 'http://127.0.0.1:{}/{}'.format(rpc_port, method)
headers = {
'content-type': 'application/json'
}
p = requests.post(url, data=json.dumps(params), headers=headers)
r = json.loads(p.text)
except Exception as ex:
raise ValueError('RPC Server Error: {}'.format(str(ex)))
return r
def make_xmr_rpc_func(port, host='127.0.0.1'):
port = port
host = host
@ -76,11 +62,12 @@ def make_xmr_rpc_func(port, host='127.0.0.1'):
return rpc_func
def make_xmr_wallet_rpc_func(port, auth):
def make_xmr_wallet_rpc_func(port, auth, host='127.0.0.1'):
port = port
auth = auth
host = host
def rpc_func(method, params=None, wallet=None):
nonlocal port, auth
return callrpc_xmr(port, auth, method, params)
nonlocal port, auth, host
return callrpc_xmr(port, auth, method, params, rpc_host=host)
return rpc_func

View file

@ -54,6 +54,7 @@ XMR_RPC_HOST = os.getenv('XMR_RPC_HOST', 'localhost')
BASE_XMR_RPC_PORT = int(os.getenv('BASE_XMR_RPC_PORT', 29798))
BASE_XMR_ZMQ_PORT = int(os.getenv('BASE_XMR_ZMQ_PORT', 30898))
BASE_XMR_WALLET_PORT = int(os.getenv('BASE_XMR_WALLET_PORT', 29998))
XMR_WALLET_RPC_HOST = os.getenv('XMR_WALLET_RPC_HOST', 'localhost')
XMR_WALLET_RPC_USER = os.getenv('XMR_WALLET_RPC_USER', 'xmr_wallet_user')
XMR_WALLET_RPC_PWD = os.getenv('XMR_WALLET_RPC_PWD', 'xmr_wallet_pwd')
XMR_SITE_COMMIT = 'db495b958f1fc6abfdfdb0a6756d902d59d9d21e' # Lock hashes.txt to monero version
@ -61,6 +62,12 @@ XMR_SITE_COMMIT = 'db495b958f1fc6abfdfdb0a6756d902d59d9d21e' # Lock hashes.txt
DEFAULT_XMR_RESTORE_HEIGHT = 2245107
PART_RPC_HOST = os.getenv('PART_RPC_HOST', 'localhost')
LTC_RPC_HOST = os.getenv('LTC_RPC_HOST', 'localhost')
BTC_RPC_HOST = os.getenv('BTC_RPC_HOST', 'localhost')
NMC_RPC_HOST = os.getenv('NMC_RPC_HOST', 'localhost')
def make_reporthook():
read = 0 # Number of bytes read so far
last_percent_str = ''
@ -256,7 +263,7 @@ def prepareCore(coin, version, settings, data_dir):
extractCore(coin, version, settings, bin_dir, release_path)
def prepareDataDir(coin, settings, data_dir, chain, particl_mnemonic):
def prepareDataDir(coin, settings, chain, particl_mnemonic):
core_settings = settings['chainclients'][coin]
data_dir = core_settings['datadir']
@ -350,6 +357,7 @@ def printHelp():
logger.info('--addcoin= Add coin to existing setup.')
logger.info('--disablecoin= Make coin inactive.')
logger.info('--preparebinonly Don\'t prepare settings or datadirs.')
logger.info('--nocores Don\'t download and extract any coin clients.')
logger.info('--portoffset=n Raise all ports by n.')
logger.info('--htmlhost= Interface to host on, default:localhost.')
logger.info('--xmrrestoreheight=n Block height to restore Monero wallet from, default:{}.'.format(DEFAULT_XMR_RESTORE_HEIGHT))
@ -383,6 +391,7 @@ def main():
chain = 'mainnet'
particl_wallet_mnemonic = None
prepare_bin_only = False
no_cores = False
with_coins = {'particl', 'litecoin'}
add_coin = ''
disable_coin = ''
@ -417,6 +426,9 @@ def main():
if name == 'preparebinonly':
prepare_bin_only = True
continue
if name == 'nocores':
no_cores = True
continue
if len(s) == 2:
if name == 'datadir':
data_dir = os.path.expanduser(s[1].strip('"'))
@ -483,9 +495,10 @@ def main():
chainclients = {
'particl': {
'connection_type': 'rpc',
'manage_daemon': True,
'manage_daemon': True if ('particl' in with_coins and PART_RPC_HOST == 'localhost') else False,
'rpchost': PART_RPC_HOST,
'rpcport': 19792 + port_offset,
'datadir': os.path.join(data_dir, 'particl'),
'datadir': os.getenv('PART_DATA_DIR', os.path.join(data_dir, 'particl')),
'bindir': os.path.join(bin_dir, 'particl'),
'blocks_confirmed': 2,
'override_feerate': 0.002,
@ -495,9 +508,10 @@ def main():
},
'litecoin': {
'connection_type': 'rpc' if 'litecoin' in with_coins else 'none',
'manage_daemon': True if 'litecoin' in with_coins else False,
'manage_daemon': True if ('litecoin' in with_coins and LTC_RPC_HOST == 'localhost') else False,
'rpchost': LTC_RPC_HOST,
'rpcport': 19795 + port_offset,
'datadir': os.path.join(data_dir, 'litecoin'),
'datadir': os.getenv('LTC_DATA_DIR', os.path.join(data_dir, 'litecoin')),
'bindir': os.path.join(bin_dir, 'litecoin'),
'use_segwit': True,
'blocks_confirmed': 2,
@ -507,9 +521,10 @@ def main():
},
'bitcoin': {
'connection_type': 'rpc' if 'bitcoin' in with_coins else 'none',
'manage_daemon': True if 'bitcoin' in with_coins else False,
'manage_daemon': True if ('bitcoin' in with_coins and BTC_RPC_HOST == 'localhost') else False,
'rpchost': BTC_RPC_HOST,
'rpcport': 19796 + port_offset,
'datadir': os.path.join(data_dir, 'bitcoin'),
'datadir': os.getenv('BTC_DATA_DIR', os.path.join(data_dir, 'bitcoin')),
'bindir': os.path.join(bin_dir, 'bitcoin'),
'use_segwit': True,
'blocks_confirmed': 1,
@ -519,9 +534,10 @@ def main():
},
'namecoin': {
'connection_type': 'rpc' if 'namecoin' in with_coins else 'none',
'manage_daemon': True if 'namecoin' in with_coins else False,
'manage_daemon': True if ('namecoin' in with_coins and NMC_RPC_HOST == 'localhost') else False,
'rpchost': NMC_RPC_HOST,
'rpcport': 19798 + port_offset,
'datadir': os.path.join(data_dir, 'namecoin'),
'datadir': os.getenv('NMC_DATA_DIR', os.path.join(data_dir, 'namecoin')),
'bindir': os.path.join(bin_dir, 'namecoin'),
'use_segwit': False,
'use_csv': False,
@ -533,15 +549,16 @@ def main():
'monero': {
'connection_type': 'rpc' if 'monero' in with_coins else 'none',
'manage_daemon': True if ('monero' in with_coins and XMR_RPC_HOST == 'localhost') else False,
'manage_wallet_daemon': True if 'monero' in with_coins else False,
'manage_wallet_daemon': True if ('monero' in with_coins and XMR_WALLET_RPC_HOST == 'localhost') else False,
'rpcport': BASE_XMR_RPC_PORT + port_offset,
'zmqport': BASE_XMR_ZMQ_PORT + port_offset,
'walletrpcport': BASE_XMR_WALLET_PORT + port_offset,
'rpchost': XMR_RPC_HOST,
'walletrpchost': XMR_WALLET_RPC_HOST,
'walletrpcuser': XMR_WALLET_RPC_USER,
'walletrpcpassword': XMR_WALLET_RPC_PWD,
'walletfile': 'swap_wallet',
'datadir': os.path.join(data_dir, 'monero'),
'datadir': os.getenv('XMR_DATA_DIR', os.path.join(data_dir, 'monero')),
'bindir': os.path.join(bin_dir, 'monero'),
'restore_height': xmr_restore_height,
'blocks_confirmed': 7, # TODO: 10?
@ -587,10 +604,11 @@ def main():
settings['chainclients'][add_coin] = chainclients[add_coin]
prepareCore(add_coin, known_coins[add_coin], settings, data_dir)
if not no_cores:
prepareCore(add_coin, known_coins[add_coin], settings, data_dir)
if not prepare_bin_only:
prepareDataDir(add_coin, settings, data_dir, chain, particl_wallet_mnemonic)
prepareDataDir(add_coin, settings, chain, particl_wallet_mnemonic)
with open(config_path, 'w') as fp:
json.dump(settings, fp, indent=4)
@ -624,15 +642,16 @@ def main():
'check_expired_seconds': 60
}
for c in with_coins:
prepareCore(c, known_coins[c], settings, data_dir)
if not no_cores:
for c in with_coins:
prepareCore(c, known_coins[c], settings, data_dir)
if prepare_bin_only:
logger.info('Done.')
return 0
for c in with_coins:
prepareDataDir(c, settings, data_dir, chain, particl_wallet_mnemonic)
prepareDataDir(c, settings, chain, particl_wallet_mnemonic)
with open(config_path, 'w') as fp:
json.dump(settings, fp, indent=4)

1
docker/production/.env Normal file
View file

@ -0,0 +1 @@
HTML_PORT=127.0.0.1:12700:12700

View file

@ -0,0 +1,26 @@
# https://github.com/NicolasDorier/docker-bitcoin/blob/master/README.md
FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=bitcoin --withoutcoins=particl,litecoin
FROM debian:buster-slim
COPY --from=install_stage /coin_bin .
ENV BITCOIN_DATA /data
RUN groupadd -r bitcoin && useradd -r -m -g bitcoin bitcoin \
&& apt-get update \
&& apt-get install -qq --no-install-recommends gosu \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir "$BITCOIN_DATA" \
&& chown -R bitcoin:bitcoin "$BITCOIN_DATA" \
&& ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin \
&& chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin
VOLUME /data
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8332 8333 18332 18333 18443 18444
CMD ["bitcoind"]

View file

@ -0,0 +1,11 @@
#!/bin/bash
set -e
if [[ "$1" == "bitcoin-cli" || "$1" == "bitcoin-tx" || "$1" == "bitcoind" || "$1" == "test_bitcoin" ]]; then
mkdir -p "$BITCOIN_DATA"
chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin
exec gosu bitcoin "$@"
else
exec "$@"
fi

View file

@ -0,0 +1,70 @@
version: '3.3'
services:
particl_core:
image: i_particl
build:
context: particl
dockerfile: Dockerfile
container_name: particl_core
volumes:
- /var/swapdata/particl:/data
ports:
- "51738:51738"
expose:
- 51735
restart: unless-stopped
bitcoin_core:
image: i_bitcoin
build:
context: bitcoin
dockerfile: Dockerfile
container_name: bitcoin_core
volumes:
- /var/swapdata/bitcoin:/data
ports:
- "8333:8333"
expose:
- 8332
restart: unless-stopped
#monero_daemon:
#image: i_monero_daemon
#build:
#context: monero_daemon
#dockerfile: Dockerfile
#container_name: monero_daemon
#volumes:
#- /var/swapdata/monero_daemon:/data
#ports:
#- "18080:18080"
#expose:
#- 8332
#restart: unless-stopped
monero_wallet:
image: i_monero_wallet
build:
context: monero_wallet
dockerfile: Dockerfile
container_name: monero_wallet
volumes:
- /var/swapdata/monero_wallet:/data
expose:
- 8332
restart: unless-stopped
swapclient:
image: i_swapclient
build:
context: swapclient
dockerfile: Dockerfile
container_name: swapclient
volumes:
- /var/swapdata/swapclient:/data
ports:
- "${HTML_PORT}" # Expose only to localhost, see .env
depends_on:
- particl_core
restart: unless-stopped
networks:
default:
external:
name: coinswap_network

View file

@ -0,0 +1,24 @@
FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=litecoin --withoutcoin=particl
FROM debian:buster-slim
COPY --from=install_stage /coin_bin .
ENV LITECOIN_DATA /data
RUN groupadd -r particl && useradd -r -m -g litecoin litecoin \
&& apt-get update \
&& apt-get install -qq --no-install-recommends gosu \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir "$LITECOIN_DATA" \
&& chown -R litecoin:litecoin "$LITECOIN_DATA" \
&& ln -sfn "$LITECOIN_DATA" /home/litecoin/.litecoin \
&& chown -h litecoin:litecoin /home/litecoin/.litecoin
VOLUME /data
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8332 8333 18332 18333 18443 18444
CMD ["litecoind"]

View file

@ -0,0 +1,11 @@
#!/bin/bash
set -e
if [[ "$1" == "litecoin-cli" || "$1" == "litecoin-tx" || "$1" == "litecoind" || "$1" == "test_litecoin" ]]; then
mkdir -p "$LITECOIN_DATA"
chown -h litecoin:litecoin /home/litecoin/.litecoin
exec gosu litecoin "$@"
else
exec "$@"
fi

View file

@ -0,0 +1,25 @@
FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=monero --withoutcoins=particl,litecoin
FROM debian:buster-slim
COPY --from=install_stage /coin_bin .
ENV MONERO_DATA /data
RUN groupadd -r monero && useradd -r -m -g monero monero \
&& apt-get update \
&& apt-get install -qq --no-install-recommends gosu \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p "$MONERO_DATA" \
&& chown -R monero:monero "$MONERO_DATA" \
&& ln -sfn "$MONERO_DATA" /home/monero/.monero \
&& chown -h monero:monero /home/monero/.monero
VOLUME $MONERO_DATA
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 18080
CMD ["monerod", "--config-file=/home/monero/.monero/monerod.conf"]

View file

@ -0,0 +1,11 @@
#!/bin/bash
set -e
if [[ "$1" == "monerod" ]]; then
mkdir -p "$MONERO_DATA"
chown -h monero:monero /home/monero/.monero
exec gosu monero "$@"
else
exec "$@"
fi

View file

@ -0,0 +1,19 @@
FROM i_monero_daemon
ENV MONERO_DATA /data
RUN groupadd -r monero && useradd -r -m -g monero monero \
&& apt-get update \
&& apt-get install -qq --no-install-recommends gosu \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p "$MONERO_DATA" \
&& chown -R monero:monero "$MONERO_DATA" \
&& ln -sfn "$MONERO_DATA" /home/monero/.monero \
&& chown -h monero:monero /home/monero/.monero
VOLUME $MONERO_DATA
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 18080
CMD ["monero-wallet-rpc", "--config-file=/home/monero/.monero/monerod.conf"]

View file

@ -0,0 +1,11 @@
#!/bin/bash
set -e
if [[ "$1" == "monerod" ]]; then
mkdir -p "$MONERO_DATA"
chown -h monero:monero /home/monero/.monero
exec gosu monero "$@"
else
exec "$@"
fi

View file

@ -0,0 +1,24 @@
FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=particl --withoutcoin=litecoin
FROM debian:buster-slim
COPY --from=install_stage /coin_bin .
ENV PARTICL_DATA /data
RUN groupadd -r particl && useradd -r -m -g particl particl \
&& apt-get update \
&& apt-get install -qq --no-install-recommends gosu \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p "$PARTICL_DATA" \
&& chown -R particl:particl "$PARTICL_DATA" \
&& ln -sfn "$PARTICL_DATA" /home/particl/.particl \
&& chown -h particl:particl /home/particl/.particl
VOLUME /data
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 51735 20792 51738
CMD ["particld"]

View file

@ -0,0 +1,11 @@
#!/bin/bash
set -e
if [[ "$1" == "particl-cli" || "$1" == "particl-tx" || "$1" == "particld" || "$1" == "test_particl" ]]; then
mkdir -p "$PARTICL_DATA"
chown -h particl:particl /home/particl/.particl
exec gosu particl "$@"
else
exec "$@"
fi

View file

@ -0,0 +1,32 @@
FROM debian:buster-slim
ENV LANG=C.UTF-8 \
DEBIAN_FRONTEND=noninteractive \
DATADIR=/data
RUN apt-get update; \
apt-get install -y wget python3-pip gnupg unzip protobuf-compiler automake libtool pkg-config gosu;
RUN wget -O coincurve-anonswap.zip https://github.com/tecnovert/coincurve/archive/anonswap.zip && \
unzip coincurve-anonswap.zip && \
cd coincurve-anonswap && \
python3 setup.py install --force
RUN wget -O basicswap-master.zip https://github.com/tecnovert/basicswap/archive/master.zip; \
unzip basicswap-master.zip; \
cd basicswap-master; \
protoc -I=basicswap --python_out=basicswap basicswap/messages.proto; \
pip3 install .;
RUN useradd -ms /bin/bash swap_user && \
mkdir /data && chown swap_user -R /data
# Expose html port
EXPOSE 12700
VOLUME /data
COPY ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["basicswap-run", "-datadir=/data"]

View file

@ -0,0 +1,6 @@
#!/bin/bash
set -e
chown -R swap_user "$DATADIR"
exec gosu swap_user "$@"