From 402c5e3444395c67ed0ec97e2fb835525eadaf3c Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Sun, 21 Mar 2021 15:12:18 -0400 Subject: [PATCH] deploy: add Makefile for easier docker deploy --- .gitignore | 3 ++ GNUmakefile | 48 +++++++++++++++++++++++++++ Makefile | 1 + docker/backend/start.sh | 2 +- docker/docker-compose.yml | 67 ++++++++++++++++++++++++++++++++++++++ docker/electrum/Dockerfile | 30 +++++++++++++++++ 6 files changed, 150 insertions(+), 1 deletion(-) create mode 100755 GNUmakefile create mode 100644 Makefile create mode 100644 docker/docker-compose.yml create mode 100644 docker/electrum/Dockerfile diff --git a/.gitignore b/.gitignore index cf813d1f4..fbf9f9101 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ sitemap +data +docker-compose.yml +backend/mempool-config.json diff --git a/GNUmakefile b/GNUmakefile new file mode 100755 index 000000000..eac479652 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,48 @@ +# If you see pwd_unknown showing up check permissions +PWD ?= pwd_unknown + +# DATABASE DEPLOY FOLDER CONFIG - default ./data +ifeq ($(data),) +DATA := data +export DATA +else +DATA := $(data) +export DATA +endif + +.PHONY: help +help: + @echo '' + @echo '' + @echo ' Usage: make [COMMAND]' + @echo '' + @echo ' make all # build init mempool and electrs' + @echo ' make init # setup some useful configs' + @echo ' make mempool # build q dockerized mempool.space' + @echo ' make electrs # build a docker electrs image' + @echo '' + +.PHONY: init +init: + @echo '' + mkdir -p $(DATA) $(DATA)/mysql $(DATA)/mysql/db-scripts $(DATA)/mysql/data + install -v mariadb-structure.sql $(DATA)/mysql/db-scripts + #REF: https://github.com/mempool/mempool/blob/master/docker/README.md + cat docker/docker-compose.yml > docker-compose.yml + cat backend/mempool-config.sample.json > backend/mempool-config.json +.PHONY: mempool +mempool: init + @echo '' + docker-compose up --force-recreate --always-recreate-deps + @echo '' +.PHONY: electrs +electrum: + #REF: https://hub.docker.com/r/beli/electrum + @echo '' + docker build -f docker/electrum/Dockerfile . + @echo '' +.PHONY: all +all: init + make mempool +####################### +-include Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..53016c66f --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +# For additional configs/scripting diff --git a/docker/backend/start.sh b/docker/backend/start.sh index 22715f8b1..90aa2b11d 100644 --- a/docker/backend/start.sh +++ b/docker/backend/start.sh @@ -11,7 +11,7 @@ __BITCOIN_MAINNET_RPC_USER__=${RPC_USER:=mempool} __BITCOIN_MAINNET_RPC_PASS__=${RPC_PASS:=mempool} # ELECTRUM __ELECTRUM_MAINNET_HTTP_HOST__=${ELECTRUM_HOST:=127.0.0.1} -__ELECTRUM_MAINNET_HTTP_PORT__=${ELECTRUM_PORT:=50002} +__ELECTRUM_MAINNET_HTTP_PORT__=${ELECTRUM_PORT:=50002} # 50001? __ELECTRUM_MAINNET_TLS_ENABLED__=${ELECTRUM_TLS:=false} # MYSQL __MYSQL_HOST__=${MYSQL_HOST:=127.0.0.1} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 000000000..1731d1aaa --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,67 @@ +version: "3.7" + +services: + + electrum: + build: + context: . + dockerfile: docker/electrum/Dockerfile + user: "1000:1000" + restart: on-failure + command: "" + ports: + - 50001:50001 + - 50002:50002 + - 4224:4224 + - 8332:8332 + environment: + ELECTRUM: "electrum" + # add electrs configs + web: + image: mempool/frontend:latest + user: "1000:1000" + restart: on-failure + stop_grace_period: 1m + command: "./wait-for db:3306 --timeout=720 -- nginx -g 'daemon off;'" + ports: + - 80:8080 + environment: + FRONTEND_HTTP_PORT: "8080" + BACKEND_MAINNET_HTTP_HOST: "api" + api: + image: mempool/backend:latest + user: "1000:1000" + restart: on-failure + stop_grace_period: 1m + command: "./wait-for-it.sh db:3306 --timeout=720 --strict -- ./start.sh" + volumes: + - ./data:/backend/cache + environment: + RPC_HOST: "127.0.0.1" + RPC_PORT: "8332" + RPC_USER: "mempool" + RPC_PASS: "mempool" + ELECTRUM_HOST: "127.0.0.1" + ELECTRUM_PORT: "50002" + ELECTRUM_TLS: "false" + MYSQL_HOST: "db" + MYSQL_PORT: "3306" + MYSQL_DATABASE: "mempool" + MYSQL_USER: "mempool" + MYSQL_PASS: "mempool" + BACKEND_MAINNET_HTTP_PORT: "8999" + CACHE_DIR: "/backend/cache" + MEMPOOL_CLEAR_PROTECTION_MINUTES: "20" + db: + image: mariadb:10.5.8 + user: "1000:1000" + restart: on-failure + stop_grace_period: 1m + volumes: + - ./mysql/data:/var/lib/mysql + - ./mysql/db-scripts:/docker-entrypoint-initdb.d + environment: + MYSQL_DATABASE: "mempool" + MYSQL_USER: "mempool" + MYSQL_PASSWORD: "mempool" + MYSQL_ROOT_PASSWORD: "admin" diff --git a/docker/electrum/Dockerfile b/docker/electrum/Dockerfile new file mode 100644 index 000000000..af5cfe0a0 --- /dev/null +++ b/docker/electrum/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:18.04 +MAINTAINER mempool.space developers +EXPOSE 50002 + +# runs as UID 1000 GID 1000 inside the container + +ENV VERSION 4.0.9 +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gpg gpg-agent dirmngr \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends wget xpra python3-pyqt5 python3-wheel python3-pip python3-setuptools libsecp256k1-0 libsecp256k1-dev python3-numpy python3-dev build-essential \ + && wget /tmp/Electrum-${VERSION}.tar.gz https://download.electrum.org/${VERSION}/Electrum-${VERSION}.tar.gz \ + && wget /tmp/Electrum-${VERSION}.tar.gz.asc https://download.electrum.org/${VERSION}/Electrum-${VERSION}.tar.gz.asc \ + && gpg --verify /tmp/Electrum-${VERSION}.tar.gz.asc \ + && pip3 install /tmp/Electrum-${VERSION}.tar.gz \ + && test -f /usr/local/bin/electrum \ + && rm -vrf /tmp/Electrum-${VERSION}.tar.gz /tmp/Electrum-${VERSION}.tar.gz.asc ${HOME}/.gnupg \ + && apt-get purge --autoremove -y python3-wheel python3-pip python3-setuptools python3-dev build-essential libsecp256k1-dev curl gpg gpg-agent dirmngr \ + && apt-get clean && rm -rf /var/lib/apt/lists/* \ + && useradd -d /home/mwmpool -m mempool \ + && mkdir /electrum \ + && ln -s /electrum /home/mempool/.electrum \ + && chown mempool:mempool /electrum + +USER mempool +ENV HOME /home/mempool +WORKDIR /home/mempool +VOLUME /electrum + +CMD ["/usr/bin/xpra", "start", ":100", "--start-child=/usr/local/bin/electrum", "--bind-tcp=0.0.0.0:50002","--daemon=yes", "--notifications=no", "--mdns=no", "--pulseaudio=no", "--html=off", "--speaker=disabled", "--microphone=disabled", "--webcam=no", "--printing=no", "--dbus-launch=", "--exit-with-children"] +ENTRYPOINT ["electrum"]