diff --git a/Dockerfile b/Dockerfile index ef4d68f5..fdd00ef0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,11 @@ FROM golang:1.20-alpine as builder RUN apk add --no-cache gcc musl-dev linux-headers +# Get dependencies - will also be cached if we won't change go.mod/go.sum +COPY go.mod /es-node/ +COPY go.sum /es-node/ +RUN cd /es-node && go mod download + ADD . /es-node RUN cd /es-node/cmd/es-node && go build RUN cd /es-node/cmd/es-utils && go build diff --git a/GUIDE.md b/GUIDE.md index 40fb6711..91baec9e 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -19,7 +19,7 @@ For a detailed explanation for es-node please refer to the [README](/README.md). ## System Environment - Ubuntu 20.04+ (has been tested with) - (Optional) Docker 24.0.5+ (would simplify the process) - - (Optional) go 1.20+ and node 16+ (can be installed following the [steps](#1-install-go-120-eg-v1213)) + - (Optional) go 1.20.* (can't be built on Go 1.21 yet) and node 16+ (can be installed following the [steps](#1-install-go-120-eg-v1213)) You can choose [how to run es-node](#step-3-run-es-node) according to your current environment. ## Step 1. Prepare miner and signer account @@ -32,7 +32,7 @@ Remember to use the signer's private key (with ETH balance) to replace ` ES_NODE_SIGNER_PRIVATE_KEY= ./run-docker.sh +if [ -z "$ES_NODE_STORAGE_MINER" ]; then + echo "Please provide 'ES_NODE_STORAGE_MINER' as an environment variable" + exit 1 +fi + +if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || case $ES_NODE_STORAGE_MINER in 0x*) false;; *) true;; esac; then + echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x' and have a total length of 42" + exit 1 +fi + +if [ -z "$ES_NODE_SIGNER_PRIVATE_KEY" ]; then + echo "Please provide 'ES_NODE_SIGNER_PRIVATE_KEY' as an environment variable" + exit 1 +fi + +if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then + echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should have a length of 64" + exit 1 +fi + container_name="es" image_name="es-node" # check if container is running -if docker ps --format "{{.Names}}" | grep -q "^$container_name$"; then +if sudo docker ps --format "{{.Names}}" | grep -q "^$container_name$"; then echo "container $container_name already started" else # start container if exist - if docker ps -a --format "{{.Names}}" | grep -q "^$container_name$"; then - docker start $container_name + if sudo docker ps -a --format "{{.Names}}" | grep -q "^$container_name$"; then + sudo docker start $container_name echo "container $container_name started" else # build an image if not exist - if ! docker images --format "{{.Repository}}" | grep -q "^$image_name$"; then - docker build -t $image_name . + if ! sudo docker images --format "{{.Repository}}" | grep -q "^$image_name$"; then + sudo docker build -t $image_name . echo "image $image_name built" fi # run container in the background - docker run --name $container_name -v ./es-data:/es-node/es-data -e ES_NODE_STORAGE_MINER=$ES_NODE_STORAGE_MINER -e ES_NODE_SIGNER_PRIVATE_KEY=$ES_NODE_SIGNER_PRIVATE_KEY -p 9545:9545 -p 9222:9222 -p 30305:30305/udp -d --entrypoint /es-node/run.sh $image_name + sudo docker run --name $container_name \ + -v ./es-data:/es-node/es-data \ + -e ES_NODE_STORAGE_MINER=$ES_NODE_STORAGE_MINER \ + -e ES_NODE_SIGNER_PRIVATE_KEY=$ES_NODE_SIGNER_PRIVATE_KEY \ + -p 9545:9545 \ + -p 9222:9222 \ + -p 30305:30305/udp \ + -d \ + --entrypoint /es-node/run.sh \ + $image_name echo "container $container_name started" fi fi diff --git a/run.sh b/run.sh index 25ff6862..5044b5e1 100644 --- a/run.sh +++ b/run.sh @@ -4,12 +4,22 @@ # env ES_NODE_STORAGE_MINER= ES_NODE_SIGNER_PRIVATE_KEY= ./run.sh if [ -z "$ES_NODE_STORAGE_MINER" ]; then - echo "Please provide 'ES_NODE_STORAGE_MINER' as environment variable" + echo "Please provide 'ES_NODE_STORAGE_MINER' as an environment variable" + exit 1 +fi + +if [ ${#ES_NODE_STORAGE_MINER} -ne 42 ] || case $ES_NODE_STORAGE_MINER in 0x*) false;; *) true;; esac; then + echo "Error: ES_NODE_STORAGE_MINER should be prefixed with '0x' and have a total length of 42" exit 1 fi if [ -z "$ES_NODE_SIGNER_PRIVATE_KEY" ]; then - echo "Please provide 'ES_NODE_SIGNER_PRIVATE_KEY' as environment variable" + echo "Please provide 'ES_NODE_SIGNER_PRIVATE_KEY' as an environment variable" + exit 1 +fi + +if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then + echo "Error: ES_NODE_SIGNER_PRIVATE_KEY should have a length of 64" exit 1 fi @@ -55,8 +65,12 @@ es_node_start=" --network devnet \ " # create data file for shard 0 if not yet if [ ! -e $storage_file_0 ]; then - $executable $es_node_init $common_flags - echo "initialized ${storage_file_0}" + if $executable $es_node_init $common_flags ; then + echo "initialized ${storage_file_0} successfully" + else + echo "failed to initialize ${storage_file_0}" + exit 1 + fi fi # start es-node