preparescript: Support production docker config.

2024-05-20_merge
tecnovert 4 years ago
parent 398ef268a6
commit 2be16465fb
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 2
      basicswap/__init__.py
  2. 16
      basicswap/basicswap.py
  3. 47
      bin/basicswap_prepare.py
  4. 20
      docker/production/.env
  5. 1
      docker/production/.gitignore
  6. 5
      docker/production/bitcoin/Dockerfile
  7. 118
      docker/production/docker-compose.yml
  8. 21
      docker/production/example.env
  9. 7
      docker/production/litecoin/Dockerfile
  10. 8
      docker/production/monero_wallet/Dockerfile
  11. 6
      docker/production/monero_wallet/entrypoint.sh
  12. 5
      docker/production/particl/Dockerfile
  13. 1
      docker/production/swapclient/.gitignore
  14. 7
      docker/production/swapclient/Dockerfile

@ -1,3 +1,3 @@
name = "basicswap" name = "basicswap"
__version__ = "0.0.18" __version__ = "0.0.19"

@ -729,13 +729,17 @@ class BasicSwap(BaseApp):
if c == Coins.PART: if c == Coins.PART:
self.coin_clients[c]['have_spent_index'] = ci.haveSpentIndex() self.coin_clients[c]['have_spent_index'] = ci.haveSpentIndex()
# Sanity checks try:
rv = self.callcoinrpc(c, 'extkey') # Sanity checks
if 'result' in rv and 'No keys to list.' in rv['result']: rv = self.callcoinrpc(c, 'extkey')
raise ValueError('No keys loaded.') if 'result' in rv and 'No keys to list.' in rv['result']:
raise ValueError('No keys loaded.')
if self.callcoinrpc(c, 'getstakinginfo')['enabled'] is not False:
self.log.warning('%s staking is not disabled.', ci.coin_name())
except Exception as e:
self.log.error('Sanity checks failed: %s', str(e))
if self.callcoinrpc(c, 'getstakinginfo')['enabled'] is not False:
self.log.warning('%s staking is not disabled.', ci.coin_name())
elif c == Coins.XMR: elif c == Coins.XMR:
ci.ensureWalletExists() ci.ensureWalletExists()

