Verified Commit 5192bb01 authored by Pavel Ševčík's avatar Pavel Ševčík Committed by likewhoa
Browse files

mempool integration

parent ae737dba
......@@ -35,8 +35,9 @@ NET_DOJO_TOR_IPV4=172.28.1.4
NET_DOJO_BITCOIND_IPV4=172.28.1.5
NET_DOJO_INDEXER_IPV4=172.28.1.6
NET_DOJO_EXPLORER_IPV4=172.28.1.7
NET_DOJO_MEMPOOL_API_IPV4=172.27.1.8
NET_DOJO_MEMPOOL_WEB_IPV4=172.27.1.9
NET_DOJO_MEMPOOL_DB_IPV4=172.28.1.9
NET_DOJO_MEMPOOL_API_IPV4=172.28.1.10
NET_DOJO_MEMPOOL_WEB_IPV4=172.28.1.11
NET_DMZ_NGINX_IPV4=172.29.1.3
NET_DMZ_TOR_IPV4=172.29.1.4
......@@ -50,7 +51,6 @@ NET_WHIRL_WHIRLPOOL_IPV4=172.30.1.8
#########################################
MYSQL_DATABASE=samourai-main
MEMPOOL_MYSQL_DATABASE=mempool
#########################################
# BITCOIND
......@@ -134,4 +134,4 @@ SOROBAN_LINUX_GID=1114
MEMPOOL_WEB_LINUX_UID=1121
MEMPOOL_WEB_LINUX_GID=1124
MEMPOOL_API_LINUX_UID=1122
MEMPOOL_API_LINUX_GID=1125
\ No newline at end of file
MEMPOOL_API_LINUX_GID=1125
......@@ -5,3 +5,23 @@
# Install and run a Mempool.space visualizer inside Dojo (recommended)
# Value: on | off
MEMPOOL_INSTALL=on
# User account used for db access
# Warning: This option must not be modified after the first installation
# Type: alphanumeric
MYSQL_USER=mempool
# Password of of user account
# Warning: This option must not be modified after the first installation
# Type: alphanumeric
MYSQL_PASSWORD=mempool
# Root password for database
# Warning: This option must not be modified after the first installation
# Type: alphanumeric
MYSQL_ROOT_PASSWORD=admin
# Database name
# Warning: This option must not be modified after the first installation
# Type: alphanumeric
MYSQL_DATABASE=mempool
......@@ -25,6 +25,13 @@ source_file "$DIR/.env"
# Export some variables for compose
export BITCOIND_RPC_EXTERNAL_IP
# Eexport env variables for mempool compose
export BITCOIND_RPC_PORT
export BITCOIND_RPC_USER
export BITCOIND_RPC_PASSWORD
export INDEXER_RPC_PORT
export NET_DOJO_MEMPOOL_API_IPV4
# Select YAML files
select_yaml_files() {
yamlFiles="-f $DIR/docker-compose.yaml"
......@@ -276,8 +283,6 @@ clean() {
del_images_for samouraiwallet/dojo-tor "$DOJO_TOR_VERSION_TAG"
del_images_for samouraiwallet/dojo-indexer "$DOJO_INDEXER_VERSION_TAG"
del_images_for samouraiwallet/dojo-whirlpool "$DOJO_WHIRLPOOL_VERSION_TAG"
del_images_for samouraiwallet/dojo-mempool_api:"$DOJO_MEMPOOL__API_VERSION_TAG"
del_images_for samouraiwallet/dojo-mempool_web:"$DOJO_MEMPOOL__WEB_VERSION_TAG"
docker image prune -f
}
......@@ -491,6 +496,20 @@ logs() {
echo -e "Command not supported for your setup.\nCause: Your Dojo is not running a mempool space"
fi
;;
mempool_db )
if [ "$MEMPOOL_INSTALL" == "on" ]; then
display_logs $1 $2
else
echo -e "Command not supported for your setup.\nCause: Your Dojo is not running a mempool space"
fi
;;
mempool_web )
if [ "$MEMPOOL_INSTALL" == "on" ]; then
display_logs $1 $2
else
echo -e "Command not supported for your setup.\nCause: Your Dojo is not running a mempool space"
fi
;;
* )
services="nginx node tor db"
if [ "$BITCOIND_INSTALL" == "on" ]; then
......@@ -507,6 +526,8 @@ logs() {
fi
if [ "$MEMPOOL_INSTALL" == "on" ]; then
services="$services mempool_api"
services="$services mempool_db"
services="$services mempool_web"
fi
display_logs "$services" $2
;;
......
......@@ -134,9 +134,4 @@ init_config_files() {
cp ./mysql/mysql-default.cnf ./mysql/mysql-dojo.cnf
fi
echo "Initialized mysql-dojo.cnf (mysql)"
# Initialize mempool db for mysql
if [ "$MEMPOOL_INSTALL" == "on" ]; then
cp ./mempool/mysql/mariadb-structure.sql.tpl ./mempool/mysql/mariadb-structure.sql
fi
}
......@@ -118,11 +118,6 @@ update_config_files() {
cp ./mysql/mysql-default.cnf ./mysql/mysql-dojo.cnf
fi
echo "Initialized mysql-dojo.cnf (mysql)"
# Initialize mempool db for mysql
if [ "$MEMPOOL_INSTALL" == "on" ]; then
cp ./mempool/mysql/mariadb-structure.sql.tpl ./mempool/mysql/mariadb-structure.sql
fi
}
# Update a configuration file from template
......
FROM node:12-buster-slim AS builder
ENV MEMPOOL_API_HOME /build/
ENV MEMPOOL_API_VERSION v2.2.0
ENV MEMPOOL_API_URL https://github.com/mempool/mempool.git
ARG MEMPOOL_API_LINUX_GID
ARG MEMPOOL_API_LINUX_UID
WORKDIR /build
RUN apt-get update
RUN apt-get install -y build-essential python3 pkg-config git
RUN cd ${MEMPOOL_API_HOME} && git clone -b ${MEMPOOL_API_VERSION} ${MEMPOOL_API_URL}
RUN cd mempool/backend && \
npm ci --production && \
npm i typescript && \
npm run build
RUN cp /build/mempool/docker/backend/wait-for-it.sh
FROM node:12-buster-slim
WORKDIR /backend
COPY --from=builder /build/mempool/backend .
COPY ./start.sh /backend/start.sh
RUN chmod +x /backend/start.sh
RUN chmod +x /backend/wait-for-it.sh
RUN chown -R ${MEMPOOL_API_LINUX_UID}:${MEMPOOL_API_LINUX_GID} /backend && chmod -R 755 /backend
USER ${MEMPOOL_API_LINUX_UID}
EXPOSE 8999
CMD ["/backend/start.sh"]
\ No newline at end of file
#!/bin/sh
#MEMPOOL
__MEMPOOL_BACKEND_MAINNET_HTTP_PORT__=${BACKEND_MAINNET_HTTP_PORT:=8999}
__MEMPOOL_BACKEND_MAINNET_CACHE_DIR__=${CACHE_DIR:=./cache}
__MEMPOOL_BACKEND_CLEAR_PROTECTION_MINUTES__=${MEMPOOL_CLEAR_PROTECTION_MINUTES:=20}
# BITCOIN
__BITCOIN_MAINNET_RPC_HOST__=${BITCOIND_IP:=127.0.0.1}
__BITCOIN_MAINNET_RPC_PORT__=${BITCOIND_RPC_PORT:=8332}
__BITCOIN_MAINNET_RPC_USER__=${BITCOIND_RPC_USER:=mempool}
__BITCOIN_MAINNET_RPC_PASS__=${BITCOIND_RPC_PASSWORD:=mempool}
# ELECTRUM
__ELECTRUM_MAINNET_HTTP_HOST__=${INDEXER_IP:=127.0.0.1}
__ELECTRUM_MAINNET_HTTP_PORT__=${INDEXER_RPC_PORT:=50001} # 50001?
__ELECTRUM_MAINNET_TLS_ENABLED__=${ELECTRUM_TLS:=false}
# MYSQL
__MYSQL_HOST__=${MYSQL_HOST:=127.0.0.1}
__MYSQL_PORT__=${MYSQL_PORT:=3306}
__MYSQL_DATABASE__=${MEMPOOL_MYSQL_DATABASE:=mempool}
__MYSQL_USERNAME__=${MEMPOOL_MYSQL_USER:=mempool}
__MYSQL_PASSWORD__=${MEMPOOL_DB_PASSWORD:=mempool}
mkdir -p "${__MEMPOOL_BACKEND_MAINNET_CACHE_DIR__}"
sed -i "s/__BITCOIN_MAINNET_RPC_HOST__/${__BITCOIN_MAINNET_RPC_HOST__}/g" mempool-config.json
sed -i "s/__BITCOIN_MAINNET_RPC_PORT__/${__BITCOIN_MAINNET_RPC_PORT__}/g" mempool-config.json
sed -i "s/__BITCOIN_MAINNET_RPC_USER__/${__BITCOIN_MAINNET_RPC_USER__}/g" mempool-config.json
sed -i "s/__BITCOIN_MAINNET_RPC_PASS__/${__BITCOIN_MAINNET_RPC_PASS__}/g" mempool-config.json
sed -i "s/__ELECTRUM_MAINNET_HTTP_HOST__/${__ELECTRUM_MAINNET_HTTP_HOST__}/g" mempool-config.json
sed -i "s/__ELECTRUM_MAINNET_HTTP_PORT__/${__ELECTRUM_MAINNET_HTTP_PORT__}/g" mempool-config.json
sed -i "s/__ELECTRUM_MAINNET_TLS_ENABLED__/${__ELECTRUM_MAINNET_TLS_ENABLED__}/g" mempool-config.json
sed -i "s/__MYSQL_HOST__/${__MYSQL_HOST__}/g" mempool-config.json
sed -i "s/__MYSQL_PORT__/${__MYSQL_PORT__}/g" mempool-config.json
sed -i "s/__MYSQL_DATABASE__/${__MYSQL_DATABASE__}/g" mempool-config.json
sed -i "s/__MYSQL_USERNAME__/${__MYSQL_USERNAME__}/g" mempool-config.json
sed -i "s/__MYSQL_PASSWORD__/${__MYSQL_PASSWORD__}/g" mempool-config.json
sed -i "s!__MEMPOOL_BACKEND_MAINNET_CACHE_DIR__!${__MEMPOOL_BACKEND_MAINNET_CACHE_DIR__}!g" mempool-config.json
sed -i "s/__MEMPOOL_BACKEND_MAINNET_HTTP_PORT__/${__MEMPOOL_BACKEND_MAINNET_HTTP_PORT__}/g" mempool-config.json
sed -i "s/__MEMPOOL_BACKEND_CLEAR_PROTECTION_MINUTES__/${__MEMPOOL_BACKEND_CLEAR_PROTECTION_MINUTES__}/g" mempool-config.json
node /backend/dist/index.js
\ No newline at end of file
FROM node:12-buster-slim AS builder
ENV MEMPOOL_WEB_HOME /build/
ENV MEMPOOL_WEB_VERSION v2.2.0
ENV MEMPOOL_WEB_URL https://github.com/mempool/mempool.git
ARG MEMPOOL_WEB_LINUX_GID
ARG MEMPOOL_WEB_LINUX_UID
ENV CYPRESS_INSTALL_BINARY=0
WORKDIR /build
RUN apt-get update
RUN apt-get install -y build-essential rsync git
RUN cd ${MEMPOOL_WEB_HOME} && git clone -b ${MEMPOOL_WEB_VERSION} ${MEMPOOL_WEB_URL}
RUN cd mempool/frontend && \
npm i && \
npm run build
FROM nginx:1.17.8-alpine
WORKDIR /patch
COPY --from=builder /build/mempool/docker/frontend/entrypoint.sh .
COPY --from=builder /build/mempool/docker/frontend/wait-for .
COPY --from=builder /build/mempool/frontend/dist/mempool /var/www/mempool
COPY --from=builder /build/mempool/nginx.conf /etc/nginx/
COPY --from=builder /build/mempool/nginx-mempool.conf /etc/nginx/conf.d/
RUN chmod +x /patch/entrypoint.sh
RUN chmod +x /patch/wait-for
RUN chown -R ${MEMPOOL_WEB_LINUX_UID}:${MEMPOOL_WEB_LINUX_GID} /patch && chmod -R 755 /patch && \
chown -R ${MEMPOOL_WEB_LINUX_UID}:${MEMPOOL_WEB_LINUX_GID} /var/cache/nginx && \
chown -R ${MEMPOOL_WEB_LINUX_UID}:${MEMPOOL_WEB_LINUX_GID} /var/log/nginx && \
chown -R ${MEMPOOL_WEB_LINUX_UID}:${MEMPOOL_WEB_LINUX_GID} /etc/nginx/nginx.conf && \
chown -R ${MEMPOOL_WEB_LINUX_UID}:${MEMPOOL_WEB_LINUX_GID} /etc/nginx/conf.d
RUN touch /var/run/nginx.pid && \
chown -R ${MEMPOOL_WEB_LINUX_UID}:${MEMPOOL_WEB_LINUX_GID} /var/run/nginx.pid
USER ${MEMPOOL_WEB_LINUX_UID}
ENTRYPOINT ["/patch/entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
\ No newline at end of file
......@@ -11,6 +11,3 @@ RUN chmod u+x /update-db.sh && \
# Copy content of mysql scripts into /docker-entrypoint-initdb.d
COPY ./db-scripts/ /docker-entrypoint-initdb.d
# Copy content of mysql structure into /docker-entrypoint-initdb.d for MEMPOOL
COPY ./docker/my-dojo/mempool/mysql/ /docker-entrypoint-initdb.d
\ No newline at end of file
......@@ -12,9 +12,3 @@ if [ -f /docker-entrypoint-initdb.d/2_update.sql ]; then
mysql -h"db" -u"root" -p"$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE" < /docker-entrypoint-initdb.d/2_update.sql
echo "Updated database with 2_update.sql"
fi
### Initiate mempool database
if [ -f /docker-entrypoint-initdb.d/mariadb-structure.sql]; then
mysql -h"db" -u"$MEMPOOL_MYSQL_USER" -p"$MEMPOOL_MYSQL_PASSWORD" "$MEMPOOL_MYSQL_DATABASE" < /docker-entrypoint-initdb.d/mariadb-structure.sql
echo "Mempool database init process in progress..."
fi
\ No newline at end of file
......@@ -2,68 +2,85 @@ version: "3.7"
services:
mempool_api:
image: "samouraiwallet/dojo-mempool_api:${DOJO_MEMPOOL_API_VERSION_TAG}"
container_name: "mempool_api"
build:
dockerfile: ./docker/my-dojo/mempool/API/Dockerfile
args:
MEMPOOL_API_LINUX_UID: ${MEMPOOL_API_LINUX_UID}
MEMPOOL_API_LINUX_GID: ${MEMPOOL_API_LINUX_GID}
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"
command: "./wait-for-it.sh mempool_db:3306 --timeout=720 --strict -- ./start.sh"
volumes:
- data-mempool-api:/backend/cache
- data-mempool_api:/backend/cache
env_file:
- ./.env
- ./conf/docker-mysql.conf
- ./conf/docker-bitcoind.conf
- ./conf/docker-indexer.conf
- ./conf/docker-mempool.conf
depends-on:
- db
environment:
RPC_HOST: "bitcoind"
RPC_PORT: ${BITCOIND_RPC_PORT}
RPC_USER: ${BITCOIND_RPC_USER}
RPC_PASS: ${BITCOIND_RPC_PASSWORD}
ELECTRUM_HOST: "indexer"
ELECTRUM_PORT: ${INDEXER_RPC_PORT}
ELECTRUM_TLS: "false"
MYSQL_HOST: "mempool_db"
MYSQL_PORT: "3306"
BACKEND_MAINNET_HTTP_PORT: "8999"
CACHE_DIR: "/backend/cache"
MEMPOOL_CLEAR_PROTECTION_MINUTES: "20"
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "10"
depends_on:
- bitcoind
- indexer
- mempool_db
networks:
dojonet:
ipv4_address: ${NET_DOJO_MEMPOOL_API_IPV4}
mempool_web:
image: "samouraiwallet/dojo-mempool_web:${DOJO_MEMPOOL_WEB_VERSION_TAG}"
container_name: "mempool_web"
build:
dockerfile: ./docker/my-dojo/mempool/WEB/Dockerfile
args:
MEMPOOL_WEB_LINUX_UID: ${MEMPOOL_WEB_LINUX_UID}
MEMPOOL_WEB_LINUX_GID: ${MEMPOOL_WEB_LINUX_GID}
image: mempool/frontend:latest
user: "1000:1000"
restart: on-failure
stop_grace_period: 1m
command: "./wait-for db:3306 --timeout=720 -- strict --- ./start.sh"
ports:
- 8051:8080
command: "./wait-for mempool_db:3306 --timeout=720 -- nginx -g 'daemon off;'"
env_file:
- ./.env
- ./conf/docker-mysql.conf
- ./conf/docker-bitcoind.conf
- ./conf/docker-nginx.conf
- ./conf/docker-indexer.conf
FRONTEND_HTTP_PORT: "8080"
BACKEND_MAINNET_HTTP_HOST: "mempool_api"
environment:
FRONTEND_HTTP_PORT: "8080"
BACKEND_MAINNET_HTTP_HOST: ${NET_DOJO_MEMPOOL_API_IPV4}
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "10"
depends_on:
- tor
- nginx
- mempool_api
- db
- mempool_db
networks:
dojonet:
ipv4_address: ${NET_DOJO_MEMPOOL_WEB_IPV4}
mempool_db:
container_name: "mempool_db"
image: mariadb:10.5.8
restart: on-failure
stop_grace_period: 1m
volumes:
- data-mempool-web:/mempool/data
- data-mempool_db:/var/lib/mysql
- ./mempool/mysql/db-scripts:/docker-entrypoint-initdb.d
env_file:
- ./conf/docker-mempool.conf
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "10"
networks:
dojonet:
ipv4_address: ${NET_DOJO_MEMPOOL_WEB_IPV4}
\ No newline at end of file
ipv4_address: ${NET_DOJO_MEMPOOL_DB_IPV4}
volumes:
data-mempool_api:
data-mempool_db:
......@@ -51,7 +51,7 @@ fi
if [ "$MEMPOOL_INSTALL" == "on" ]; then
tor_options+=(--HiddenServiceDir /var/lib/tor/hsv3mempool)
tor_options+=(--HiddenServiceVersion 3)
tor_options+=(--HiddenServicePort "80 $NET_DOJO_MEMPOOL_WEB_IPV4:8051")
tor_options+=(--HiddenServicePort "80 $NET_DOJO_MEMPOOL_WEB_IPV4:8080")
tor_options+=(--HiddenServiceDirGroupReadable 1)
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment