mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-17 00:47:03 +00:00
Merge pull request #1245 from status-im/docker
new Docker image for shared testnets
This commit is contained in:
commit
79f60968b9
@ -3,7 +3,7 @@ FROM debian:bullseye-slim AS build
|
|||||||
SHELL ["/bin/bash", "-c"]
|
SHELL ["/bin/bash", "-c"]
|
||||||
|
|
||||||
RUN apt-get -qq update \
|
RUN apt-get -qq update \
|
||||||
&& apt-get -qq -y install build-essential make wget libpcre3-dev golang-go git &>/dev/null \
|
&& apt-get -qq -y install build-essential libpcre3-dev git &>/dev/null \
|
||||||
&& apt-get -qq clean \
|
&& apt-get -qq clean \
|
||||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
@ -11,8 +11,7 @@ RUN apt-get -qq update \
|
|||||||
RUN cd /root \
|
RUN cd /root \
|
||||||
&& git clone https://github.com/status-im/nim-beacon-chain.git \
|
&& git clone https://github.com/status-im/nim-beacon-chain.git \
|
||||||
&& cd nim-beacon-chain \
|
&& cd nim-beacon-chain \
|
||||||
&& make -j$(nproc) update \
|
&& make -j$(nproc) update
|
||||||
&& make deps
|
|
||||||
|
|
||||||
# Please note that the commands above have the goal of caching the
|
# Please note that the commands above have the goal of caching the
|
||||||
# compilation of Nim, but don't depend on the current git revision.
|
# compilation of Nim, but don't depend on the current git revision.
|
||||||
|
15
docker/shared_testnet/Dockerfile
Normal file
15
docker/shared_testnet/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
FROM debian:bullseye-slim
|
||||||
|
|
||||||
|
SHELL ["/bin/bash", "-c"]
|
||||||
|
|
||||||
|
RUN apt-get -qq update \
|
||||||
|
&& apt-get -qq -y install build-essential libpcre3-dev git &>/dev/null \
|
||||||
|
&& apt-get -qq clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
ARG NETWORK
|
||||||
|
ENV NETWORK=${NETWORK}
|
||||||
|
|
||||||
|
STOPSIGNAL SIGINT
|
||||||
|
ENTRYPOINT ["/root/nim-beacon-chain/docker/shared_testnet/entry_point.sh"]
|
||||||
|
|
28
docker/shared_testnet/Makefile
Normal file
28
docker/shared_testnet/Makefile
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
SHELL := bash # the shell used internally by "make"
|
||||||
|
|
||||||
|
# These default settings can be overriden by exporting env variables
|
||||||
|
|
||||||
|
NETWORK ?= witti
|
||||||
|
IMAGE_TAG ?= testnet2
|
||||||
|
IMAGE_NAME ?= statusteam/nimbus_beacon_node:$(IMAGE_TAG)
|
||||||
|
|
||||||
|
CURRENT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
|
||||||
|
COMPUTER_SAYS_NO = { echo "I'm sorry, Dave. I'm afraid I can't do that."; exit 1; }
|
||||||
|
|
||||||
|
.PHONY: build push push-last
|
||||||
|
|
||||||
|
build:
|
||||||
|
@ DOCKER_BUILDKIT=1 \
|
||||||
|
docker build \
|
||||||
|
--build-arg="NETWORK=$(NETWORK)" \
|
||||||
|
-t $(IMAGE_NAME) \
|
||||||
|
--progress=plain \
|
||||||
|
.
|
||||||
|
|
||||||
|
push: build
|
||||||
|
+@ $(MAKE) push-last
|
||||||
|
|
||||||
|
push-last:
|
||||||
|
@ [[ "$(CURRENT_BRANCH)" != "devel" ]] && $(COMPUTER_SAYS_NO) || true
|
||||||
|
docker push $(IMAGE_NAME)
|
||||||
|
|
15
docker/shared_testnet/README.md
Normal file
15
docker/shared_testnet/README.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
## local testing
|
||||||
|
|
||||||
|
From the "nim-beacon-chain" dir:
|
||||||
|
|
||||||
|
```text
|
||||||
|
make -C docker/shared_testnet build
|
||||||
|
mkdir tmp
|
||||||
|
docker run --rm --mount type=bind,source="$(pwd)"/tmp,target=/root/.cache/nimbus --name testnet2 statusteam/nimbus_beacon_node:testnet2 --build
|
||||||
|
ls -l tmp/nim-beacon-chain/build
|
||||||
|
docker run --rm --mount type=bind,source="$(pwd)"/tmp,target=/root/.cache/nimbus --name testnet2 -p 127.0.0.1:8008:8008 -p 9000:9000 statusteam/nimbus_beacon_node:testnet2 --run -- --metrics-address=0.0.0.0
|
||||||
|
# from another terminal
|
||||||
|
docker ps
|
||||||
|
docker stop testnet2
|
||||||
|
```
|
||||||
|
|
93
docker/shared_testnet/entry_point.sh
Executable file
93
docker/shared_testnet/entry_point.sh
Executable file
@ -0,0 +1,93 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||||
|
|
||||||
|
####################
|
||||||
|
# argument parsing #
|
||||||
|
####################
|
||||||
|
! getopt --test > /dev/null
|
||||||
|
if [ ${PIPESTATUS[0]} != 4 ]; then
|
||||||
|
echo '`getopt --test` failed in this environment.'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
OPTS="h"
|
||||||
|
LONGOPTS="help,build,run"
|
||||||
|
|
||||||
|
# default values
|
||||||
|
BUILD=0
|
||||||
|
RUN=0
|
||||||
|
|
||||||
|
print_help() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $(basename $0) <options> -- <beacon_node options>
|
||||||
|
|
||||||
|
-h, --help this help message
|
||||||
|
--build build the beacon_node
|
||||||
|
--run run the beacon_node
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
! PARSED=$(getopt --options=${OPTS} --longoptions=${LONGOPTS} --name "$0" -- "$@")
|
||||||
|
if [ ${PIPESTATUS[0]} != 0 ]; then
|
||||||
|
# getopt has complained about wrong arguments to stdout
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# read getopt's output this way to handle the quoting right
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
print_help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
--build)
|
||||||
|
BUILD=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--run)
|
||||||
|
RUN=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "argument parsing error"
|
||||||
|
print_help
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
EXTRA_ARGS="$@"
|
||||||
|
|
||||||
|
#########
|
||||||
|
# build #
|
||||||
|
#########
|
||||||
|
|
||||||
|
if [[ "$BUILD" == "1" ]]; then
|
||||||
|
# "/root/.cache/nimbus" is the external bind-mounted dir, preserved between runs
|
||||||
|
cd /root/.cache/nimbus
|
||||||
|
[[ -d nim-beacon-chain ]] || git clone https://github.com/status-im/nim-beacon-chain.git
|
||||||
|
cd nim-beacon-chain
|
||||||
|
git config pull.rebase false
|
||||||
|
git checkout devel
|
||||||
|
git pull
|
||||||
|
make -j$(nproc) update
|
||||||
|
make LOG_LEVEL="TRACE" NIMFLAGS="-d:insecure -d:testnet_servers_image" SCRIPT_PARAMS="--skipGoerliKey --writeLogFile=false --buildOnly" ${NETWORK}
|
||||||
|
fi
|
||||||
|
|
||||||
|
#######
|
||||||
|
# run #
|
||||||
|
#######
|
||||||
|
|
||||||
|
if [[ "$RUN" == "1" ]]; then
|
||||||
|
cd /root/.cache/nimbus/nim-beacon-chain
|
||||||
|
# make sure Docker's SIGINT reaches the beacon_node binary
|
||||||
|
eval $(make SCRIPT_PARAMS="--skipGoerliKey --writeLogFile=false --runOnly --printCmdOnly" ${NETWORK} | tail -n 1) ${EXTRA_ARGS}
|
||||||
|
fi
|
||||||
|
|
@ -68,15 +68,14 @@ proc becomeValidator(validatorsDir, beaconNodeBinary, secretsDir, depositContrac
|
|||||||
discard readLineFromStdin()
|
discard readLineFromStdin()
|
||||||
|
|
||||||
proc runNode(dataDir, beaconNodeBinary, bootstrapFileOpt, depositContractOpt, genesisFileOpt: string,
|
proc runNode(dataDir, beaconNodeBinary, bootstrapFileOpt, depositContractOpt, genesisFileOpt: string,
|
||||||
basePort, nodeID, baseMetricsPort, baseRpcPort: int) =
|
basePort, nodeID, baseMetricsPort, baseRpcPort: int, printCmdOnly: bool) =
|
||||||
let logLevel = getEnv("LOG_LEVEL")
|
let logLevel = getEnv("LOG_LEVEL")
|
||||||
var logLevelOpt = ""
|
var logLevelOpt = ""
|
||||||
if logLevel.len > 0:
|
if logLevel.len > 0:
|
||||||
logLevelOpt = &"""--log-level="{logLevel}" """
|
logLevelOpt = &"""--log-level="{logLevel}" """
|
||||||
|
|
||||||
mode = Verbose
|
mode = Verbose
|
||||||
cd dataDir
|
let cmd = replace(&"""{beaconNodeBinary}
|
||||||
execIgnoringExitCode replace(&"""{beaconNodeBinary}
|
|
||||||
--data-dir="{dataDir}"
|
--data-dir="{dataDir}"
|
||||||
--dump
|
--dump
|
||||||
--web3-url={web3Url}
|
--web3-url={web3Url}
|
||||||
@ -91,6 +90,12 @@ proc runNode(dataDir, beaconNodeBinary, bootstrapFileOpt, depositContractOpt, ge
|
|||||||
{depositContractOpt}
|
{depositContractOpt}
|
||||||
{genesisFileOpt} """, "\n", " ")
|
{genesisFileOpt} """, "\n", " ")
|
||||||
|
|
||||||
|
if printCmdOnly:
|
||||||
|
echo &"cd {dataDir}; exec {cmd}"
|
||||||
|
else:
|
||||||
|
cd dataDir
|
||||||
|
execIgnoringExitCode cmd
|
||||||
|
|
||||||
cli do (skipGoerliKey {.
|
cli do (skipGoerliKey {.
|
||||||
desc: "Don't prompt for an Eth1 Goerli key to become a validator" .}: bool,
|
desc: "Don't prompt for an Eth1 Goerli key to become a validator" .}: bool,
|
||||||
|
|
||||||
@ -123,6 +128,9 @@ cli do (skipGoerliKey {.
|
|||||||
runOnly {.
|
runOnly {.
|
||||||
desc: "Just run it." .} = false,
|
desc: "Just run it." .} = false,
|
||||||
|
|
||||||
|
printCmdOnly {.
|
||||||
|
desc: "Just print the commands (suitable for passing to 'eval'; might replace current shell)." .} = false,
|
||||||
|
|
||||||
testnetName {.argument .}: string):
|
testnetName {.argument .}: string):
|
||||||
let
|
let
|
||||||
nameParts = testnetName.split "/"
|
nameParts = testnetName.split "/"
|
||||||
@ -222,5 +230,5 @@ cli do (skipGoerliKey {.
|
|||||||
|
|
||||||
if not buildOnly:
|
if not buildOnly:
|
||||||
runNode(dataDir, beaconNodeBinary, bootstrapFileOpt, depositContractOpt, genesisFileOpt,
|
runNode(dataDir, beaconNodeBinary, bootstrapFileOpt, depositContractOpt, genesisFileOpt,
|
||||||
basePort, nodeID, baseMetricsPort, baseRpcPort)
|
basePort, nodeID, baseMetricsPort, baseRpcPort, printCmdOnly)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user