From 484d811fe7758f2afd6decabc1d098dd9a496b01 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 9 Mar 2023 15:32:54 +0200 Subject: [PATCH] docker: Add script container fragment. Example: python3 ./scripts/build_yml_files.py -c bitcoin monero dash pivx --withscript --- .../production/compose-fragments/8_script.yml | 23 +++++++++++++++++++ .../compose-fragments/8_swapclient.yml | 7 ++++-- docker/production/example.env | 4 ++-- docker/production/scripts/build_yml_files.py | 7 ++++++ docker/production/swapclient/Dockerfile | 10 ++++---- 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 docker/production/compose-fragments/8_script.yml diff --git a/docker/production/compose-fragments/8_script.yml b/docker/production/compose-fragments/8_script.yml new file mode 100644 index 0000000..59da700 --- /dev/null +++ b/docker/production/compose-fragments/8_script.yml @@ -0,0 +1,23 @@ + swapscript: + image: i_swapclient + build: + context: swapclient + dockerfile: Dockerfile + container_name: swapscript + volumes: + - ${DATA_PATH}/scripts:/data + environment: + - TZ + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "5" + depends_on: + - swapclient + restart: unless-stopped + command: ["/usr/bin/python3", "basicswap/scripts/createoffers.py", + "--host", "swapclient", + "--port", "${HTML_PORT}", + "--configfile", "/data/createoffers.json", + "--statefile", "/data/createoffers_state.json"] diff --git a/docker/production/compose-fragments/8_swapclient.yml b/docker/production/compose-fragments/8_swapclient.yml index fbabc56..e19863b 100644 --- a/docker/production/compose-fragments/8_swapclient.yml +++ b/docker/production/compose-fragments/8_swapclient.yml @@ -6,9 +6,12 @@ container_name: swapclient volumes: - ${DATA_PATH}/swapclient:/data + expose: + - "${HTML_PORT}" + - "${WS_PORT}" ports: - - "${HTML_PORT}" # Expose only to localhost, see .env - - "${WS_PORT}" # Expose only to localhost, see .env + - "127.0.0.1:${HTML_PORT}:${HTML_PORT}" # Expose only to localhost + - "127.0.0.1:${WS_PORT}:${WS_PORT}" # Expose only to localhost environment: - TZ logging: diff --git a/docker/production/example.env b/docker/production/example.env index c9a9e02..b401fb5 100644 --- a/docker/production/example.env +++ b/docker/production/example.env @@ -1,5 +1,5 @@ -HTML_PORT=127.0.0.1:12700:12700 -WS_PORT=127.0.0.1:11700:11700 +HTML_PORT=12700 +WS_PORT=11700 TZ=UTC DATA_PATH=/var/swapdata/ diff --git a/docker/production/scripts/build_yml_files.py b/docker/production/scripts/build_yml_files.py index 5ae4219..ba08473 100755 --- a/docker/production/scripts/build_yml_files.py +++ b/docker/production/scripts/build_yml_files.py @@ -27,6 +27,7 @@ def main(): parser.add_argument('-v', '--version', action='version', version='%(prog)s {version}'.format(version=__version__)) parser.add_argument('-c', '--coins', nargs='+', help=' Select coins', required=True) + parser.add_argument('--withscript', dest='withscript', help='Add container to run createoffers.py (default=false)', required=False, action='store_true') args = parser.parse_args() with_coins = ['particl', ] @@ -73,6 +74,12 @@ def main(): with open(os.path.join(fragments_dir, '8_swapclient.yml'), 'rb') as fp_in: for line in fp_in: fp.write(line) + + if args.withscript: + with open(os.path.join(fragments_dir, '8_script.yml'), 'rb') as fp_in: + for line in fp_in: + fp.write(line) + with open(os.path.join(fragments_dir, '9_swapprepare.yml'), 'rb') as fp_in: for line in fp_in: fpp.write(line) diff --git a/docker/production/swapclient/Dockerfile b/docker/production/swapclient/Dockerfile index 4e04ae2..9f07030 100644 --- a/docker/production/swapclient/Dockerfile +++ b/docker/production/swapclient/Dockerfile @@ -26,21 +26,19 @@ ARG BASICSWAP_URL=https://github.com/tecnovert/basicswap/archive/master.zip ARG BASICSWAP_DIR=basicswap-master RUN wget -O basicswap-repo.zip $BASICSWAP_URL; \ unzip basicswap-repo.zip; \ - cd $BASICSWAP_DIR; \ + mv $BASICSWAP_DIR /basicswap; \ + cd /basicswap; \ protoc -I=basicswap --python_out=basicswap basicswap/messages.proto; \ pip3 install .; -#COPY ./test_code basicswap-master -#RUN cd basicswap-master; \ +#COPY ./test_code basicswap +#RUN cd basicswap; \ # 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 -# Expose html port -EXPOSE 12700 - VOLUME /data COPY ./entrypoint.sh /entrypoint.sh