updated backend for mempool v2
This commit is contained in:
parent
6abfb8d9c2
commit
1caaca2f1d
78
Dockerfile
78
Dockerfile
@ -1,57 +1,36 @@
|
||||
FROM node:16-buster-slim AS builder
|
||||
|
||||
WORKDIR /build
|
||||
COPY mempool/ .
|
||||
ADD ./mariadb-structure.sql .
|
||||
# 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/
|
||||
|
||||
# Creating the builder image to install the backend and frontend package managers
|
||||
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
|
||||
|
||||
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 /frontend
|
||||
RUN npm install --prod && npm run build && rsync -av --delete dist/ /var/www/
|
||||
|
||||
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
|
||||
COPY --from=builder /build/mariadb-structure.sql .
|
||||
|
||||
RUN mkdir /var/cache/nginx
|
||||
RUN touch /var/run/nginx.pid
|
||||
@ -67,13 +46,10 @@ RUN touch /var/run/nginx.pid && \
|
||||
# BUILD S9 CUSTOM
|
||||
ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
|
||||
|
||||
ADD ./mariadb-structure.sql /docker-entrypoint-initdb.d/
|
||||
|
||||
# remove default mysql so 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"]
|
||||
# CMD ["nginx", "-g", "daemon off;"]
|
||||
ENTRYPOINT ["/usr/local/bin/docker_entrypoint.sh"]
|
||||
@ -6,6 +6,14 @@ tor-address:
|
||||
package-id: mempool
|
||||
target: tor-address
|
||||
interface: main
|
||||
lan-address:
|
||||
name: Network LAN Address
|
||||
description: The LAN address for the network interface.
|
||||
type: pointer
|
||||
subtype: package
|
||||
package-id: mempool
|
||||
target: lan-address
|
||||
interface: main
|
||||
bitcoin:
|
||||
type: object
|
||||
name: Bitcoin Core RPC
|
||||
|
||||
@ -6,40 +6,38 @@ _term() {
|
||||
kill -TERM "$backend_process" 2>/dev/null
|
||||
kill -TERM "$db_process" 2>/dev/null
|
||||
kill -TERM "$frontend_process" 2>/dev/null
|
||||
kill -TERM "$configure" 2>/dev/null
|
||||
kill -TERM "$mempool_child" 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}
|
||||
|
||||
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 RPC_HOST=$(yq e '.bitcoin.rpc-host' /root/start9/config.yaml)
|
||||
export RPC_USER=$(yq e '.bitcoin.rpc-user' /root/start9/config.yaml)
|
||||
export RPC_PASS=$(yq e '.bitcoin.rpc-password' /root/start9/config.yaml)
|
||||
|
||||
export LAN_ADDRESS=$(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
|
||||
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
|
||||
# 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
|
||||
|
||||
# DATABASE SETUP
|
||||
|
||||
if [ -d "/run/mysqld" ]; then
|
||||
echo "[i] mysqld already present, skipping creation"
|
||||
chown -R mysql:mysql /run/mysqld
|
||||
@ -48,16 +46,13 @@ 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
|
||||
@ -65,33 +60,26 @@ 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"}
|
||||
|
||||
sed -i "1s/^/USE ${MYSQL_DATABASE};\n/" /docker-entrypoint-initdb.d/mariadb-structure.sql
|
||||
|
||||
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 test ;
|
||||
DROP DATABASE IF EXISTS mempool ;
|
||||
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
|
||||
@ -99,11 +87,8 @@ 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 ;;
|
||||
@ -112,30 +97,20 @@ 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
|
||||
# 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=$!
|
||||
|
||||
nginx -g 'daemon off;' & frontend_process=$!
|
||||
# replace example.com with your domain name
|
||||
# certbot --nginx -d $LAN_ADDRESS
|
||||
echo 'All processes initalized'
|
||||
|
||||
# ERROR HANDLING
|
||||
trap _term SIGTERM
|
||||
|
||||
wait -n $db_process $backend_process $frontend_process
|
||||
# exec "$@"
|
||||
wait -n $mempool_child
|
||||
|
||||
@ -1 +1,5 @@
|
||||
git --git-dir=mempool/.git name-rev --tags --name-only $(git --git-dir=mempool/.git rev-parse HEAD) | sed 's|\([^\^]*\)\(\^0\)$|\1|g'
|
||||
export MEMPOOL_VERSION=$(awk 'match($0,/version:[^ ]*/){ print substr($0, RSTART+9,5)}' manifest.yaml | awk 'NR == 1')
|
||||
echo 'v'$MEMPOOL_VERSION
|
||||
|
||||
# Old method of getting the Version number from mempool/mempool, does not work.
|
||||
#git --git-dir=mempool/.git name-rev --tags --name-only $(git --git-dir=mempool/.git rev-parse HEAD) | sed 's|\([^\^]*\)\(\^0\)$|\1|g'
|
||||
@ -115,18 +115,15 @@ volumes:
|
||||
type: assets
|
||||
interfaces:
|
||||
main:
|
||||
name: Browser Interface
|
||||
description: Specifies the interface to listen on for HTTP connections.
|
||||
name: Mempool Interface
|
||||
description: Specifies the mempool interface to listen on for HTTP connections.
|
||||
tor-config:
|
||||
port-mapping:
|
||||
8080: "8080"
|
||||
80: "8999"
|
||||
lan-config:
|
||||
8999:
|
||||
ssl: false
|
||||
443:
|
||||
ssl: true
|
||||
internal: 8999
|
||||
80:
|
||||
ssl: false
|
||||
internal: 80
|
||||
ui: true
|
||||
protocols:
|
||||
- tcp
|
||||
|
||||
Loading…
Reference in New Issue
Block a user