@ -27,6 +27,7 @@ from basicswap.rpc import (
) )
from basicswap.basicswap import BasicSwap from basicswap.basicswap import BasicSwap
from basicswap.chainparams import Coins from basicswap.chainparams import Coins
from basicswap.contrib.rpcauth import generate_salt, password_to_hmac
from bin.basicswap_run import startDaemon, startXmrWalletDaemon from bin.basicswap_run import startDaemon, startXmrWalletDaemon
@ -77,6 +78,14 @@ LTC_RPC_PORT = int(os.getenv('LTC_RPC_PORT', 19795))
BTC_RPC_PORT = int(os.getenv('BTC_RPC_PORT', 19796)) BTC_RPC_PORT = int(os.getenv('BTC_RPC_PORT', 19796))
NMC_RPC_PORT = int(os.getenv('NMC_RPC_PORT', 19798)) NMC_RPC_PORT = int(os.getenv('NMC_RPC_PORT', 19798))
PART_RPC_USER = os.getenv('PART_RPC_USER', '')
PART_RPC_PWD = os.getenv('PART_RPC_PWD', '')
BTC_RPC_USER = os.getenv('BTC_RPC_USER', '')
BTC_RPC_PWD = os.getenv('BTC_RPC_PWD', '')
LTC_RPC_USER = os.getenv('LTC_RPC_USER', '')
LTC_RPC_PWD = os.getenv('LTC_RPC_PWD', '')
COINS_BIND_IP = os.getenv('COINS_BIND_IP', '127.0.0.1')
extract_core_overwrite = True extract_core_overwrite = True
@ -328,18 +337,23 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic):
fp.write('testnet=1\n') fp.write('testnet=1\n')
fp.write('data-dir={}\n'.format(data_dir)) fp.write('data-dir={}\n'.format(data_dir))
fp.write('rpc-bind-port={}\n'.format(core_settings['rpcport'])) fp.write('rpc-bind-port={}\n'.format(core_settings['rpcport']))
fp.write('rpc-bind-ip=127.0.0.1\n') fp.write('rpc-bind-ip={}\n'.format(COINS_BIND_IP))
fp.write('zmq-rpc-bind-port={}\n'.format(core_settings['zmqport'])) fp.write('zmq-rpc-bind-port={}\n'.format(core_settings['zmqport']))
fp.write('zmq-rpc-bind-ip=127.0.0.1\n') fp.write('zmq-rpc-bind-ip={}\n'.format(COINS_BIND_IP))
fp.write('prune-blockchain=1\n') fp.write('prune-blockchain=1\n')
wallet_conf_path = os.path.join(data_dir, coin + '_wallet.conf') wallets_dir = core_settings.get('walletsdir', data_dir)
if not os.path.exists(wallets_dir):
os.makedirs(wallets_dir)
wallet_conf_path = os.path.join(wallets_dir, coin + '_wallet.conf')
if os.path.exists(wallet_conf_path): if os.path.exists(wallet_conf_path):
exitWithError('{} exists'.format(wallet_conf_path)) exitWithError('{} exists'.format(wallet_conf_path))
with open(wallet_conf_path, 'w') as fp: with open(wallet_conf_path, 'w') as fp:
fp.write('daemon-address={}:{}\n'.format(core_settings['rpchost'], core_settings['rpcport'])) fp.write('daemon-address={}:{}\n'.format(core_settings['rpchost'], core_settings['rpcport']))
fp.write('no-dns=1\n') fp.write('no-dns=1\n')
fp.write('rpc-bind-port={}\n'.format(core_settings['walletrpcport'])) fp.write('rpc-bind-port={}\n'.format(core_settings['walletrpcport']))
fp.write('rpc-bind-ip={}\n'.format(COINS_BIND_IP))
fp.write('wallet-dir={}\n'.format(os.path.join(data_dir, 'wallets'))) fp.write('wallet-dir={}\n'.format(os.path.join(data_dir, 'wallets')))
fp.write('log-file={}\n'.format(os.path.join(data_dir, 'wallet.log'))) fp.write('log-file={}\n'.format(os.path.join(data_dir, 'wallet.log')))
fp.write('shared-ringdb-dir={}\n'.format(os.path.join(data_dir, 'shared-ringdb'))) fp.write('shared-ringdb-dir={}\n'.format(os.path.join(data_dir, 'shared-ringdb')))
@ -358,25 +372,36 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic):
else: else:
logger.warning('Unknown chain %s', chain) logger.warning('Unknown chain %s', chain)
if COINS_BIND_IP != '127.0.0.1':
fp.write('rpcallowip=127.0.0.1\n')
fp.write('rpcallowip=172.0.0.0/8\n') # Allow 172.x.x.x, range used by docker
fp.write('rpcbind={}\n'.format(COINS_BIND_IP))
fp.write('rpcport={}\n'.format(core_settings['rpcport'])) fp.write('rpcport={}\n'.format(core_settings['rpcport']))
fp.write('printtoconsole=0\n') fp.write('printtoconsole=0\n')
fp.write('daemon=0\n') fp.write('daemon=0\n')
fp.write('wallet=wallet.dat\n') fp.write('wallet=wallet.dat\n')
salt = generate_salt(16)
if coin == 'particl': if coin == 'particl':
fp.write('debugexclude=libevent\n') fp.write('debugexclude=libevent\n')
fp.write('zmqpubsmsg=tcp://127.0.0.1:{}\n'.format(settings['zmqport'])) fp.write('zmqpubsmsg=tcp://{}:{}\n'.format(COINS_BIND_IP, settings['zmqport']))
fp.write('spentindex=1\n') fp.write('spentindex=1\n')
fp.write('txindex=1\n') fp.write('txindex=1\n')
fp.write('staking=0\n') fp.write('staking=0\n')
if PART_RPC_USER != '':
fp.write('rpcauth={}:{}${}\n'.format(PART_RPC_USER, salt, password_to_hmac(salt, PART_RPC_PWD)))
if particl_mnemonic == 'none': if particl_mnemonic == 'none':
fp.write('createdefaultmasterkey=1') fp.write('createdefaultmasterkey=1')
elif coin == 'litecoin': elif coin == 'litecoin':
fp.write('prune=2000\n') fp.write('prune=2000\n')
if LTC_RPC_USER != '':
fp.write('rpcauth={}:{}${}\n'.format(LTC_RPC_USER, salt, password_to_hmac(salt, LTC_RPC_PWD)))
elif coin == 'bitcoin': elif coin == 'bitcoin':
fp.write('prune=2000\n') fp.write('prune=2000\n')
fp.write('fallbackfee=0.0002\n') fp.write('fallbackfee=0.0002\n')
if BTC_RPC_USER != '':
fp.write('rpcauth={}:{}${}\n'.format(BTC_RPC_USER, salt, password_to_hmac(salt, BTC_RPC_PWD)))
elif coin == 'namecoin': elif coin == 'namecoin':
fp.write('prune=2000\n') fp.write('prune=2000\n')
else: else:
@ -627,6 +652,18 @@ def main():
} }
} }
if PART_RPC_USER != '':
chainclients['particl']['rpcuser'] = PART_RPC_USER
chainclients['particl']['rpcpassword'] = PART_RPC_PWD
if LTC_RPC_USER != '':
chainclients['litecoin']['rpcuser'] = LTC_RPC_USER
chainclients['litecoin']['rpcpassword'] = LTC_RPC_PWD
if BTC_RPC_USER != '':
chainclients['bitcoin']['rpcuser'] = BTC_RPC_USER
chainclients['bitcoin']['rpcpassword'] = BTC_RPC_PWD
chainclients['monero']['walletsdir'] = os.getenv('XMR_WALLETS_DIR', chainclients['monero']['datadir'])
if disable_coin != '': if disable_coin != '':
logger.info('Disabling coin: %s', disable_coin) logger.info('Disabling coin: %s', disable_coin)
if not os.path.exists(config_path): if not os.path.exists(config_path):

@ -1,2 +1,22 @@
HTML_PORT=127.0.0.1:12700:12700 HTML_PORT=127.0.0.1:12700:12700
TZ=UTC TZ=UTC
DATA_PATH=/mnt/hdd50/docker2
PART_RPC_HOST=particl_core
LTC_RPC_HOST=litecoin_core
BTC_RPC_HOST=bitcoin_core
PART_RPC_USER=particl_user
PART_RPC_PWD=particl_pwd
BTC_RPC_USER=bitcoin_user
BTC_RPC_PWD=bitcoin_pwd
LTC_RPC_USER=litecoin_user
LTC_RPC_PWD=litecoin_pwd
PART_DATA_DIR=/data/particl
LTC_DATA_DIR=/data/litecoin
BTC_DATA_DIR=/data/bitcoin
XMR_DATA_DIR=/data/monero_daemon
XMR_WALLETS_DIR=/data/monero_wallet
COINS_BIND_IP=0.0.0.0

@ -2,7 +2,8 @@
FROM i_swapclient as install_stage FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=bitcoin --withoutcoins=particl RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=bitcoin --withoutcoins=particl && \
find /coin_bin -name *.tar.gz -delete
FROM debian:buster-slim FROM debian:buster-slim
COPY --from=install_stage /coin_bin . COPY --from=install_stage /coin_bin .
@ -23,4 +24,4 @@ COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8332 8333 18332 18333 18443 18444 EXPOSE 8332 8333 18332 18333 18443 18444
CMD ["bitcoind"] CMD ["/bitcoin/bitcoind", "--datadir=/data"]

