This commit is contained in:
Dread 2022-03-14 08:38:46 -07:00
parent 1caaca2f1d
commit e9ba57ce43
6 changed files with 142 additions and 141 deletions

View File

@ -1,36 +1,55 @@
# Creating the builder image to install the backend and frontend package managers
FROM node:16-buster-slim AS builder
WORKDIR /build
COPY mempool/ .
# because just a submodule in wrapper project
RUN rm .git
RUN sh docker/init.sh
# generate-config.js uses this ref
COPY .git/modules/mempool/refs/heads/master .git/refs/heads/master
RUN apt-get update
RUN apt-get install -y build-essential python3 pkg-config rsync
WORKDIR /build/frontend
RUN npm i
RUN npm run build
WORKDIR /build/backend
RUN npm ci --production
RUN npm i typescript
RUN npm run build
WORKDIR /build
RUN cp docker/backend/mempool-config.json backend/
FROM node:16-buster-slim
WORKDIR /
COPY mempool/ .
RUN rm .git && sh docker/init.sh
COPY .git/modules/mempool/refs/heads/master .git/refs/heads/master
RUN apt-get update && apt-get install -y build-essential python3 pkg-config rsync \
wget netcat jq pwgen vim procps nano \
mariadb-server mariadb-client nginx \
&& wget https://github.com/mikefarah/yq/releases/download/v4.6.3/yq_linux_arm.tar.gz -O - |\
tar xz && mv yq_linux_arm /usr/bin/yq
WORKDIR /backend
RUN npm install --prod && npm run build && cp mempool-config.sample.json mempool-config.json
WORKDIR /frontend
RUN npm install --prod && npm run build && rsync -av --delete dist/ /var/www/
RUN apt-get update
RUN apt-get install wget netcat jq pwgen vim procps -y
RUN apt-get install nginx -y
RUN wget https://github.com/mikefarah/yq/releases/download/v4.6.3/yq_linux_arm.tar.gz -O - |\
tar xz && mv yq_linux_arm /usr/bin/yq
RUN apt-get install mariadb-server mariadb-client -y
WORKDIR /
# install the mempool configuration for nginx
RUN cp nginx.conf /etc/nginx/ && cp nginx-mempool.conf /etc/nginx/conf.d/ && cp nginx-mempool.conf /etc/nginx/nginx-mempool.conf
RUN cp /frontend/wait-for /usr/local/bin/wait-for.sh
# RUN cp /frontend/dist/mempool /var/www/mempool
WORKDIR /backend
USER root
RUN cp wait-for-it.sh /usr/local/bin \
&& chmod +x start.sh \
&& chmod +x /backend/wait-for-it.sh \
&& chmod +x /usr/local/bin/wait-for.sh \
&& mkdir -p data mysql/data mysql/db-scripts
COPY --from=builder /build/backend .
COPY --from=builder /build/frontend/wait-for /usr/local/bin/wait-for.sh
COPY --from=builder /build/frontend/dist/mempool /var/www/mempool
COPY --from=builder /build/nginx.conf /etc/nginx/
COPY --from=builder /build/nginx-mempool.conf /etc/nginx/conf.d/
COPY --from=builder /build/nginx-mempool.conf /etc/nginx/nginx-mempool.conf
RUN cp wait-for-it.sh /usr/local/bin
RUN chmod +x start.sh
RUN chmod +x /backend/wait-for-it.sh
RUN chmod +x /usr/local/bin/wait-for.sh
# initalize db folders
RUN mkdir -p data mysql/data mysql/db-scripts
RUN mkdir /var/cache/nginx
RUN touch /var/run/nginx.pid
@ -46,10 +65,11 @@ RUN touch /var/run/nginx.pid && \
# BUILD S9 CUSTOM
ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
# remove default mysql so we can manually handle db initalization
# remove to we can manually handle db initalization
RUN rm -rf /var/lib/mysql/
# USER 1000
EXPOSE 8080 8999 80
ENTRYPOINT ["/usr/local/bin/docker_entrypoint.sh"]
ENTRYPOINT ["/usr/local/bin/docker_entrypoint.sh"]
# CMD ["nginx", "-g", "daemon off;"]

View File

@ -0,0 +1,6 @@
- rule: "txindex?"
description: "Must have transaction indexing enabled"
suggestions:
- SET:
var: "txindex"
to-value: true

View File

@ -16,13 +16,13 @@ lan-address:
interface: main
bitcoin:
type: object
name: Bitcoin Core RPC
name: Bitcoin Core
description: The Bitcoin Core node to connect to over the RPC interface
nullable: false
spec:
bitcoind-rpc:
type: union
name: Bitcoin Core RPC
name: Bitcoin Core RPC Credentials for Mempool
description: The Bitcoin Core node to connect to over the RPC interface
tag:
id: type

View File

@ -6,38 +6,42 @@ _term() {
kill -TERM "$backend_process" 2>/dev/null
kill -TERM "$db_process" 2>/dev/null
kill -TERM "$frontend_process" 2>/dev/null
kill -TERM "$mempool_child" 2>/dev/null
kill -TERM "$configure" 2>/dev/null
}
# FRONTEND SETUP
__MEMPOOL_BACKEND_MAINNET_HTTP_HOST__=${BACKEND_MAINNET_HTTP_HOST:=127.0.0.1}
__MEMPOOL_BACKEND_MAINNET_HTTP_PORT__=${BACKEND_MAINNET_HTTP_PORT:=8999}
__MEMPOOL_FRONTEND_HTTP_PORT__=${FRONTEND_HTTP_PORT:=8080}
__MEMPOOL_FRONTEND_HTTP_PORT__=${FRONTEND_HTTP_PORT:=80}
sed -i "s/__MEMPOOL_BACKEND_MAINNET_HTTP_HOST__/${__MEMPOOL_BACKEND_MAINNET_HTTP_HOST__}/g" /etc/nginx/conf.d/nginx-mempool.conf
sed -i "s/__MEMPOOL_BACKEND_MAINNET_HTTP_PORT__/${__MEMPOOL_BACKEND_MAINNET_HTTP_PORT__}/g" /etc/nginx/conf.d/nginx-mempool.conf
cp /etc/nginx/conf.d/nginx-mempool.conf /etc/nginx/nginx-mempool.conf
# rm /etc/nginx/sites-enabled/default
# /etc/init.d/nginx restart
cp /etc/nginx/nginx.conf /backend/nginx.conf
sed -i "s/__MEMPOOL_FRONTEND_HTTP_PORT__/${__MEMPOOL_FRONTEND_HTTP_PORT__}/g" /backend/nginx.conf
cat /backend/nginx.conf > /etc/nginx/nginx.conf
# echo "daemon off;" >> /etc/nginx/nginx.conf
# BACKEND SETUP
echo -e 'setting variables...'
# read bitcoin proxy creds from start9 config
export HOST_IP=$(ip -4 route list match 0/0 | awk '{print $3}')
export LAN_ADDRESS=$(yq e '.lan-address' /root/start9/config.yaml)
export RPC_HOST=$(yq e '.lan-address' /root/start9/config.yaml)
export RPC_USER=$(yq e '.bitcoin.bitcoind-rpc.rpc-user' /root/start9/config.yaml)
export RPC_PASS=$(yq e '.bitcoin.bitcoind-rpc.rpc-password' /root/start9/config.yaml)
# configure mempool to use just a bitcoind backend
# echo -e 'Modifying start.sh...'
# sed -i '/^node \/backend\/dist\/index.js/i jq \x27.MEMPOOL.BACKEND="none"\x27 \/backend\/mempool-config.json > \/backend\/mempool-config.json.tmp && mv \/backend\/mempool-config.json.tmp \/backend\/mempool-config.json' start.sh
# sed -i 's/CORE_RPC_HOST:=127.0.0.1/CORE_RPC_HOST:=btc-rpc-proxy.embassy/' start.sh
# sed -i 's/MEMPOOL_BACKEND:=electrum/MEMPOOL_BACKEND:=none/' start.sh
# sed -i 's/CORE_RPC_USERNAME:=mempool/CORE_RPC_USERNAME:='$RPC_USER'/' start.sh
# sed -i 's/CORE_RPC_PASSWORD:=mempool/CORE_RPC_PASSWORD:='$RPC_PASS'/' start.sh
echo -e 'Modifying mempool-config.json...'
sed -i -e '1,4 s/electrum/none/' -e '20,28 s/127.0.0.1/btc-rpc-proxy.embassy/' -e '20,28 s/"USERNAME": "mempool"/"USERNAME": "'$RPC_USER'"/' -e '20,28 s/"PASSWORD": "mempool"/"PASSWORD": "'$RPC_PASS'"/' mempool-config.json
sed -i '29,33 s/true/false/' mempool-config.json
sed -i '/^node \/backend\/dist\/index.js/i jq \x27.MEMPOOL.BACKEND="none"\x27 \/backend\/mempool-config.json > \/backend\/mempool-config.json.tmp && mv \/backend\/mempool-config.json.tmp \/backend\/mempool-config.json' start.sh
sed -i 's/CORE_RPC_HOST:=127.0.0.1/CORE_RPC_HOST:=btc-rpc-proxy.embassy/' start.sh
sed -i 's/MEMPOOL_BACKEND:=electrum/MEMPOOL_BACKEND:=none/' start.sh
sed -i 's/CORE_RPC_USERNAME:=mempool/CORE_RPC_USERNAME:='$RPC_USER'/' start.sh
sed -i 's/CORE_RPC_PASSWORD:=mempool/CORE_RPC_PASSWORD:='$RPC_PASS'/' start.sh
# DATABASE SETUP
if [ -d "/run/mysqld" ]; then
echo "[i] mysqld already present, skipping creation"
chown -R mysql:mysql /run/mysqld
@ -46,13 +50,16 @@ else
mkdir -p /run/mysqld
chown -R mysql:mysql /run/mysqld
fi
if [ -d /var/lib/mysql/mysql ]; then
echo "[i] MySQL directory already present, skipping creation"
chown -R mysql:mysql /var/lib/mysql
else
echo "[i] MySQL data directory not found, creating initial DBs"
mkdir -p /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
mysql_install_db --user=mysql --ldata=/var/lib/mysql > /dev/null
if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then
@ -60,26 +67,31 @@ else
echo "[i] MySQL root Password: $MYSQL_ROOT_PASSWORD"
export MYSQL_ROOT_PASSWORD
fi
MYSQL_DATABASE=${MYSQL_DATABASE:-"mempool"}
MYSQL_USER=${MYSQL_USER:-"mempool"}
MYSQL_PASSWORD=${MYSQL_PASSWORD:-"mempool"}
tfile=`mktemp`
if [ ! -f "$tfile" ]; then
return 1
fi
cat << EOF > $tfile
USE mysql;
FLUSH PRIVILEGES ;
GRANT ALL ON *.* TO 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION ;
GRANT ALL ON *.* TO 'root'@'localhost' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION ;
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('${MYSQL_ROOT_PASSWORD}') ;
DROP DATABASE IF EXISTS mempool ;
DROP DATABASE IF EXISTS test ;
FLUSH PRIVILEGES ;
EOF
if [ "$MYSQL_DATABASE" != "" ]; then
echo "[i] Creating database: $MYSQL_DATABASE"
echo "[i] with character set: 'utf8' and collation: 'utf8_general_ci'"
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile
if [ "$MYSQL_USER" != "" ]; then
echo "[i] Creating user: $MYSQL_USER with password $MYSQL_PASSWORD"
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
@ -87,8 +99,11 @@ EOF
echo "FLUSH PRIVILEGES;" >> $tfile
fi
fi
/usr/sbin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < $tfile
rm -f $tfile
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sql) echo "$0: running $f"; /usr/sbin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
@ -97,20 +112,30 @@ EOF
esac
echo
done
echo
echo 'MySQL init process done. Starting mysqld...'
echo
fi
/usr/bin/mysqld_safe --user=mysql --datadir='/var/lib/mysql' & db_process=$!
/usr/bin/mysqld_safe --user=mysql --datadir='/var/lib/mysql' &
db_process=$!
# START UP
npm run start & mempool_child=$!
sed -i "s/user nobody;//g" /etc/nginx/nginx.conf
nginx -g 'daemon off;' & frontend_process=$!
# replace example.com with your domain name
# certbot --nginx -d $LAN_ADDRESS
echo 'All processes initalized'
# wait-for.sh 127.0.0.1:3306 --timeout=720 -- nginx -g 'daemon off;' &
# frontend_process=$!
nginx -g 'daemon off;' &
frontend_process=$!
/backend/wait-for-it.sh 127.0.0.1:3306 --timeout=60 --strict -- /backend/start.sh
&
backend_process=$!
echo 'All processes initalized'
# ERROR HANDLING
trap _term SIGTERM
wait -n $mempool_child
wait -n $db_process $backend_process $frontend_process
# exec "$@"

View File

@ -1,6 +1,6 @@
id: mempool
title: mempool.space
version: 2.3.1.0
version: 2.3.1
release-notes: Initial release for Embassy 0.3.0.
license: mit
wrapper-repo: "https://github.com/Start9Labs/mempool-wrapper"
@ -108,6 +108,42 @@ dependencies:
main: /root
compat: /mnt/assets
io-format: yaml
bitcoind:
version: "^0.21.1.2"
requirement:
type: "opt-out"
how: Can alternatively configure an external bitcoin node.
description: Used to subscribe to new block events.
config:
check:
type: docker
image: compat
system: true
entrypoint: compat
args:
- dependency
- check
- mempool
- bitcoind
- /root
- "/mnt/assets/bitcoind_config_rules.yaml"
mounts:
compat: /mnt/assets
main: /root
auto-configure:
type: docker
image: compat
system: true
entrypoint: compat
args:
- dependency
- "auto-configure"
- mempool
- bitcoind
- /root
- "/mnt/assets/bitcoind_config_rules.yaml"
mounts:
compat: /mnt/assets
volumes:
main:
type: data
@ -119,11 +155,11 @@ interfaces:
description: Specifies the mempool interface to listen on for HTTP connections.
tor-config:
port-mapping:
80: "8999"
80: "80"
lan-config:
443:
ssl: true
internal: 8999
internal: 80
ui: true
protocols:
- tcp

View File

@ -1,86 +0,0 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
CREATE TABLE `blocks` (
`height` int(11) NOT NULL,
`hash` varchar(65) NOT NULL,
`size` int(11) NOT NULL,
`weight` int(11) NOT NULL,
`minFee` int(11) NOT NULL,
`maxFee` int(11) NOT NULL,
`time` int(11) NOT NULL,
`fees` double NOT NULL,
`nTx` int(11) NOT NULL,
`medianFee` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `statistics` (
`id` int(11) NOT NULL,
`added` datetime NOT NULL,
`unconfirmed_transactions` int(11) UNSIGNED NOT NULL,
`tx_per_second` float UNSIGNED NOT NULL,
`vbytes_per_second` int(10) UNSIGNED NOT NULL,
`mempool_byte_weight` int(10) UNSIGNED NOT NULL,
`fee_data` longtext NOT NULL,
`total_fee` double UNSIGNED NOT NULL,
`vsize_1` int(11) NOT NULL,
`vsize_2` int(11) NOT NULL,
`vsize_3` int(11) NOT NULL,
`vsize_4` int(11) NOT NULL,
`vsize_5` int(11) NOT NULL,
`vsize_6` int(11) NOT NULL,
`vsize_8` int(11) NOT NULL,
`vsize_10` int(11) NOT NULL,
`vsize_12` int(11) NOT NULL,
`vsize_15` int(11) NOT NULL,
`vsize_20` int(11) NOT NULL,
`vsize_30` int(11) NOT NULL,
`vsize_40` int(11) NOT NULL,
`vsize_50` int(11) NOT NULL,
`vsize_60` int(11) NOT NULL,
`vsize_70` int(11) NOT NULL,
`vsize_80` int(11) NOT NULL,
`vsize_90` int(11) NOT NULL,
`vsize_100` int(11) NOT NULL,
`vsize_125` int(11) NOT NULL,
`vsize_150` int(11) NOT NULL,
`vsize_175` int(11) NOT NULL,
`vsize_200` int(11) NOT NULL,
`vsize_250` int(11) NOT NULL,
`vsize_300` int(11) NOT NULL,
`vsize_350` int(11) NOT NULL,
`vsize_400` int(11) NOT NULL,
`vsize_500` int(11) NOT NULL,
`vsize_600` int(11) NOT NULL,
`vsize_700` int(11) NOT NULL,
`vsize_800` int(11) NOT NULL,
`vsize_900` int(11) NOT NULL,
`vsize_1000` int(11) NOT NULL,
`vsize_1200` int(11) NOT NULL,
`vsize_1400` int(11) NOT NULL,
`vsize_1600` int(11) NOT NULL,
`vsize_1800` int(11) NOT NULL,
`vsize_2000` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `transactions` (
`blockheight` int(11) NOT NULL,
`txid` varchar(65) NOT NULL,
`fee` double NOT NULL,
`feePerVsize` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `blocks`
ADD PRIMARY KEY (`height`);
ALTER TABLE `statistics`
ADD PRIMARY KEY (`id`);
ALTER TABLE `transactions`
ADD PRIMARY KEY (`txid`),
ADD KEY `blockheight` (`blockheight`);
ALTER TABLE `statistics`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;