diff --git a/DOCKER/Dockerfile b/DOCKER/Dockerfile index 74345aec37e1e7c126fdacb9ddb31d83f4003ba3..f354a3010c58365c1ee71c30a0b21c90bad6aca8 100644 --- a/DOCKER/Dockerfile +++ b/DOCKER/Dockerfile @@ -25,7 +25,7 @@ RUN mkdir --parents $GOPATH/src/$REPO WORKDIR $GOPATH/src/$REPO RUN git clone https://$REPO . && \ git checkout $BRANCH && \ - go build -o ./build/tendermint ./cmd/tendermint + go build -o ./build/tendermint ./cmd/tendermint && \ mv ./build/tendermint /usr/local/bin/tendermint # set the repo and install erisdb @@ -39,6 +39,10 @@ RUN cd ./cmd/erisdb && \ go build && \ mv erisdbss /usr/local/bin/ +# install chain manager scripts +COPY ./DOCKER/chain_* /usr/local/bin/ +ENV ECM_PATH /usr/local/bin + # set the repo and install mint-client ENV REPO github.com/eris-ltd/mint-client ENV BRANCH master @@ -61,4 +65,4 @@ RUN mkdir --parents /home/$USER/.eris/blockchains/tendermint ENV TMROOT /home/$USER/.eris/blockchains/tendermint # run tendermint -CMD ["erisdb-wrapper"] +ENTRYPOINT ["erisdb-wrapper"] diff --git a/DOCKER/build.sh b/DOCKER/build.sh index 0ed34a66641945e6017401b9f5419ae90bac14ec..aa51ef77f1ef72fbd1a490ad1d3d90455271bc5d 100755 --- a/DOCKER/build.sh +++ b/DOCKER/build.sh @@ -1,13 +1,15 @@ #!/bin/bash base=github.com/eris-ltd/eris-db repo=$GOPATH/src/$base -branch=${ERISDB_BUILD_BRANCH:=docker} +branch=${ERISDB_BUILD_BRANCH:=dockerfixes} start=`pwd` cd $repo -git checkout $branch -git pull origin +if [ "$DEV" != "true" ]; then + git checkout $branch + git pull origin +fi docker build -t eris/erisdb:0.10 -f DOCKER/Dockerfile . -cd $start \ No newline at end of file +cd $start diff --git a/DOCKER/chain_fetch.sh b/DOCKER/chain_fetch.sh new file mode 100755 index 0000000000000000000000000000000000000000..36a685aa74b0dc5f931f2c69ed2d2e12e329acac --- /dev/null +++ b/DOCKER/chain_fetch.sh @@ -0,0 +1,56 @@ +#! /bin/sh + +ifExit(){ + if [ $? -ne 0 ]; then + echo $1 + exit 1 + fi +} + +# fetching a chain means grabbing its genesis.json (from etcb) and putting it in the right folder +# we also copy in the config.toml, and update grab the seed node from etcb + +## get chain id for main reference chain (given by NODE_ADDR) +REFS_CHAIN_ID=$(mintinfo --node-addr $NODE_ADDR genesis chain_id) +ifExit "Error fetching default chain id from $NODE_ADDR" +REFS_CHAIN_ID=$(echo "$REFS_CHAIN_ID" | tr -d '"') # remove surrounding quotes + +# get the genesis.json for a refs chain from the /genesis rpc endpoint +# for a different chain, use etcb (ie namereg on the ref chain) +if [ "$CHAIN_ID" = "$REF_CHAIN_ID" ] ; then + # grab genesis.json and config + mintinfo --node-addr $NODE_ADDR genesis > "${CHAIN_DIR}/genesis.json" + ifExit "Error fetching genesis.json from $NODE_ADDR" + cp $ECM_PATH/config.toml "${CHAIN_DIR}/config.toml" + ifExit "Error copying config file from $ECM_PATH to $CHAIN_DIR" +else + # fetch genesis from etcb + GENESIS=$(mintinfo --node-addr $NODE_ADDR names "${CHAIN_ID}_genesis.json" data) + ifExit "Error fetching genesis.json for $CHAIN_ID: $GENESIS" + + echo $GENESIS > "${CHAIN_DIR}/genesis.json" + cp $ECM_PATH/config.toml "${CHAIN_DIR}/config.toml" + ifExit "Error copying config file from $ECM_PATH to $CHAIN_DIR" + + SEED_NODE=$(mintinfo --node-addr $NODE_ADDR names "${CHAIN_ID}_seed" data) + ifExit "Error grabbing seed node from $NODE_ADDR for $CHAIN_ID" + + sed -i "s/^\(seeds\s*=\s*\).*\$/\1\"$SEED_NODE\"/" "${CHAIN_DIR}/config.toml" + ifExit "Error setting seed node in config.toml" + echo "Seed node: ${SEED_NODE}" +fi + +if [ "$HOST_NAME" = "" ]; then + HOST_NAME=mint_user +fi + +echo "Host name: ${HOST_NAME}" + +sed -i "s/^\(moniker\s*=\s*\).*\$/\1\"$HOST_NAME\"/" "${CHAIN_DIR}/config.toml" +ifExit "Error setting host name in config.toml" + + +# would be nice if we could stop syncing once we're caught up ... +echo "Running mint in ${CHAIN_DIR}" +tendermint node --fast_sync +ifExit "Error running tendermint!" diff --git a/DOCKER/chain_new.sh b/DOCKER/chain_new.sh new file mode 100755 index 0000000000000000000000000000000000000000..6babaf974a07bad1b27d72b446b8abcac46dfe8f --- /dev/null +++ b/DOCKER/chain_new.sh @@ -0,0 +1,14 @@ +#! /bin/sh + +echo "new chain: $CHAIN_ID" + +if [ "$GENERATE_GENESIS" = "true" ]; then + mintgen --single $CHAIN_DIR +fi + +if [ "$RUN" = "true" ]; then + tendermint node +else + # this will just run for a second and quit + tendermint node & last_pid=$! && sleep 1 && kill -KILL $last_pid +fi diff --git a/DOCKER/chain_run.sh b/DOCKER/chain_run.sh new file mode 100755 index 0000000000000000000000000000000000000000..dc50082b92fbdce6382e26c202d8e44d4e56b7e3 --- /dev/null +++ b/DOCKER/chain_run.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +ifExit(){ + if [ $? -ne 0 ]; then + echo $1 + exit 1 + fi +} + +# if no CHAIN_ID, get that off the main test net +if [[ ! $CHAIN_ID ]]; then + # get the chain id + CHAIN_ID=$(mintinfo --node-addr $NODE_ADDR genesis chain_id) + ifExit "Error fetching default chain id from $NODE_ADDR" + CHAIN_ID=$(echo "$CHAIN_ID" | tr -d '"') # remove surrounding quotes +fi + +CHAIN_DIR="${ROOT_DIR}/$CHAIN_ID" + +if [[ ! -d $CHAIN_DIR ]]; then + echo "Unknown chain ($CHAIN_ID)" + exit 1 +fi + +echo Running chain $CHAIN_ID +tendermint node diff --git a/DOCKER/config.toml b/DOCKER/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..6959fd2993a7e8c99463f1e9be723f8a2e021968 --- /dev/null +++ b/DOCKER/config.toml @@ -0,0 +1,10 @@ +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +moniker = "eris_db" +node_laddr = "0.0.0.0:46656" +seeds = "interblock.io:46656" +fast_sync = true +db_backend = "leveldb" +log_level = "debug" +rpc_laddr = "0.0.0.0:46657" diff --git a/DOCKER/start.sh b/DOCKER/start.sh index eb3457cd61f1f041726cc8429806a8fa4117e1e3..6b52a87a131937adb337317a37fb56ed1f98c8fa 100755 --- a/DOCKER/start.sh +++ b/DOCKER/start.sh @@ -1,7 +1,68 @@ -#!/bin/bash -if [[ $FAST_SYNC ]]; then - tendermint node --fast_sync -else - tendermint node +#! /bin/sh + +ifExit(){ + if [ $? -ne 0 ]; then + echo $1 + exit 1 + fi +} + +############################################# +# We expect the following env vars to be set +# $CHAIN_ID +# +# one day we'll make it more flexible +# for now the only consumer is eris-cli + + +# TODO: deal with chain numbers +# and eg. $CONTAINER_NAME +CHAIN_DIR="/home/$USER/.eris/blockchains/$CHAIN_ID" + +TMROOT=$CHAIN_DIR + +if [ ! -d "$CHAIN_DIR" ]; then + mkdir -p $CHAIN_DIR + ifExit "Error making root dir $CHAIN_DIR" +fi + +# our root chain +if [ ! $NODE_ADDR ]; then + NODE_ADDR=http://interblock.io:46657 fi +# where the etcb client scripts are +if [ ! $ECM_PATH ]; then + ECM_PATH=. +fi + + +export TMROOT +export CHAIN_DIR +export NODE_ADDR +export ECM_PATH # set by Dockerfile + + +# either we are fetching a chain for the first time, +# creating one from scratch, or running one we already have +CMD=$1 +case $CMD in +"fetch" ) $ECM_PATH/chain_fetch.sh + ;; +"new" ) $ECM_PATH/chain_new.sh + ;; +"run" ) $ECM_PATH/chain_run.sh + ;; +*) echo "Enter a command for starting the chain (fetch, new, run)" + ;; +esac + +#-------------------------------------------------------------------------------- + +# XXX: assume for now the chain_id is always given +# +## if no CHAIN_ID given, use the ref chain +#if [ ! $CHAIN_ID ]; then +# CHAIN_ID=$REFS_CHAIN_ID +#fi +