@ -8,9 +8,9 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: particl_core container_name: particl_core
volumes: volumes:
- /var/swapdata/particl:/data - ${DATA_PATH}/particl:/data
ports: #ports:
- "51738:51738" # - "51738:51738"
expose: expose:
- 51735 - 51735
logging: logging:
@ -19,18 +19,32 @@ services:
max-size: "10m" max-size: "10m"
max-file: "3" max-file: "3"
restart: unless-stopped restart: unless-stopped
bitcoin_core: #bitcoin_core:
image: i_bitcoin #image: i_bitcoin
#build:
#context: bitcoin
#dockerfile: Dockerfile
#container_name: bitcoin_core
#volumes:
#- ${DATA_PATH}/bitcoin:/data
##ports:
## - "8333:8333"
#expose:
#- 8332
#logging:
#driver: "json-file"
#options:
#max-size: "10m"
#max-file: "3"
#restart: unless-stopped
litecoin_core:
image: i_litecoin
build: build:
context: bitcoin context: litecoin
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: bitcoin_core container_name: litecoin_core
volumes: volumes:
- /var/swapdata/bitcoin:/data - ${DATA_PATH}/litecoin:/data
ports:
- "8333:8333"
expose:
- 8332
logging: logging:
driver: "json-file" driver: "json-file"
options: options:
@ -44,7 +58,7 @@ services:
#dockerfile: Dockerfile #dockerfile: Dockerfile
#container_name: monero_daemon #container_name: monero_daemon
#volumes: #volumes:
#- /var/swapdata/monero_daemon:/data #- ${DATA_PATH}/monero_daemon:/data
#ports: #ports:
#- "18080:18080" #- "18080:18080"
#expose: #expose:
@ -55,22 +69,22 @@ services:
#max-size: "10m" #max-size: "10m"
#max-file: "3" #max-file: "3"
#restart: unless-stopped #restart: unless-stopped
monero_wallet: #monero_wallet:
image: i_monero_wallet #image: i_monero_wallet
build: #build:
context: monero_wallet #context: monero_wallet
dockerfile: Dockerfile #dockerfile: Dockerfile
container_name: monero_wallet #container_name: monero_wallet
volumes: #volumes:
- /var/swapdata/monero_wallet:/data #- ${DATA_PATH}/monero_wallet:/data
expose: #expose:
- 8332 #- 8332
logging: #logging:
driver: "json-file" #driver: "json-file"
options: #options:
max-size: "10m" #max-size: "10m"
max-file: "3" #max-file: "3"
restart: unless-stopped #restart: unless-stopped
swapclient: swapclient:
image: i_swapclient image: i_swapclient
build: build:
@ -78,7 +92,7 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: swapclient container_name: swapclient
volumes: volumes:
- /var/swapdata/swapclient:/data - ${DATA_PATH}/swapclient:/data
ports: ports:
- "${HTML_PORT}" # Expose only to localhost, see .env - "${HTML_PORT}" # Expose only to localhost, see .env
environment: environment:
@ -91,6 +105,50 @@ services:
depends_on: depends_on:
- particl_core - particl_core
restart: unless-stopped restart: unless-stopped
swapprepare:
image: i_swapclient
build:
context: swapclient
dockerfile: Dockerfile
container_name: swapprepare
volumes:
- ${DATA_PATH}/swapclient:/data/swapclient
- ${DATA_PATH}/monero_daemon:/data/monero_daemon
- ${DATA_PATH}/monero_wallet:/data/monero_wallet
- ${DATA_PATH}/particl:/data/particl
- ${DATA_PATH}/bitcoin:/data/bitcoin
- ${DATA_PATH}/litecoin:/data/litecoin
environment:
- TZ
- PART_RPC_HOST
- LTC_RPC_HOST
- BTC_RPC_HOST
- PART_RPC_PORT
- LTC_RPC_PORT
- BTC_RPC_PORT
- XMR_RPC_HOST
- BASE_XMR_RPC_PORT
- BASE_XMR_ZMQ_PORT
- BASE_XMR_WALLET_PORT
- XMR_WALLET_RPC_HOST
- XMR_WALLET_RPC_USER
- XMR_WALLET_RPC_PWD
- DEFAULT_XMR_RESTORE_HEIGHT
- UI_HTML_PORT
- PART_ZMQ_PORT
- PART_RPC_USER
- PART_RPC_PWD
- BTC_RPC_USER
- BTC_RPC_PWD
- LTC_RPC_USER
- LTC_RPC_PWD
- PART_DATA_DIR
- LTC_DATA_DIR
- BTC_DATA_DIR
- XMR_DATA_DIR
- XMR_WALLETS_DIR
- COINS_BIND_IP
restart: "no"
networks: networks:
default: default:
external: external:

