forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-docker-miner.sh
executable file
·80 lines (64 loc) · 2.41 KB
/
run-docker-miner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
#
# This is an EXAMPLE of how to run itcoin's miner in a container, connecting to
# a bitcoin daemon running on a separate container.
#
# Like bitcoind, this script shows that the container entrypoint is able to
# dynamically configure the software components using environment variables.
#
# The containers are run in host network mode, and thus the "--publish"
# arguments are not relevant. They are kept for documentation purposes, should
# we want to migrate to bridge networking mode.
# USAGE:
# ./run-miner.sh ADDRESS < --set-block-time -1 | --ongoing >
set -eu
# https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself#246128
MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ITCOIN_IMAGE_NAME="arthub.azurecr.io/itcoin-core"
# this uses the current checked out version. If you want to use a different
# version, you'll have to modify this variable, for now.
ITCOIN_IMAGE_TAG="git-"$("${MYDIR}"/compute-git-hash.sh)
CONTAINER_NAME="itcoin-miner"
EXTERNAL_DATADIR="${MYDIR}/datadir"
INTERNAL_DATADIR="/opt/itcoin-core/datadir"
BITCOIN_PORT=38333
# BLOCKSCRIPT is not relevant for miner
BLOCKSCRIPT="NOT_RELEVANT"
RPC_HOST=127.0.0.1 # localhost would fail if the system is ipv6-only
RPC_PORT=38332
# ZMQ_PUBHASHTX_PORT is not relevant for miner
ZMQ_PUBHASHTX_PORT="NOT_RELEVANT"
# ZMQ_PUBRAWBLOCK_PORT is not relevant for miner
ZMQ_PUBRAWBLOCK_PORT="NOT_RELEVANT"
# ZMQ_PUBITCOINBLOCK_PORT is not relevant for miner
ZMQ_PUBITCOINBLOCK_PORT="NOT_RELEVANT"
errecho() {
# prints to stderr
>&2 echo "${@}"
}
ITCOIN_IMAGE="${ITCOIN_IMAGE_NAME}:${ITCOIN_IMAGE_TAG}"
errecho "Using itcoin docker image ${ITCOIN_IMAGE}"
ADDRESS=$1
shift
docker run \
--read-only \
--name "${CONTAINER_NAME}" \
--user "$(id --user):$(id --group)" \
--rm \
--env BITCOIN_PORT="${BITCOIN_PORT}" \
--env BLOCKSCRIPT="${BLOCKSCRIPT}" \
--env RPC_HOST="${RPC_HOST}" \
--env RPC_PORT="${RPC_PORT}" \
--env ZMQ_PUBHASHTX_PORT="${ZMQ_PUBHASHTX_PORT}" \
--env ZMQ_PUBRAWBLOCK_PORT="${ZMQ_PUBRAWBLOCK_PORT}" \
--env ZMQ_PUBITCOINBLOCK_PORT="${ZMQ_PUBITCOINBLOCK_PORT}" \
--network=host \
--tmpfs /opt/itcoin-core/configdir \
--mount type=bind,source="${EXTERNAL_DATADIR}",target="${INTERNAL_DATADIR}",readonly \
"${ITCOIN_IMAGE}" \
miner \
generate \
--address "${ADDRESS}" \
--grind-cmd='bitcoin-util grind' \
--min-nbits \
"${@}"