Skip to content
Permalink
Browse files

tools/stratum_log_proxy: add a docker compose

  • Loading branch information
SwimmingTiger committed Oct 8, 2019
1 parent 4e8fb3d commit fe7692a6dc8134dc353e25a22539cc3d416e613b
@@ -17,6 +17,10 @@ tools/stratum_log_proxy/build
tools/stratum_log_proxy/build*/
tools/stratum_log_proxy/cfg
tools/stratum_log_proxy/cfg*/
tools/stratum_log_proxy/img
tools/stratum_log_proxy/img*/
tools/stratum_log_proxy/data
tools/stratum_log_proxy/data*/
tools/tls_decrypt_proxy/build
tools/tls_decrypt_proxy/build*/
tools/worker_update/build
@@ -1,2 +1,6 @@
cfg/
cfg*/
img/
img*/
data/
data*/
@@ -54,13 +54,11 @@ LABEL maintainer="Yihao Peng <yihao.peng@bitmain.com>"

ARG APT_MIRROR_URL

COPY docker/btcpool/deploy/update_apt_sources.sh /tmp/
COPY docker/btcpool/deploy/update_apt_sources.sh docker/btcpool/deploy/wait-for-it.sh /tmp/
RUN /tmp/update_apt_sources.sh

# Copy deb packages and scripts
COPY --from=build /work/build/*.deb /work/package/
#COPY --from=build /work/btcpool/install/cfg-generator /work/cfg-generator
COPY tools/stratum_log_proxy/entrypoint.sh /

# Install utilities & btcpool w/ debug symbols
RUN apt-get update \
@@ -69,4 +67,4 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["stratum_log_proxy"]
@@ -0,0 +1,32 @@
#!/bin/sh
# build/pull/export docker images
set -e

echo "build stratum-log-proxy"
cd "$( dirname "$0" )"
docker build -t stratum-log-proxy --build-arg APT_MIRROR_URL="$APT_MIRROR_URL" -f Dockerfile ../..

echo "build get-eth-header"
cd get_eth_header
docker build -t get-eth-header .

echo "pull geth"
docker pull ethereum/client-go:stable

echo "pull mariadb"
docker pull mariadb

echo "pull grafana"
docker pull grafana/grafana

echo "pull phpmyadmin"
docker pull phpmyadmin/phpmyadmin

echo 'export docker images to ./img/'
cd ../img
docker save stratum-log-proxy | gzip > stratum-log-proxy.img.gz
docker save get-eth-header | gzip > get-eth-header.img.gz
docker save ethereum/client-go:stable | gzip > geth.img.gz
docker save mariadb | gzip > mariadb.img.gz
docker save grafana/grafana | gzip > grafana.img.gz
docker save phpmyadmin/phpmyadmin | gzip > phpmyadmin.img.gz
@@ -0,0 +1,72 @@
version: '3'
services:
mysql:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: root
command: --log-error=/var/log/mysql/mysql.log
volumes:
- ./data/mysql/data:/var/lib/mysql
- ./data/mysql/sql:/docker-entrypoint-initdb.d
- ./data/mysql/log:/var/log/mysql
restart: always

eth-node:
image: ethereum/client-go:stable
entrypoint: sh
command: -c 'exec geth --syncmode light --rpc --rpcaddr 0.0.0.0 --ws --wsaddr 0.0.0.0 --verbosity 3 --nousb 2>>/root/log/geth.log'
volumes:
- ./data/eth-node/data:/root/.ethereum
- ./data/eth-node/log:/root/log
restart: always

block-update:
depends_on:
- mysql
- eth-node
image: get-eth-header
entrypoint: sh
command: -c '/tmp/wait-for-it.sh -t 60 mysql:3306; exec get_eth_header -log_dir /root/log -v 1 -mysql "root:root@tcp(mysql:3306)/proxy" -node eth-node:8546 -sqlfile /root/sql/update-share-info.sql'
volumes:
- ./data/block-update/log:/root/log
- ./data/block-update/sql:/root/sql
restart: always

proxy:
depends_on:
- mysql
image: stratum-log-proxy
entrypoint: sh
command: -c '/tmp/wait-for-it.sh -t 60 mysql:3306; exec stratum_log_proxy -c /root/cfg/stratum_log_proxy.cfg -l /root/log'
volumes:
- ./data/proxy/log:/root/log
- ./data/proxy/cfg:/root/cfg
ports:
- 3333:3333
restart: always

grafana:
depends_on:
- mysql
image: grafana/grafana
environment:
GF_LOG_MODE: file
volumes:
- ./data/grafana/data:/var/lib/grafana
- ./data/grafana/log:/var/log/grafana
ports:
- 3000:3000
restart: always

phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: mysql
entrypoint: bash
command: -c 'exec /docker-entrypoint.sh apache2-foreground &>>/var/log/phpmyadmin/phpmyadmin.log'
volumes:
- ./data/phpmyadmin/log:/var/log/phpmyadmin
ports:
- 3100:80

This file was deleted.

@@ -23,4 +23,6 @@ ARG APT_MIRROR_URL

COPY --from=build /work/get_eth_header/get_eth_header /usr/local/bin/get_eth_header

COPY update_apt_sources.sh wait-for-it.sh /tmp/

ENTRYPOINT ["get_eth_header"]
@@ -0,0 +1,11 @@
#!/bin/sh
set -e

. /etc/lsb-release

if [ -n "${APT_MIRROR_URL}" ]; then
echo "deb ${APT_MIRROR_URL} ${DISTRIB_CODENAME} main restricted universe multiverse" > /etc/apt/sources.list
for x in updates backports security; do
echo "deb ${APT_MIRROR_URL} ${DISTRIB_CODENAME}-${x} main restricted universe multiverse" >> /etc/apt/sources.list
done
fi
@@ -0,0 +1,201 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
#
# From <https://github.com/vishnubob/wait-for-it>
#
# The MIT License (MIT)
# Copyright (c) 2016 Giles Hall
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

WAITFORIT_cmdname=${0##*/}

echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
cat << USAGE >&2
Usage:
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}

wait_for()
{
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
else
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
fi
WAITFORIT_start_ts=$(date +%s)
while :
do
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
WAITFORIT_result=$?
else
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
WAITFORIT_result=$?
fi
if [[ $WAITFORIT_result -eq 0 ]]; then
WAITFORIT_end_ts=$(date +%s)
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
break
fi
sleep 1
done
return $WAITFORIT_result
}

wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
else
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
fi
WAITFORIT_PID=$!
trap "kill -INT -$WAITFORIT_PID" INT
wait $WAITFORIT_PID
WAITFORIT_RESULT=$?
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
fi
return $WAITFORIT_RESULT
}

# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
WAITFORIT_hostport=(${1//:/ })
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
shift 1
;;
--child)
WAITFORIT_CHILD=1
shift 1
;;
-q | --quiet)
WAITFORIT_QUIET=1
shift 1
;;
-s | --strict)
WAITFORIT_STRICT=1
shift 1
;;
-h)
WAITFORIT_HOST="$2"
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
WAITFORIT_HOST="${1#*=}"
shift 1
;;
-p)
WAITFORIT_PORT="$2"
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
WAITFORIT_PORT="${1#*=}"
shift 1
;;
-t)
WAITFORIT_TIMEOUT="$2"
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
WAITFORIT_TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
WAITFORIT_CLI=("$@")
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done

if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi

WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}

# check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
WAITFORIT_ISBUSY=1
WAITFORIT_BUSYTIMEFLAG="-t"

else
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
fi

if [[ $WAITFORIT_CHILD -gt 0 ]]; then
wait_for
WAITFORIT_RESULT=$?
exit $WAITFORIT_RESULT
else
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
wait_for_wrapper
WAITFORIT_RESULT=$?
else
wait_for
WAITFORIT_RESULT=$?
fi
fi

if [[ $WAITFORIT_CLI != "" ]]; then
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
exit $WAITFORIT_RESULT
fi
exec "${WAITFORIT_CLI[@]}"
else
exit $WAITFORIT_RESULT
fi
@@ -0,0 +1,11 @@
#!/bin/sh
# import docker images
set -e

cd "$( dirname "$0" )/img"
docker load -i stratum-log-proxy.img.gz
docker load -i get-eth-header.img.gz
docker load -i geth.img.gz
docker load -i mariadb.img.gz
docker load -i grafana.img.gz
docker load -i phpmyadmin.img.gz

0 comments on commit fe7692a

Please sign in to comment.
You can’t perform that action at this time.