@ -0,0 +1,21 @@
HTML_PORT=127.0.0.1:12700:12700
TZ=UTC
DATA_PATH=/var/swapdata/
PART_RPC_HOST=particl_core
LTC_RPC_HOST=litecoin_core
BTC_RPC_HOST=bitcoin_core
PART_RPC_USER=particl_user
PART_RPC_PWD=particl_pwd
BTC_RPC_USER=bitcoin_user
BTC_RPC_PWD=bitcoin_pwd
LTC_RPC_USER=litecoin_user
LTC_RPC_PWD=litecoin_pwd
PART_DATA_DIR=/data/particl
LTC_DATA_DIR=/data/litecoin
BTC_DATA_DIR=/data/bitcoin
XMR_DATA_DIR=/data/monero_daemon
XMR_WALLETS_DIR=/data/monero_wallet
COINS_BIND_IP=0.0.0.0

@ -1,13 +1,14 @@
FROM i_swapclient as install_stage FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=litecoin --withoutcoin=particl RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=litecoin --withoutcoin=particl && \
find /coin_bin -name *.tar.gz -delete
FROM debian:buster-slim FROM debian:buster-slim
COPY --from=install_stage /coin_bin . COPY --from=install_stage /coin_bin .
ENV LITECOIN_DATA /data ENV LITECOIN_DATA /data
RUN groupadd -r particl && useradd -r -m -g litecoin litecoin \ RUN groupadd -r litecoin && useradd -r -m -g litecoin litecoin \
&& apt-get update \ && apt-get update \
&& apt-get install -qq --no-install-recommends gosu \ && apt-get install -qq --no-install-recommends gosu \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
@ -21,4 +22,4 @@ COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8332 8333 18332 18333 18443 18444 EXPOSE 8332 8333 18332 18333 18443 18444
CMD ["litecoind"] CMD ["/litecoin/litecoind", "--datadir=/data"]

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

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

@ -1,6 +1,7 @@
FROM i_swapclient as install_stage FROM i_swapclient as install_stage
RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=particl RUN basicswap-prepare --preparebinonly --bindir=/coin_bin --withcoin=particl && \
find /coin_bin -name *.tar.gz -delete
FROM debian:buster-slim FROM debian:buster-slim
COPY --from=install_stage /coin_bin . COPY --from=install_stage /coin_bin .
@ -21,4 +22,4 @@ COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 51735 20792 51738 EXPOSE 51735 20792 51738
CMD ["particld"] CMD ["/particl/particld", "--datadir=/data"]

@ -18,7 +18,12 @@ RUN wget -O basicswap-master.zip https://github.com/tecnovert/basicswap/archive/
protoc -I=basicswap --python_out=basicswap basicswap/messages.proto; \ protoc -I=basicswap --python_out=basicswap basicswap/messages.proto; \
pip3 install .; pip3 install .;
RUN useradd -ms /bin/bash swap_user && \ #COPY ./test_code basicswap-master
#RUN cd basicswap-master; \
# protoc -I=basicswap --python_out=basicswap basicswap/messages.proto; \
# pip3 install .;
RUN groupadd -r swap_user && useradd -g swap_user -ms /bin/bash swap_user && \
mkdir /data && chown swap_user -R /data mkdir /data && chown swap_user -R /data
# Expose html port # Expose html port

Loading…
Cancel
Save