From 0f680e887a62b31b8f6390452d26fe14293024e6 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Fri, 21 Jun 2019 19:36:19 +0300 Subject: [PATCH] A safer wrapper script for launching the beacon node containers in docker --- docker/beacon_node/Dockerfile | 5 ++-- docker/beacon_node/run_in_docker.sh | 7 ++++++ docker/hosts.nims | 36 ++++++++++++++--------------- scripts/create_nimble_link.sh | 6 ++--- vendor/nim-beacon-chain | 2 +- 5 files changed, 32 insertions(+), 24 deletions(-) create mode 100755 docker/beacon_node/run_in_docker.sh diff --git a/docker/beacon_node/Dockerfile b/docker/beacon_node/Dockerfile index a9132722b..d3b5a2ed8 100644 --- a/docker/beacon_node/Dockerfile +++ b/docker/beacon_node/Dockerfile @@ -21,7 +21,7 @@ RUN export GOROOT=/usr/local/go \ && git reset --hard ${GIT_REVISION} \ && make update deps vendor/go/bin/p2pd nat-libs \ && cp vendor/go/bin/p2pd /usr/bin/p2pd \ - && cat vendor/.nimble/pkgs/*/* + && cp docker/beacon_node/run_in_docker.sh /usr/bin/run_beacon_node.sh ARG NETWORK ARG NETWORK_TYPE @@ -53,9 +53,10 @@ RUN apt update \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* COPY --from=build /usr/bin/beacon_node /usr/bin/beacon_node +COPY --from=build /usr/bin/run_beacon_node.sh /usr/bin/run_beacon_node.sh COPY --from=build /usr/bin/p2pd /usr/bin/p2pd MAINTAINER Zahary Karadjov LABEL description="Nimbus installation that can act as an ETH2 network bootstrap node." -ENTRYPOINT ["/usr/bin/beacon_node"] +ENTRYPOINT ["/usr/bin/run_beacon_node.sh"] diff --git a/docker/beacon_node/run_in_docker.sh b/docker/beacon_node/run_in_docker.sh new file mode 100755 index 000000000..16ec78a0a --- /dev/null +++ b/docker/beacon_node/run_in_docker.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +killall p2pd +rm -rf /tmp/* + +beacon_node $* + diff --git a/docker/hosts.nims b/docker/hosts.nims index e7bbccb3c..b652fd9d0 100644 --- a/docker/hosts.nims +++ b/docker/hosts.nims @@ -1,4 +1,5 @@ -import strformat +import + strformat var serverCount = 10 @@ -11,8 +12,7 @@ var validatorsPerServer = systemValidators div serverCount validatorsPerNode = validatorsPerServer div instancesCount - network = "testnet1" - buildFlavour = "libp2p_spec" + network = "testnet0" type ContainerCmd = enum @@ -22,23 +22,23 @@ type iterator containers: tuple[cmd: ContainerCmd, node, container: string, firstValidator, lastValidator: int] = for i in 0 ..< serverCount: let baseIdx = userValidators + i * validatorsPerServer - for j in 0 ..< instancesCount: + for j in 1 .. instancesCount: let firstIdx = baseIdx + j * validatorsPerNode let lastIdx = firstIdx + validatorsPerNode - 1 - yield (restart, &"nimbus-node-0{i}", &"beacon-node-{buildFlavour}-{network}-{j}", firstIdx, lastIdx) - for j in instancesCount .. 2: - yield (stop, &"nimbus-node-0{i}", &"beacon-node-{buildFlavour}-{network}-{j}", -1, -1) + yield (restart, &"nimbus-node-0{i}", &"beacon-node-{network}-{j}", firstIdx, lastIdx) -for i in 0 ..< serverCount: - let baseIdx = userValidators + i * validatorsPerServer - for j in 1 .. instancesCount: - let firstIdx = baseIdx + (j - 1) * validatorsPerNode - let lastIdx = firstIdx + validatorsPerNode - 1 - let dockerPath = &"/docker/beacon-node-{buildFlavour}-{network}-{j}/data/BeaconNode/{network}" - echo &"ssh nimbus-node-0{i} 'sudo mkdir -p {dockerPath}/validators && sudo rm -f {dockerPath}/validators/* && " & - &"sudo ~/nimbus/vendor/nim-beacon-chain/scripts/download_validator_keys.sh {network} {firstIdx} {lastIdx} {dockerPath} && " & - &"sudo chown dockremap:docker -R {dockerPath}'" +when false: + for i in 0 ..< serverCount: + let baseIdx = userValidators + i * validatorsPerServer + for j in 1 .. instancesCount: + let firstIdx = baseIdx + (j - 1) * validatorsPerNode + let lastIdx = firstIdx + validatorsPerNode - 1 + let dockerPath = &"/docker/beacon-node-{network}-{j}/data/BeaconNode/{network}" + + echo &"ssh nimbus-node-0{i} 'sudo mkdir -p {dockerPath}/validators && sudo rm -f {dockerPath}/validators/* && " & + &"sudo ~/nimbus/vendor/nim-beacon-chain/scripts/download_validator_keys.sh {network} {firstIdx} {lastIdx} {dockerPath} && " & + &"sudo chown dockremap:docker -R {dockerPath}'" -# for c in containers(): -# echo &"ssh {c.node} docker {c.cmd} {c.container}" +for c in containers(): + echo &"ssh {c.node} docker {c.cmd} {c.container}" diff --git a/scripts/create_nimble_link.sh b/scripts/create_nimble_link.sh index e0dd313cf..84745207d 100644 --- a/scripts/create_nimble_link.sh +++ b/scripts/create_nimble_link.sh @@ -4,10 +4,10 @@ module_name="${1#*/}" if [ `ls -1 *.nimble 2>/dev/null | wc -l ` -gt 0 ]; then mkdir -p "${NIMBLE_DIR}/pkgs/${module_name}-#head" - PKG_DIR="$(${PWD_CMD})" - if [ -d src ]; then + PKG_DIR="$(${PWD_CMD})" + if [ -d src ]; then PKG_DIR="${PKG_DIR}/src" fi - echo -e "${PKG_DIR}\n${PKG_DIR}" > "${NIMBLE_DIR}/pkgs/${module_name}-#head/${module_name}.nimble-link" + echo -e "${PKG_DIR}\n${PKG_DIR}" > "${NIMBLE_DIR}/pkgs/${module_name}-#head/${module_name}.nimble-link" fi diff --git a/vendor/nim-beacon-chain b/vendor/nim-beacon-chain index 681fc2dd3..855d141cf 160000 --- a/vendor/nim-beacon-chain +++ b/vendor/nim-beacon-chain @@ -1 +1 @@ -Subproject commit 681fc2dd36ff865c6dae50ed5b69587bc235e2a4 +Subproject commit 855d141cf2660d7a22699a29f05215c1be7a56e3