diff --git a/ci/build-docker-image.sh b/ci/build-docker-image.sh index e5e34488..6268adb3 100755 --- a/ci/build-docker-image.sh +++ b/ci/build-docker-image.sh @@ -1,8 +1,17 @@ #!/bin/bash set -eu +if [ "$#" -lt 2 ]; then + echo 'Usage: build-docker-image.sh [...]' >&2 + exit 1 +fi + +dockerFile="$1" +dockerTag="$2" +shift; shift + scripts="$(dirname "$0")" -"$scripts"/custom-timeout.sh 20 docker pull "$2" || true -echo "Building $2" -"$scripts"/custom-timeout.sh 30 docker build -f "$1" -t "$2" --cache-from "$2" . +"$scripts"/custom-timeout.sh 20 docker pull "${dockerTag}" || true +echo "Building $dockerTag" +"$scripts"/custom-timeout.sh 30 docker build "$@" -f "${dockerFile}" -t "${dockerTag}" --cache-from "${dockerTag}" . diff --git a/ci/deploy-docker.sh b/ci/deploy-docker.sh index 7669e33c..d82a3984 100755 --- a/ci/deploy-docker.sh +++ b/ci/deploy-docker.sh @@ -15,13 +15,23 @@ elif [ -n "$TRAVIS_TAG" ]; then tags+=("$TRAVIS_TAG" latest) fi -ci/build-docker-image.sh docker/node/Dockerfile nanocurrency/nano -for tag in "${tags[@]}"; do - # Sanitize docker tag - # https://docs.docker.com/engine/reference/commandline/tag/ - tag="$(printf '%s' "$tag" | tr -c '[a-z][A-Z][0-9]_.-' -)" - if [ "$tag" != "latest" ]; then - docker tag nanocurrency/nano nanocurrency/nano:"$tag" +for network in live beta; do + if [ "${network}" = 'live' ]; then + network_tag_suffix='' + else + network_tag_suffix="-${network}" fi - "$scripts"/custom-timeout.sh 30 docker push nanocurrency/nano:"$tag" + + docker_image_name="nanocurrency/nano${network_tag_suffix}" + + ci/build-docker-image.sh docker/node/Dockerfile "$docker_image_name" --build-arg NETWORK="${network}" + for tag in "${tags[@]}"; do + # Sanitize docker tag + # https://docs.docker.com/engine/reference/commandline/tag/ + tag="$(printf '%s' "$tag" | tr -c '[a-z][A-Z][0-9]_.-' -)" + if [ "$tag" != "latest" ]; then + docker tag "$docker_image_name" "${docker_image_name}:$tag" + fi + "$scripts"/custom-timeout.sh 30 docker push "${docker_image_name}:$tag" + done done diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index dfbe1521..ece9f9a4 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -1,35 +1,31 @@ FROM ubuntu:16.04 -ENV BOOST_BASENAME=boost_1_66_0 \ - BOOST_ROOT=/tmp/boost_install \ - BOOST_URL=https://netix.dl.sourceforge.net/project/boost/boost/1.66.0/boost_1_66_0.tar.gz +ARG NETWORK=live + +ENV BOOST_ROOT=/tmp/boost_install + +ADD ci /tmp/ci RUN apt-get update -qq && apt-get install -yqq \ build-essential \ cmake \ g++ \ wget && \ - wget -qO ${BOOST_BASENAME}.tar.gz ${BOOST_URL} && \ - tar xzf ${BOOST_BASENAME}.tar.gz && \ - cd ${BOOST_BASENAME} && \ - ./bootstrap.sh && \ - ./b2 -d0 --prefix=${BOOST_ROOT} link=static install && \ - rm -rf ${BOOST_BASENAME} && \ - rm -f ${BOOST_BASENAME}.tar.gz && \ - cd .. && \ - mkdir /usr/share/raiblocks/ + /tmp/ci/bootstrap_boost.sh -m ADD ./ /tmp/src RUN mkdir /tmp/build && \ cd /tmp/build && \ - cmake /tmp/src -DBOOST_ROOT=${BOOST_ROOT} && \ + cmake /tmp/src -DBOOST_ROOT=${BOOST_ROOT} -DACTIVE_NETWORK=rai_${NETWORK}_network && \ make rai_node && \ - cd .. + cd .. && \ + echo ${NETWORK} > /etc/nano-network FROM ubuntu:16.04 COPY --from=0 /tmp/build/rai_node /usr/bin +COPY --from=0 /etc/nano-network /etc COPY docker/node/entry.sh /entry.sh -COPY docker/node/config.json /usr/share/raiblocks/config.json +COPY docker/node/config /usr/share/raiblocks/config RUN chmod +x /entry.sh CMD ["/bin/bash", "/entry.sh"] diff --git a/docker/node/build.sh b/docker/node/build.sh index c873913b..7885e5eb 100755 --- a/docker/node/build.sh +++ b/docker/node/build.sh @@ -1,6 +1,42 @@ #!/bin/bash + +network='live' + +print_usage() { + echo 'build.sh [-h] [-n {live|beta|test}]' +} + +while getopts 'hn:' OPT; do + case "${OPT}" in + h) + print_usage + exit 0 + ;; + n) + network="${OPTARG}" + ;; + *) + print_usage >&2 + exit 1 + ;; + esac +done + +case "${network}" in + live) + network_tag='' + ;; + test|beta) + network_tag="-${network}" + ;; + *) + echo "Invalid network: ${network}" >&2 + exit 1 + ;; +esac + REPO_ROOT=`git rev-parse --show-toplevel` COMMIT_SHA=`git rev-parse --short HEAD` pushd $REPO_ROOT -docker build -f docker/node/Dockerfile -t raiblocks-node:latest . +docker build --build-arg NETWORK="${network}" -f docker/node/Dockerfile -t raiblocks-node${network_tag}:latest . popd diff --git a/docker/node/config/beta.json b/docker/node/config/beta.json new file mode 100644 index 00000000..2443091b --- /dev/null +++ b/docker/node/config/beta.json @@ -0,0 +1,67 @@ +{ + "version": "2", + "rpc_enable": "true", + "rpc": { + "address": "::ffff:0.0.0.0", + "port": "7076", + "enable_control": "true", + "frontier_request_limit": "16384", + "chain_request_limit": "16384" + }, + "node": { + "version": "8", + "peering_port": "7075", + "bootstrap_fraction_numerator": "1", + "receive_minimum": "1000000000000000000000000", + "logging": { + "version": "2", + "ledger": "false", + "ledger_duplicate": "false", + "vote": "false", + "network": "true", + "network_message": "false", + "network_publish": "false", + "network_packet": "false", + "network_keepalive": "false", + "node_lifetime_tracing": "false", + "insufficient_work": "true", + "log_rpc": "true", + "bulk_pull": "false", + "work_generation_time": "true", + "log_to_cerr": "false", + "max_size": "16777216", + "rotation_size": "4194304", + "flush": "false" + }, + "work_peers": "", + "preconfigured_peers": [ + "rai-beta.raiblocks.net" + ], + "preconfigured_representatives": [ + "xrb_3arg3asgtigae3xckabaaewkx3bzsh7nwz7jkmjos79ihyaxwphhm6qgjps4", + "xrb_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou", + "xrb_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p", + "xrb_3dmtrrws3pocycmbqwawk6xs7446qxa36fcncush4s1pejk16ksbmakis78m", + "xrb_3hd4ezdgsp15iemx7h81in7xz5tpxi43b6b41zn3qmwiuypankocw3awes5k", + "xrb_1awsn43we17c1oshdru4azeqjz9wii41dy8npubm4rg11so7dx3jtqgoeahy", + "xrb_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs", + "xrb_1hza3f7wiiqa7ig3jczyxj5yo86yegcmqk3criaz838j91sxcckpfhbhhra1" + ], + "inactive_supply": "0", + "password_fanout": "1024", + "io_threads": "4", + "work_threads": "4", + "enable_voting": "true", + "bootstrap_connections": "16", + "callback_address": "", + "callback_port": "0", + "callback_target": "", + "lmdb_max_dbs": "128" + }, + "opencl_enable": "false", + "opencl": { + "platform": "0", + "device": "0", + "threads": "1048576" + } +} diff --git a/docker/node/config.json b/docker/node/config/live.json similarity index 100% rename from docker/node/config.json rename to docker/node/config/live.json diff --git a/docker/node/config/test.json b/docker/node/config/test.json new file mode 100644 index 00000000..bdd6c191 --- /dev/null +++ b/docker/node/config/test.json @@ -0,0 +1,67 @@ +{ + "version": "2", + "rpc_enable": "true", + "rpc": { + "address": "::ffff:0.0.0.0", + "port": "7076", + "enable_control": "true", + "frontier_request_limit": "16384", + "chain_request_limit": "16384" + }, + "node": { + "version": "8", + "peering_port": "7075", + "bootstrap_fraction_numerator": "1", + "receive_minimum": "1000000000000000000000000", + "logging": { + "version": "2", + "ledger": "false", + "ledger_duplicate": "false", + "vote": "false", + "network": "true", + "network_message": "false", + "network_publish": "false", + "network_packet": "false", + "network_keepalive": "false", + "node_lifetime_tracing": "false", + "insufficient_work": "true", + "log_rpc": "true", + "bulk_pull": "false", + "work_generation_time": "true", + "log_to_cerr": "false", + "max_size": "16777216", + "rotation_size": "4194304", + "flush": "false" + }, + "work_peers": "", + "preconfigured_peers": [ + "rai-test.raiblocks.net" + ], + "preconfigured_representatives": [ + "xrb_3arg3asgtigae3xckabaaewkx3bzsh7nwz7jkmjos79ihyaxwphhm6qgjps4", + "xrb_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou", + "xrb_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p", + "xrb_3dmtrrws3pocycmbqwawk6xs7446qxa36fcncush4s1pejk16ksbmakis78m", + "xrb_3hd4ezdgsp15iemx7h81in7xz5tpxi43b6b41zn3qmwiuypankocw3awes5k", + "xrb_1awsn43we17c1oshdru4azeqjz9wii41dy8npubm4rg11so7dx3jtqgoeahy", + "xrb_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs", + "xrb_1hza3f7wiiqa7ig3jczyxj5yo86yegcmqk3criaz838j91sxcckpfhbhhra1" + ], + "inactive_supply": "0", + "password_fanout": "1024", + "io_threads": "4", + "work_threads": "4", + "enable_voting": "true", + "bootstrap_connections": "16", + "callback_address": "", + "callback_port": "0", + "callback_target": "", + "lmdb_max_dbs": "128" + }, + "opencl_enable": "false", + "opencl": { + "platform": "0", + "device": "0", + "threads": "1048576" + } +} diff --git a/docker/node/entry.sh b/docker/node/entry.sh index a38dc03d..02d38d09 100644 --- a/docker/node/entry.sh +++ b/docker/node/entry.sh @@ -1,10 +1,27 @@ #!/bin/bash + set -euo pipefail IFS=$'\n\t' -mkdir -p ~/RaiBlocks -if [ ! -f ~/RaiBlocks/config.json ]; then - echo "Config File not found, adding default." - cp /usr/share/raiblocks/config.json ~/RaiBlocks/ +network="$(cat /etc/nano-network)" +case "${network}" in + live|'') + network='live' + dirSuffix='' + ;; + beta) + dirSuffix='Beta' + ;; + test) + dirSuffix='Test' + ;; +esac + +nanodir="${HOME}/RaiBlocks${dirSuffix}" +mkdir -p "${nanodir}" +if [ ! -f "${nanodir}/config.json" ]; then + echo "Config File not found, adding default." + cp "/usr/share/raiblocks/config/${network}.json" "${nanodir}/config.json" fi + /usr/bin/rai_node --daemon