Skip to content
Snippets Groups Projects
Commit 0dce3edc authored by Silas Davis's avatar Silas Davis Committed by GitHub
Browse files

Merge pull request #160 from benjaminbollen/deployment_docker_and_ECM

Deployment docker and ecm
parents eb1d4bfe 7a2a9c54
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>erisdb</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.googlecode.goclipse.goBuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.googlecode.goclipse.core.goNature</nature>
</natures>
</projectDescription>
# Pull base image.
FROM quay.io/eris/build
MAINTAINER Eris Industries <support@erisindustries.com>
#-----------------------------------------------------------------------------
# install eris-db
#
ENV GO15VENDOREXPERIMENT 1
# install glide for dependency management
RUN go install github.com/Masterminds/glide
# set the repo and install erisdb
ENV REPO $GOPATH/src/github.com/eris-ltd/eris-db
WORKDIR $REPO
COPY . $REPO
RUN glide install
RUN cd ./cmd/eris-db && go build -o /usr/local/bin/eris-db && cd ../..
#-----------------------------------------------------------------------------
# install mint-client tools
# set the repo and install mint-client
ENV REPO github.com/eris-ltd/mint-client
ENV BRANCH master
RUN mkdir -p $GOPATH/src/$REPO
WORKDIR $GOPATH/src/$REPO
RUN git clone --quiet https://$REPO . && \
git checkout --quiet $BRANCH && \
go install ./... && \
mv $GOPATH/bin/mint* /usr/local/bin && \
mv ./mint-client /usr/local/bin/
#-----------------------------------------------------------------------------
# cleanup
RUN rm -f $GOPATH/bin/glide
RUN rm -rf $GOPATH/src/* && \
unset REPO && \
unset COMMIT && \
unset BRANCH
#-----------------------------------------------------------------------------
# start script
# install the wrapper/start script
COPY DOCKER/start.sh /usr/local/bin/erisdb-wrapper
#-----------------------------------------------------------------------------
# chain manager scripts and default mint config
ENV ECM_PATH /usr/local/lib/ecm
RUN mkdir -p $ECM_PATH
COPY DOCKER/chain_* $ECM_PATH/
COPY DOCKER/config.toml $ECM_PATH/
COPY DOCKER/version.sh $ECM_PATH/
#-----------------------------------------------------------------------------
# permission the directories
RUN chown -R eris /usr/local/bin
RUN chown -R eris $ECM_PATH
#-----------------------------------------------------------------------------
# root dir
# persist data, set user
WORKDIR /home/$USER/.eris
VOLUME /home/$USER/.eris
USER $USER
RUN mkdir -p /home/$USER/.eris/chains/tendermint
ENV CHAINROOT /home/$USER/.eris/chains/tendermint
# run eris-db
# ports: 1337:eris-db API; 46656:tendermint-peer; 46657:tendermint-rpc
EXPOSE 1337
EXPOSE 46656
EXPOSE 46657
ENTRYPOINT ["eris-db", "serve"]
CMD["--work-dir $CHAINROOT"]
# Pull base image.
FROM quay.io/eris/build:arm
MAINTAINER Eris Industries <support@erisindustries.com>
#-----------------------------------------------------------------------------
# install tendermint
# set the repo and install tendermint -- should track vendored commit
ENV REPO_ALIAS github.com/tendermint/tendermint
ENV REPO github.com/eris-ltd/tendermint
#ENV COMMIT 4ee387d0770ed379e2d524f7077938517b38cd7c
ENV COMMIT working
# note, we want to lock in the same commit number
# as eris-db has vendored.
RUN mkdir -p $GOPATH/src/$REPO
WORKDIR $GOPATH/src/$REPO_ALIAS
RUN git clone --quiet https://$REPO . && \
git checkout --quiet $COMMIT && \
go build -o /usr/local/bin/tendermint ./cmd/tendermint
#-----------------------------------------------------------------------------
# install mint-client tools
# set the repo and install mint-client
ENV REPO github.com/eris-ltd/mint-client
ENV BRANCH master
RUN mkdir -p $GOPATH/src/$REPO
WORKDIR $GOPATH/src/$REPO
RUN git clone --quiet https://$REPO . && \
git checkout --quiet $BRANCH && \
go install ./... && \
mv $GOPATH/bin/mint* /usr/local/bin && \
mv ./mint-client /usr/local/bin/
#-----------------------------------------------------------------------------
# install erisdb
# set the repo and install erisdb
ENV REPO $GOPATH/src/github.com/eris-ltd/eris-db
COPY . $REPO
WORKDIR $REPO
RUN cd ./cmd/erisdb && go build -o /usr/local/bin/erisdb && cd ../..
#-----------------------------------------------------------------------------
# cleanup
RUN rm -rf $GOPATH/src/* && \
unset REPO && \
unset REPO_ALIAS && \
unset COMMIT && \
unset BRANCH
#-----------------------------------------------------------------------------
# start script
# install the wrapper/start script
COPY DOCKER/start.sh /usr/local/bin/erisdb-wrapper
#-----------------------------------------------------------------------------
# chain manager scripts and default mint config
ENV ECM_PATH /usr/local/lib/ecm
RUN mkdir -p $ECM_PATH
COPY DOCKER/chain_* $ECM_PATH/
COPY DOCKER/config.toml $ECM_PATH/
COPY DOCKER/version.sh $ECM_PATH/
#-----------------------------------------------------------------------------
# permission the directories
RUN chown -R eris /usr/local/bin
RUN chown -R eris $ECM_PATH
#-----------------------------------------------------------------------------
# root dir
# persist data, set user
VOLUME /home/$USER/.eris
WORKDIR /home/$USER/.eris
USER $USER
RUN mkdir -p /home/$USER/.eris/chains/tendermint
ENV TMROOT /home/$USER/.eris/chains/tendermint
# run tendermint
# ports: 1337:eris-db API; 46656:mint-peer; 46657:mint-rpc
EXPOSE 1337
EXPOSE 46656
EXPOSE 46657
CMD "erisdb-wrapper"
#! /bin/bash
echo "Running chain $CHAIN_ID (via ErisDB API)"
erisdb $CHAIN_DIR
#! /bin/bash
#-----------------------------------------------------------------------
# get genesis, seed, copy config
export MINTX_NODE_ADDR=$NODE_ADDR
# get genesis if not already
if [ ! -e "${CHAIN_DIR}/genesis.json" ]; then
# etcb chain (given by $NODE_ADDR)
REFS_CHAIN_ID=$(mintinfo genesis chain_id)
ifExit "Error fetching default chain id from $NODE_ADDR"
REFS_CHAIN_ID=$(echo "$REFS_CHAIN_ID" | tr -d '"') # remove surrounding quotes
echo "etcb chain: $REFS_CHAIN_ID"
# 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" = "$REFS_CHAIN_ID" ] ; then
# grab genesis.json
mintinfo genesis > "${CHAIN_DIR}/genesis.json"
ifExit "Error fetching genesis.json from $NODE_ADDR"
else
# fetch genesis from etcb
GENESIS=$(mintinfo names "${CHAIN_ID}/genesis" data)
ifExit "Error fetching genesis.json for $CHAIN_ID: $GENESIS"
echo $GENESIS > "${CHAIN_DIR}/genesis.json"
SEED_NODE=$(mintinfo names "${CHAIN_ID}/seeds" data)
ifExit "Error grabbing seed node from $NODE_ADDR for $CHAIN_ID"
fi
fi
# copy in config if not already
if [ ! -e "${CHAIN_DIR}/config.toml" ]; then
echo "laying default config..."
mintconfig > $CHAIN_DIR/config.toml
ifExit "Error creating config"
if [ "$SEED_NODE" = "" ]; then
SEED_NODE=$P2P_ADDR
fi
if [ "$HOST_NAME" = "" ]; then
HOST_NAME=mint_user
fi
fi
# set seed node and host name
if [ "$SEED_NODE" != "" ]; then
echo "Seed node: $SEED_NODE"
# NOTE the NODE_ADDR must not have any slashes (no http://)
sed -i "s/^\(seeds\s*=\s*\).*\$/\1\"$SEED_NODE\"/" "${CHAIN_DIR}/config.toml"
ifExit "Error setting seed node in config.toml"
fi
if [ "$HOST_NAME" != "" ]; then
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"
fi
#-----------------------------------------------------------------------
# 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!"
#! /bin/bash
echo "your new chain, kind marmot: $CHAIN_ID"
# lay the genesis
# if it exists, just overwrite the chain id
if [ ! -f $CHAIN_DIR/genesis.json ]; then
if [ "$CSV" = "" ]; then
mintgen random --dir="$CHAIN_DIR" 1 $CHAIN_ID
ifExit "Error creating random genesis file"
else
mintgen known --csv="$CSV" $CHAIN_ID > $CHAIN_DIR/genesis.json
ifExit "Error creating genesis file from csv"
fi
else
# apparently just outputing to $CHAIN_DIR/genesis.json doesn't work so we copy
cat $CHAIN_DIR/genesis.json | jq .chain_id=\"$CHAIN_ID\" > genesis.json
cp genesis.json $CHAIN_DIR/genesis.json
fi
# if no config was given, lay one with the given options
if [ ! -f $CHAIN_DIR/config.toml ]; then
echo "running mintconfig $CONFIG_OPTS"
mintconfig $CONFIG_OPTS > $CHAIN_DIR/config.toml
else
echo "found config file:"
cat $CHAIN_DIR/config.toml
fi
# run the node.
# TODO: maybe bring back this stopping option if we think its useful
# tendermint node & last_pid=$! && sleep 1 && kill -KILL $last_pid
if [ $ERISDB_API ]; then
echo "Running chain $CHAIN_ID (via ErisDB API)"
erisdb $CHAIN_DIR
ifExit "Error starting erisdb"
else
echo Running chain $CHAIN_ID
tendermint node
ifExit "Error starting tendermint"
fi
#! /bin/bash
echo "registering $CHAIN_ID in the grand registry of marmot mayhem and marmalade"
# lay the genesis
# if it exists, just overwrite the chain id
if [ ! -f "$CHAIN_DIR/genesis.json" ]; then
"Could not find genesis file in $CHAIN_DIR. Did you run `eris chains new $CHAIN_ID`?"
exit 1
fi
echo "or less dramatically, registering $CHAIN_ID with the $ETCB_CHAIN_ID chain at $MINTX_NODE_ADDR from address $PUBKEY"
echo "NAME ${CHAIN_ID}_genesis"
cat $CHAIN_DIR/genesis.json
# register the genesis
RES=`mintx name --pubkey=$PUBKEY --name="${CHAIN_ID}/genesis" --data-file=$CHAIN_DIR/genesis.json --amt=10000 --fee=0 --sign --broadcast --chainID=$ETCB_CHAIN_ID --wait`
ifExit "$RES" "Error registering genesis with etcb_testnet"
echo $RES | grep "Incorrect"
if0Exit "$RES" "Error registering genesis with etcb_testnet"
echo $RES
echo "successfully registered genesis on etcb chain"
# register the seed/s
RES=`mintx name --pubkey=$PUBKEY --name="${CHAIN_ID}/seeds" --data="$NEW_P2P_SEEDS" --amt=10000 --fee=0 --sign --broadcast --chainID=$ETCB_CHAIN_ID --wait`
ifExit "$RES" "Error registering seeds with etcb_testnet"
echo $RES | grep "Incorrect"
if0Exit "$RES" "Error registering seeds with etcb_testnet"
echo $RES
echo "successfully registered seed on etcb chain"
#! /bin/bash
if [ $ERISDB_API ]; then
echo "Running chain $CHAIN_ID (via ErisDB API)"
erisdb $CHAIN_DIR
ifExit "Error starting erisdb"
else
echo Running chain $CHAIN_ID
tendermint node
ifExit "Error starting tendermint"
fi
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
moniker = "eris_chains"
node_laddr = "0.0.0.0:46656"
seeds = ""
fast_sync = false
db_backend = "leveldb"
log_level = "debug"
rpc_laddr = "0.0.0.0:46657"
#! /bin/bash
ifExit(){
if [[ $? != 0 ]]; then
echo "ifExit"
echo "$1"
for var in "$@"
do
echo "$var"
done
exit 1
fi
}
if0Exit(){
if [[ $? == 0 ]]; then
echo "if0Exit"
echo "$1"
for var in "$@"
do
echo "$var"
done
exit 1
fi
}
export -f ifExit
export -f if0Exit
#------------------------------------------------
# set and export directories
if [ "$CHAIN_ID" = "" ]; then
echo "ecm requires CHAIN_ID be set"
exit 1
fi
# TODO: deal with chain numbers
# and eg. $CONTAINER_NAME
CHAIN_DIR="/home/$USER/.eris/chains/$CHAIN_ID"
# set the tendermint directory
TMROOT="$CHAIN_DIR"/tendermint
if [ ! -d "$CHAIN_DIR" ]; then
mkdir -p $CHAIN_DIR
ifExit "Error making root dir $CHAIN_DIR"
fi
# our root chain
if [ ! $ROOT_CHAIN_ID ]; then
ROOT_CHAIN_ID=etcb_testnet
fi
if [ ! $NODE_ADDR ]; then
NODE_ADDR=interblock.io:46657
fi
if [ ! $P2P_ADDR ]; then
P2P_ADDR=interblock.io:46656
fi
# where the etcb client scripts are
if [ ! $ECM_PATH ]; then
ECM_PATH=.
fi
#------------------------------------------------
# dump key files if they are in env vars
if [ -z "$KEY" ]
then
echo "No Key Given"
else
echo "Key Given. Writing priv_validator.json"
echo "$KEY" >> $CHAIN_DIR/priv_validator.json
fi
if [ -z "$GENESIS" ]
then
echo "No Genesis Given"
else
echo "Genesis Given. Writing genesis.json"
echo "$GENESIS" > $CHAIN_DIR/genesis.json
fi
if [ -z "$GENESIS_CSV" ]
then
echo "No Genesis_CSV Given"
else
echo "Genesis_CSV Given. Writing genesis.csv"
echo "$GENESIS_CSV" > $CHAIN_DIR/genesis.csv
fi
if [ -z "$CHAIN_CONFIG" ]
then
echo "No Chain Config Given"
else
echo "Chain Config Given. Writing config.toml"
echo "$CHAIN_CONFIG" > $CHAIN_DIR/config.toml
fi
if [ -z "$SERVER_CONFIG" ]
then
echo "No Server Config Given"
else
echo "Server Config Given. Writing server_conf.toml"
echo "$SERVER_CONFIG" > $CHAIN_DIR/server_conf.toml
fi
#------------------------------------------------
# export important vars
export TMROOT
export CHAIN_DIR
export NODE_ADDR
export P2P_ADDR
export ECM_PATH # set by Dockerfile
export MINTX_NODE_ADDR=$NODE_ADDR
export MINTX_SIGN_ADDR=keys:4767
# print the version
bash $ECM_PATH/version.sh
#-----------------------------------------------------------------------
# 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
"install" ) $ECM_PATH/chain_install.sh
;;
"new" ) $ECM_PATH/chain_new.sh
;;
"run" ) $ECM_PATH/chain_run.sh
;;
"register" ) $ECM_PATH/chain_register.sh
;;
*) echo "Enter a command for starting the chain (new, install, run, register)"
;;
esac
# json break
echo "ecm version 0.12.0"
# Pull base image.
FROM quay.io/eris/build
MAINTAINER Eris Industries <support@erisindustries.com>
# Expose ports for 1337:eris-db API; 46656:tendermint-peer; 46657:tendermint-rpc
EXPOSE 1337
EXPOSE 46656
EXPOSE 46657
#-----------------------------------------------------------------------------
# install eris-db
# set the source code path and copy the repository in
ENV ERIS_DB_SRC_PATH $GOPATH/src/github.com/eris-ltd/eris-db
COPY . $ERIS_DB_SRC_PATH
# fetch and install eris-db and its dependencies
# install glide for dependency management
RUN go get github.com/Masterminds/glide \
# build the main eris-db target
&& cd $ERIS_DB_SRC_PATH/cmd/eris-db \
&& go build \
&& cp eris-db $INSTALL_BASE/eris-db \
# copy the start script for eris-db \
&& cp $ERIS_DB_SRC_PATH/bin/start_eris_db $INSTALL_BASE/erisdb-wrapper \
&& chmod 755 $INSTALL_BASE/erisdb-wrapper
#-----------------------------------------------------------------------------
# install mint-client [to be deprecated]
ENV ERIS_DB_MINT_REPO github.com/eris-ltd/mint-client
ENV ERIS_DB_MINT_SRC_PATH $GOPATH/src/$ERIS_DB_MINT_REPO
WORKDIR $ERIS_DB_MINT_SRC_PATH
RUN git clone --quiet https://$ERIS_DB_MINT_REPO . \
&& git checkout --quiet master \
&& go build -o $INSTALL_BASE/mintx ./mintx \
&& go build -o $INSTALL_BASE/mintconfig ./mintconfig \
&& go build -o $INSTALL_BASE/mintkey ./mintkey
# restrict build targets for re-evaluation
# && go build -o $INSTALL_BASE/mintdump ./mintdump \
# && go build -o $INSTALL_BASE/mintperms ./mintperms \
# && go build -o $INSTALL_BASE/mintunsafe ./mintunsafe \
# && go build -o $INSTALL_BASE/mintgen ./mintgen \
# && go build -o $INSTALL_BASE/mintsync ./mintsync
#-----------------------------------------------------------------------------
# clean up [build container needs to be separated from shipped container]
RUN unset ERIS_DB_SRC_PATH \
&& unset ERIS_DB_MINT_SRC_PATH \
&& apk del --purge go git musl-dev \
&& rm -rf $GOPATH
# mount the data container on the eris directory
VOLUME $ERIS
WORKDIR $ERIS
CMD "erisdb-wrapper"
\ No newline at end of file
# Pull base image.
FROM quay.io/eris/build:arm
MAINTAINER Eris Industries <support@erisindustries.com>
# Expose ports for 1337:eris-db API; 46656:tendermint-peer; 46657:tendermint-rpc
EXPOSE 1337
EXPOSE 46656
EXPOSE 46657
#-----------------------------------------------------------------------------
# install eris-db
# set the source code path and copy the repository in
ENV ERIS_DB_SRC_PATH $GOPATH/src/github.com/eris-ltd/eris-db
COPY . $ERIS_DB_SRC_PATH
# fetch and install eris-db and its dependencies
# install glide for dependency management
RUN go get github.com/Masterminds/glide \
# build the main eris-db target
&& cd $ERIS_DB_SRC_PATH/cmd/eris-db \
&& go build \
&& cp eris-db $INSTALL_BASE/eris-db \
# copy the start script for eris-db \
&& cp $ERIS_DB_SRC_PATH/bin/start_eris_db $INSTALL_BASE/erisdb-wrapper \
&& chmod 755 $INSTALL_BASE/erisdb-wrapper
#-----------------------------------------------------------------------------
# install mint-client [to be deprecated]
ENV ERIS_DB_MINT_REPO github.com/eris-ltd/mint-client
ENV ERIS_DB_MINT_SRC_PATH $GOPATH/src/$ERIS_DB_MINT_REPO
WORKDIR $ERIS_DB_MINT_SRC_PATH
RUN git clone --quiet https://$ERIS_DB_MINT_REPO . \
&& git checkout --quiet master \
&& go build -o $INSTALL_BASE/mintx ./mintx \
&& go build -o $INSTALL_BASE/mintconfig ./mintconfig \
&& go build -o $INSTALL_BASE/mintkey ./mintkey
# restrict build targets for re-evaluation
# && go build -o $INSTALL_BASE/mintdump ./mintdump \
# && go build -o $INSTALL_BASE/mintperms ./mintperms \
# && go build -o $INSTALL_BASE/mintunsafe ./mintunsafe \
# && go build -o $INSTALL_BASE/mintgen ./mintgen \
# && go build -o $INSTALL_BASE/mintsync ./mintsync
#-----------------------------------------------------------------------------
# clean up [build container needs to be separated from shipped container]
RUN unset ERIS_DB_SRC_PATH \
&& unset ERIS_DB_MINT_SRC_PATH \
&& apk del --purge go git musl-dev \
&& rm -rf $GOPATH
# mount the data container on the eris directory
VOLUME $ERIS
WORKDIR $ERIS
ENTRYPOINT ["erisdb-wrapper"]
\ No newline at end of file
#! /bin/bash
ifExit(){
if [[ $? != 0 ]]; then
echo "ifExit"
echo "$1"
for var in "$@"
do
echo "$var"
done
exit 1
fi
}
if0Exit(){
if [[ $? == 0 ]]; then
echo "if0Exit"
echo "$1"
for var in "$@"
do
echo "$var"
done
exit 1
fi
}
export -f ifExit
export -f if0Exit
#-----------------------------------------------------------------------
# set and export directories
if [ "$CHAIN_ID" = "" ]; then
echo "Eris-db container requires environment variable CHAIN_ID to be set. Please run docker container with \`-e CHAIN_ID=\"<chainId>\"\`"
exit 1
fi
if [ "$ERIS_DB_WORKDIR" = "" ]; then
ERIS_DB_WORKDIR="$ERIS/chains/$CHAIN_ID"
fi
if [ ! -d "$ERIS_DB_WORKDIR" ]; then
mkdir -p $ERIS_DB_WORKDIR
ifExit "Error making working directory $ERIS_DB_WORKDIR"
fi
export ERIS_DB_WORKDIR
export ERIS_DB_DATADIR=$ERIS_DB_WORKDIR/data
echo "env CHAIN_ID is set to $CHAIN_ID"
echo "env ERIS_DB_WORKDIR is set to $ERIS_DB_WORKDIR"
echo "env ERIS_DB_DATADIR is set to $ERIS_DB_DATADIR"
#-----------------------------------------------------------------------
# [2016-07-13 ben] we preserve the existing contact commands "new", "run",
# but this functionality is absorbed in eris-db, eris-cm, eris-cli
# and the mapping is preserved here to catch deployed use-cases.
# NOTE: eris-db serve picks up following environment variables which are relevant to interaction with eris-cli
# - CHAIN_ID, set by eris-cli
# - ERIS_DB_WORKDIR, set in this script
# - ERIS_DB_DATADIR, set in this script
# - ERISDB_API (to be deprecated in favor of explicit --disable-rpc)
# - CONFIG_OPTS, for arbitrary flags to be passed to `eris-db serve`
CMD=$1
case $CMD in
"install" )
echo "Install is under review to be deprecated; please contact support@erisindustries.com if you encounter this error."
exit 1
;;
"new" ) echo "passed new"
;;
"run" ) echo "passed run"
;;
"register" )
echo "Register is under review to be deprecated; please contact support@erisindustries.com if you encounter this error."
exit 1
;;
# we append $@ to eris-db to expose the same flags on the docker container,
# eg `docker run -it quay.io/eris/erisdb --chain-id=<chain_id>`, will overwrite $CHAIN_ID
*) echo "no known command given: $CMD"
;;
esac
echo "running eris-db serve --debug $CONFIG_OPTS $@"
eris-db serve --debug $CONFIG_OPTS $@
\ No newline at end of file
......@@ -47,11 +47,11 @@ deployment:
master:
branch: master
commands:
- DOCKER/build.sh
- tests/build_tool.sh
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
- docker push quay.io/eris/erisdb
develop:
branch: develop
commands:
- DOCKER/build.sh
- tests/build_tool.sh
- docker push quay.io/eris/erisdb
......@@ -92,7 +92,7 @@ func defaultDebug() bool {
return setDefaultBool("ERIS_DB_DEBUG", false)
}
// setDefaultBool returns the provided default value if the environment variab;e
// setDefaultBool returns the provided default value if the environment variable
// is not set or not parsable as a bool.
func setDefaultBool(environmentVariable string, defaultValue bool) bool {
value := os.Getenv(environmentVariable)
......
......@@ -18,7 +18,9 @@ package commands
import (
"os"
"os/signal"
"path"
"syscall"
cobra "github.com/spf13/cobra"
......@@ -35,7 +37,8 @@ var ServeCmd = &cobra.Command{
The Eris-DB node is modularly configured for the consensus engine and application
manager. The client API can be disabled.`,
Example: `$ eris-db serve -- will start the Eris-DB node based on the configuration file "server_config.toml" in the current working directory
$ eris-db serve --work-dir <path-to-working-directory> -- will start the Eris-DB node based on the configuration file "server_config.toml" in the provided working directory`,
$ eris-db serve --work-dir <path-to-working-directory> -- will start the Eris-DB node based on the configuration file "server_config.toml" in the provided working directory
$ eris-db serve --chain-id <CHAIN_ID> -- will overrule the configuration entry assert_chain_id`,
PreRun: func(cmd *cobra.Command, args []string) {
// if WorkDir was not set by a flag or by $ERIS_DB_WORKDIR
// NOTE [ben]: we can consider an `Explicit` flag that eliminates
......@@ -45,7 +48,6 @@ $ eris-db serve --work-dir <path-to-working-directory> -- will start the Eris-DB
log.Fatalf("No directory provided and failed to get current working directory: %v", err)
os.Exit(1)
} else {
do.WorkDir = currentDirectory
}
}
......@@ -62,10 +64,14 @@ func buildServeCommand() {
}
func addServeFlags() {
ServeCmd.PersistentFlags().StringVarP(&do.ChainId, "chain-id", "c",
defaultChainId(), "specify the chain id to use for assertion against the genesis file or the existing state. If omitted, and no id is set in $CHAIN_ID, then assert_chain_id is used from the configuration file.")
ServeCmd.PersistentFlags().StringVarP(&do.WorkDir, "work-dir", "w",
defaultWorkDir(), "specify the working directory for the chain to run. If omitted, and no path set in $ERIS_DB_WORKDIR, the current working directory is taken.")
ServeCmd.PersistentFlags().StringVarP(&do.DataDir, "data-dir", "a",
ServeCmd.PersistentFlags().StringVarP(&do.DataDir, "data-dir", "",
defaultDataDir(), "specify the data directory. If omitted and not set in $ERIS_DB_DATADIR, <working_directory>/data is taken.")
ServeCmd.PersistentFlags().BoolVarP(&do.DisableRpc, "disable-rpc", "",
defaultDisableRpc(), "indicate for the RPC to be disabled. If omitted the RPC is enabled by default, unless (deprecated) $ERISDB_API is set to false.")
}
//------------------------------------------------------------------------------
......@@ -77,17 +83,19 @@ func addServeFlags() {
func Serve(cmd *cobra.Command, args []string) {
// load configuration from a single location to avoid a wrong configuration
// file is loaded.
if err := do.ReadConfig(do.WorkDir, "server_config", "toml"); err != nil {
if err := do.ReadConfig(do.WorkDir, "config", "toml"); err != nil {
log.WithFields(log.Fields{
"directory": do.WorkDir,
"file": "server_config.toml",
"file": "config.toml",
}).Fatalf("Fatal error reading configuration")
os.Exit(1)
}
// load chain_id for assertion
if do.ChainId = do.Config.GetString("chain.assert_chain_id"); do.ChainId == "" {
log.Fatalf("Failed to read non-empty string for ChainId from config.")
os.Exit(1)
// if do.ChainId is not yet set, load chain_id for assertion from configuration file
if do.ChainId == "" {
if do.ChainId = do.Config.GetString("chain.assert_chain_id"); do.ChainId == "" {
log.Fatalf("Failed to read non-empty string for ChainId from config.")
os.Exit(1)
}
}
// load the genesis file path
do.GenesisFile = path.Join(do.WorkDir,
......@@ -129,33 +137,53 @@ func Serve(cmd *cobra.Command, args []string) {
log.Fatalf("Failed to load core: %s", err)
}
serverConfig, err := core.LoadServerConfig(do)
if err != nil {
log.Fatalf("Failed to load server configuration: %s.", err)
os.Exit(1)
}
serverProcess, err := newCore.NewGatewayV0(serverConfig)
if err != nil {
log.Fatalf("Failed to load servers: %s.", err)
os.Exit(1)
}
err = serverProcess.Start()
if err != nil {
log.Fatalf("Failed to start servers: %s.", err)
os.Exit(1)
}
_, err = newCore.NewGatewayTendermint(serverConfig)
if err != nil {
log.Fatalf("Failed to start Tendermint gateway")
if !do.DisableRpc {
serverConfig, err := core.LoadServerConfig(do)
if err != nil {
log.Fatalf("Failed to load server configuration: %s.", err)
os.Exit(1)
}
serverProcess, err := newCore.NewGatewayV0(serverConfig)
if err != nil {
log.Fatalf("Failed to load servers: %s.", err)
os.Exit(1)
}
err = serverProcess.Start()
if err != nil {
log.Fatalf("Failed to start servers: %s.", err)
os.Exit(1)
}
_, err = newCore.NewGatewayTendermint(serverConfig)
if err != nil {
log.Fatalf("Failed to start Tendermint gateway")
}
<-serverProcess.StopEventChannel()
} else {
signals := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
go func() {
signal := <-signals
// TODO: [ben] clean up core; in a manner consistent with enabled rpc
log.Fatalf("Received %s signal. Marmots out.", signal)
done <- true
}()
<-done
}
<-serverProcess.StopEventChannel()
}
//------------------------------------------------------------------------------
// Defaults
func defaultChainId() string {
// if CHAIN_ID environment variable is not set, keep do.ChainId empty to read
// assert_chain_id from configuration file
return setDefaultString("CHAIN_ID", "")
}
func defaultWorkDir() string {
// if ERIS_DB_WORKDIR environment variable is not set, keep do.WorkDir empty
// as do.WorkDir is set by the PreRun
return setDefaultString("ERIS_DB_WORKDIR", "")
}
......@@ -164,3 +192,11 @@ func defaultDataDir() string {
// wait setting a default value, and initialise the data directory from serve()
return setDefaultString("ERIS_DB_DATADIR", "")
}
func defaultDisableRpc() bool {
// we currently observe environment variable ERISDB_API (true = enable)
// and default to enabling the RPC if it is not set.
// TODO: [ben] deprecate ERISDB_API across the stack for 0.12.1, and only disable
// the rpc through a command line flag --disable-rpc
return !setDefaultBool("ERISDB_API", true)
}
......@@ -47,6 +47,7 @@ type Do struct {
// AccountTypes []string
// Zip bool
// Tarball bool
DisableRpc bool
Config *viper.Viper
// Accounts []*Account
// Result string
......@@ -60,6 +61,7 @@ func NowDo() *Do {
do.DataDir = ""
do.ChainId = ""
do.GenesisFile = ""
do.DisableRpc = false
do.Config = viper.New()
return do
}
......
......@@ -159,8 +159,12 @@ func startState(dataDir, backend, genesisFile, chainId string) (*state.State,
}
// assert loaded genesis doc has the same chainId as the provided chainId
if genesisDoc.ChainID != chainId {
return nil, nil, fmt.Errorf("ChainId (%s) loaded from genesis document in existing database does not match configuration chainId (%s).",
genesisDoc.ChainID, chainId)
log.WithFields(log.Fields{
"chainId from loaded genesis": genesisDoc.ChainID,
"chainId from configuration": chainId,
}).Warn("Conflicting chainIds")
// return nil, nil, fmt.Errorf("ChainId (%s) loaded from genesis document in existing database does not match configuration chainId (%s).",
// genesisDoc.ChainID, chainId)
}
}
......
#!/bin/sh
#!/usr/bin/env bash
# ----------------------------------------------------------
# PURPOSE
# This is the build script for eris-db. It will build the
# tool into docker containers in a reliable and predicatable
# manner.
# ----------------------------------------------------------
# REQUIREMENTS
# docker installed locally
# ----------------------------------------------------------
# USAGE
# build_tool.sh
# ----------------------------------------------------------
# Set defaults
set -e
start=`pwd`
if [ "$CIRCLE_BRANCH" ]
then
repo=`pwd`
......@@ -8,21 +28,23 @@ else
repo=$GOPATH/src/$base
fi
branch=${CIRCLE_BRANCH:=master}
branch=${branch/-/_}
release_min=$(cat $repo/version/version.go | tail -n 1 | cut -d \ -f 4 | tr -d '"')
release_maj=$(echo $release_min | cut -d . -f 1-2)
start=`pwd`
image_base=quay.io/eris/erisdb
cd $repo
if [ "$branch" = "master" ]; then
docker build -t $image_base:latest -f DOCKER/Dockerfile .
docker tag $image_base:latest $image_base:$release_maj
docker tag $image_base:latest $image_base:$release_min
if [[ "$branch" = "master" ]]
then
docker build -t $image_base:latest $repo
docker tag -f $image_base:latest $image_base:$release_maj
docker tag -f $image_base:latest $image_base:$release_min
else
docker build -t $image_base:$release_min -f DOCKER/Dockerfile .
docker build -t $image_base:$release_min $repo
fi
cd $start
\ No newline at end of file
test_exit=$?
cd $start
exit $test_exit
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment