Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerized nodejs pool #482

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.git/
35 changes: 35 additions & 0 deletions deployment/docker/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM "ubuntu:16.04"

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y upgrade

RUN DEBIAN_FRONTEND=noninteractive apt-get -y install git curl python-virtualenv python3-virtualenv \
build-essential libzmq3-dev libboost-all-dev sudo mysql-server && \
rm -rf /var/lib/apt/lists/*
# ntp screen cmake pkg-config libevent-dev libunbound-dev \
# libminiupnpc-dev libunwind8-dev liblzma-dev libldns-dev libexpat1-dev libgtest-dev mysql-server \
# lmdb-utils libsodium-dev

RUN useradd -ms /bin/bash pool
ENV CURUSER=pool
ENV POOL_DIR=/home/pool
ENV PATH=${PATH}:/home/pool/.nodejs/bin:/home/pool/.bin

ADD deployment/docker/backend/start.bash /home/pool/start.bash
ADD deployment/docker/backend/stack.yml /home/pool/stack.yml

COPY . /home/pool/pool
RUN chown -R pool /home/pool/pool

USER pool
WORKDIR /home/pool

ARG DB_STORAGE_PATH
ARG DB_HOST
ARG DB_NAME
ARG DB_USER
ARG DB_PASS

RUN cd /home/pool/pool/deployment/docker/backend; ./build.bash

ENTRYPOINT /home/pool/start.bash

237 changes: 237 additions & 0 deletions deployment/docker/backend/base.sql

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions deployment/docker/backend/build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e

WORKDIR=$(mktemp -d)

echo "+ Installing wait utility (wait for mysql before starting)"
mkdir $POOL_DIR/.bin
cd $POOL_DIR/.bin
curl -Lo ./wait-util https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait
chmod +x ./wait-util

echo "+ Setting up NodeJS"
curl -o$WORKDIR/node.tar.gz https://nodejs.org/dist/latest-v8.x/node-v8.17.0-linux-x64.tar.gz
cd $WORKDIR
tar -xf node.tar.gz
mv node-v8.17.0-linux-x64/ $POOL_DIR/.nodejs/

# echo "+ Cloning nodejs-pool source"
# cd $POOL_DIR
# git clone https://github.com/Snipa22/nodejs-pool.git pool

echo "+ Installing nodejs-pool dependencies"
mkdir -p $POOL_DIR/pool_db/ $POOL_DIR/keys
cd $POOL_DIR/pool
npm install --production
npm install -g pm2
openssl req -subj "/C=IT/ST=Pool/L=Daemon/O=Mining Pool/CN=mining.pool" -newkey rsa:2048 -nodes -keyout cert.key -x509 -out cert.pem -days 36500

echo "+ Installing pm2-logrotate"
pm2 install pm2-logrotate

# cd ~/nodejs-pool/sql_sync/
# env PATH=$PATH:`pwd`/.nvm/versions/node/v8.9.3/bin node sql_sync.js
echo "You're setup! Please read the rest of the readme for the remainder of your setup and configuration. These steps include: Setting your Fee Address, Pool Address, Global Domain, and the Mailgun setup!"
37 changes: 37 additions & 0 deletions deployment/docker/backend/stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
apps:
- name: api
log_date_format: "YYYY-MM-DD HH:mm Z"
script: init.js
args: "--module=api"

- name: remoteShare
log_date_format: "YYYY-MM-DD HH:mm Z"
script: init.js
args: "--module=remoteShare"

- name: pool
log_date_format: "YYYY-MM-DD HH:mm Z"
script: init.js
args: "--module=pool"

- name: longRunner
log_date_format: "YYYY-MM-DD HH:mm Z"
script: init.js
args: "--module=longRunner"

- name: payments
log_date_format: "YYYY-MM-DD HH:mm Z"
script: init.js
args: "--module=payments"

- name: blockManager
log_date_format: "YYYY-MM-DD HH:mm Z"
script: init.js
args: "--module=blockManager"

- name: worker
log_date_format: "YYYY-MM-DD HH:mm Z"
script: init.js
args: "--module=worker"

54 changes: 54 additions & 0 deletions deployment/docker/backend/start.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

set -eo pipefail

DB_STORAGE_PATH=${DB_STORAGE_PATH:-$POOL_DIR/pool_db}
COIN=${COIN:-xmr}

cd $POOL_DIR/pool
cat > config.json <<-EOF
{
"pool_id": 0,
"bind_ip": "0.0.0.0",
"hostname": "${POOL_HOSTNAME}",
"db_storage_path": "${DB_STORAGE_PATH}",
"coin": "${COIN}",
"mysql": {
"connectionLimit": 20,
"host": "${DB_HOST}",
"database": "${DB_NAME}",
"user": "${DB_USER}",
"password": "${DB_PASS}"
}
}
EOF

echo "Waiting for MySQL to come online"
WAIT_HOSTS=$DB_HOST:$DB_PORT wait-util

function exec_sql() {
mysql -u root --password=$ROOT_SQL_PASS -h ${DB_HOST} -sN pool -e "$@"
}

cd ~/pool

RESULT=`exec_sql "SELECT COUNT(1) \
FROM information_schema.tables \
WHERE table_schema = 'pool' \
LIMIT 1"`
if [[ "$RESULT" == "0" ]]; then
echo "+ Setting up pool database"
exec_sql "CREATE USER IF NOT EXISTS pool@'%' IDENTIFIED BY '$DB_USER';";
exec_sql "FLUSH PRIVILEGES;"
mysql -u root --password=$ROOT_SQL_PASS -h ${DB_HOST} < deployment/docker/api/base.sql
exec_sql "INSERT INTO pool.config (module, item, item_value, item_type, Item_desc) VALUES ('api', 'authKey', '`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`', 'string', 'Auth key sent with all Websocket frames for validation.')"
exec_sql "INSERT INTO pool.config (module, item, item_value, item_type, Item_desc) VALUES ('api', 'secKey', '`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`', 'string', 'HMAC key for Passwords. JWT Secret Key. Changing this will invalidate all current logins.')"
else
echo "+ Pool database already setup"
fi

pushd sql_sync/
node sql_sync
popd

pm2-runtime ./deployment/docker/backend/stack.yml --only "$ENABLED_DAEMONS"
21 changes: 21 additions & 0 deletions deployment/docker/monerod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:18.04 as build

RUN apt-get update && apt-get install -y curl
RUN cd /tmp && curl -L https://downloads.getmonero.org/cli/monero-linux-x64-v0.17.1.6.tar.bz2 -o monero.tar.gz && \
cd /tmp && mkdir /monero && tar -xjf monero.tar.gz -C /monero && cd /monero && mv monero-x86_64-linux-gnu-v0.17.1.6/* .

# COPY monero.tar.gz /tmp

FROM ubuntu:18.04

COPY --from=build /monero /monero

RUN useradd -ms /bin/bash monero
USER monero
RUN if [ -d /home/monero/monero-blockchain ]; then monero-blockchain-import /home/monero/monero-blockchain/blockchain.raw; fi

WORKDIR /monero
ENTRYPOINT /monero/monerod



10 changes: 10 additions & 0 deletions deployment/docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM "node:8" as build

ADD build.bash /build.bash
RUN /build.bash

FROM "nginx:1.19.5"

COPY --from=build /build /www


14 changes: 14 additions & 0 deletions deployment/docker/web/build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

TMP=$(mktemp -d)

cd $TMP
git clone -b sb-app-cache-fix https://github.com/tari-project/poolui.git poolui
cd $TMP/poolui
npm install
npx bower update --allow-root
npx gulp build
ls
mv build /build
34 changes: 34 additions & 0 deletions deployment/docker/web/templates/web.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
upstream poolApi {
server pool-backend:8001;
}

upstream remoteShare {
server pool-backend:8000;
}

server {
listen 80;
server_name ${WEB_HOSTNAME};

location / {
root /www;
index index.html index.htm;
}
}


server {
listen 80;
server_name ${API_HOSTNAME};

location /leafApi {
proxy_pass http://remoteShare;
}

location / {
proxy_pass http://poolApi;
}

}


Empty file modified deployment/install_lmdb_tools.sh
100644 → 100755
Empty file.
Empty file modified deployment/leaf.bash
100644 → 100755
Empty file.
Empty file modified deployment/upgrade_monero.bash
100644 → 100755
Empty file.
127 changes: 127 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
version: '3.8'
services:
monero-init:
entrypoint: /bin/sh -c "chown -Rv monero /home/monero/.bitmonero"
user: root
restart: "no"
volumes:
- monero-data:/home/monero/.bitmonero
build:
context: ./deployment/docker/monerod

monerod:
container_name: pool-monerod
image: tari/monerod
build:
context: ./deployment/docker/monerod
user: monero
networks:
- monero
volumes:
- monero-data:/home/monero/.bitmonero
depends_on:
- monero-init
ports:
- 18080:18080
- 18089:18089
entrypoint: "/monero/monerod"
command:
- "--non-interactive"
- "--restricted-rpc"
- "--rpc-bind-ip=0.0.0.0"
- "--rpc-bind-port=18089"
- "--confirm-external-bind"
- "--max-concurrency=4"
- "--public-node"
- "--limit-rate-up=1024"
- "--limit-rate-down=2048"
- "--stagenet"

db:
image: mysql:5.7
environment:
MYSQL_DATABASE: 'pool'
# So you don't have to use root, but you can if you like
MYSQL_USER: 'pool'
# You can use whatever password you like
MYSQL_PASSWORD: 'password'
# Password for root access
MYSQL_ROOT_PASSWORD: 'password'
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3306:3306'
expose:
# Opens port 3306 on the container
- '3306'
# Where our data will be persisted
volumes:
- backend-db:/var/lib/mysql
networks:
- database

pool-backend:
image: nodejs-pool
build:
context: ./
dockerfile: ./deployment/docker/backend/Dockerfile
args:
- DB_STORAGE_PATH=/home/pool/pool_db
- DB_HOST=db
- DB_NAME=pool
- DB_USER=pool
- DB_PASS=password
volumes:
- lmdb:/home/pool/pool_db
- ./lib:/home/pool/pool/lib
ports:
- 8001:8001
- 3333:3333
- 5555:5555
- 7777:7777
- 9000:9000
networks:
- monero
- database
- web-proxy
environment:
# - ENABLED_DAEMONS=blockManager
# - ENABLED_DAEMONS=api,remoteShare,pool,longRunner,payments,blockManager
- ENABLED_DAEMONS=api,remoteShare,pool,longRunner,payments,blockManager,worker
- DB_HOST=db
- DB_PORT=3306
- DB_NAME=pool
- DB_USER=pool
- DB_PASS=password
- ROOT_SQL_PASS=password
- HOSTNAME=xmrpool.test
- COIN=xmr

pool-web:
image: pool-web
build:
context: ./deployment/docker/web
volumes:
- web-assets:/var/www
- ./deployment/docker/web/templates/:/etc/nginx/templates
environment:
# Can set these in your hosts file when testing
- API_HOSTNAME=api.xmrtaripool.test
- WEB_HOSTNAME=xmrtaripool.test
depends_on:
- pool-backend
ports:
- 80:80
- 443:443
networks:
- web-proxy

volumes:
backend-db:
lmdb:
monero-data:
web-assets:

networks:
database:
web-proxy:
monero:
Loading