From 3bbb483a0a33bdcc88262c148e295e9bd1c49efa Mon Sep 17 00:00:00 2001 From: tecnovert Date: Wed, 2 Dec 2020 23:19:10 +0200 Subject: [PATCH] Simplify docker config. --- .dockerignore | 1 - Dockerfile | 20 +++++++------------ bin/basicswap_prepare.py | 18 ++++++++--------- bin/basicswap_run.py | 11 ++++++----- doc/{run.docker.example.txt => docker.md} | 24 ++++++++++++++++++++++- docker/.env | 2 +- docker/docker-compose.yml | 4 +--- docker/entrypoint.sh | 6 ++++++ 8 files changed, 52 insertions(+), 34 deletions(-) delete mode 100644 .dockerignore rename doc/{run.docker.example.txt => docker.md} (72%) create mode 100755 docker/entrypoint.sh diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 6d0eac4..0000000 --- a/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -docker \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0e9e8e1..f1aba7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,11 @@ FROM ubuntu:20.04 -ARG WITH_COINS -ARG WITHOUT_COINS - ENV LANG=C.UTF-8 \ DEBIAN_FRONTEND=noninteractive \ DATADIRS="/coindata" RUN apt-get update; \ - apt-get install -y wget python3-pip gnupg unzip protobuf-compiler automake libtool pkg-config; + 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 && \ @@ -21,18 +18,15 @@ RUN cd basicswap-master; \ protoc -I=basicswap --python_out=basicswap basicswap/messages.proto; \ pip3 install .; -# Download binaries, these will be part of the docker image -RUN basicswap-prepare -datadir=/opt -preparebinonly ${WITH_COINS} ${WITHOUT_COINS} - -RUN useradd -ms /bin/bash user && \ - mkdir /coindata && chown user -R /coindata - -USER user -WORKDIR /home/user +RUN useradd -ms /bin/bash swap_user && \ + mkdir /coindata && chown swap_user -R /coindata # Expose html port EXPOSE 12700 VOLUME /coindata -ENTRYPOINT ["basicswap-run", "-datadir=/coindata/basicswap"] +COPY ./docker/entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["basicswap-run", "-datadir=/coindata/basicswap"] diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index 01e318b..80f9a26 100755 --- a/bin/basicswap_prepare.py +++ b/bin/basicswap_prepare.py @@ -8,24 +8,22 @@ """ Atomic Swap Client - Proof of Concept -sudo pip install python-gnupg - """ -import sys import os +import sys import json -import hashlib import mmap +import stat +import gnupg +import hashlib import tarfile import zipfile -import stat -from urllib.request import urlretrieve -import urllib.parse import logging import platform +import urllib.parse +from urllib.request import urlretrieve -import gnupg import basicswap.config as cfg from basicswap.rpc import ( @@ -571,8 +569,8 @@ def main(): 'network_key': '7sW2UEcHXvuqEjkpE5mD584zRaQYs6WXYohue4jLFZPTvMSxwvgs', 'network_pubkey': '035758c4a22d7dd59165db02a56156e790224361eb3191f02197addcb3bde903d2', 'chainclients': withchainclients, - 'auto_reply_delay_min': 5, # Min delay before sending a response message - 'auto_reply_delay_max': 50, # Max delay before sending a response message + 'min_delay_event': 5, # Min delay in seconds before reacting to an event + 'max_delay_event': 50, # Max delay in seconds before reacting to an event 'check_progress_seconds': 60, 'check_watched_seconds': 60, 'check_expired_seconds': 60 diff --git a/bin/basicswap_run.py b/bin/basicswap_run.py index 59fb368..8649103 100644 --- a/bin/basicswap_run.py +++ b/bin/basicswap_run.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright (c) 2019 tecnovert +# Copyright (c) 2019-2020 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -10,14 +10,15 @@ Atomic Swap Client - Proof of Concept """ -import sys import os -import time +import sys import json -import traceback +import time import signal -import subprocess import logging +import traceback +import subprocess + import basicswap.config as cfg from basicswap import __version__ diff --git a/doc/run.docker.example.txt b/doc/docker.md similarity index 72% rename from doc/run.docker.example.txt rename to doc/docker.md index bb95402..2ac542a 100644 --- a/doc/run.docker.example.txt +++ b/doc/docker.md @@ -1,7 +1,29 @@ +# Docker Setup + +## Build the images +``` +$ docker-compose build +``` + +## Prepare the binaries, coin dirs and settings +``` +$ docker run -t --name swap_prepare -v /tmp/coindata:/coindata i_swapclient basicswap-prepare --datadir=/coindata --withcoins=monero --withoutcoins=litecoin +``` + +Record the mnemonic from the output of the above command. + +Remove swap_prepare container (and logs): +``` +$ docker rm swap_prepare +``` + + +# Running on windows 10 + + Work in progress - doesn't work reliably. -Running on windows 10 Install the latest docker toolbox from: https://github.com/docker/toolbox/releases diff --git a/docker/.env b/docker/.env index 315f1dd..5229854 100644 --- a/docker/.env +++ b/docker/.env @@ -1,2 +1,2 @@ HTML_PORT=127.0.0.1:12700:12700 -COINDATA_PATH=./coindata +COINDATA_PATH=/var/data/basicswap diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 8f5422b..670c3f4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,12 +2,10 @@ version: '3' services: swapclient: + image: i_swapclient stop_grace_period: 5m build: context: ../ - args: - - WITH_COINS=--withcoins=monero - - WITHOUT_COINS=--withoutcoins=litecoin volumes: - ${COINDATA_PATH}:/coindata ports: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..8116ef8 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +chown -R swap_user "$DATADIRS" +exec gosu swap_user "$@" +