From b49aa55f8f97cf92ae135295301dc90cfe131f21 Mon Sep 17 00:00:00 2001 From: apolloww <32606824+apolloww@users.noreply.github.com> Date: Fri, 21 Jun 2019 12:36:18 +0800 Subject: [PATCH] vapord docker: add missing options to deploy script (#216) --- docker/vapord/README.md | 40 ++++++++++++---------- docker/vapord/deploy.sh | 73 ++++++++++++++++++++--------------------- docker/vapord/vapord.Dockerfile | 6 ++-- 3 files changed, 61 insertions(+), 58 deletions(-) diff --git a/docker/vapord/README.md b/docker/vapord/README.md index fbe66664..7b4d0c35 100644 --- a/docker/vapord/README.md +++ b/docker/vapord/README.md @@ -1,59 +1,61 @@ # quick start -execute deploy.sh at the root of vapor repo +execute ./docker/vapord/deploy.sh from the root of vapor repo. -## usage +every vapord image has a unique public key, always create only one instance per image, otherwise you would end up with multiple nodes with same public key. + +## print usage ```bash -bash deploy.sh --help +bash ./docker/vapord/deploy.sh --help ``` -## build and run a 2-node vapor nodes +## build and run 2 vapor nodes ```bash -bash deploy.sh --scale=2 +bash ./docker/vapord/deploy.sh --scale=2 ``` ## list available node images and public keys ```bash -bash deploy.sh --list +bash ./docker/vapord/deploy.sh --list ``` ## remove all node images ```bash -bash deploy.sh --rm-all +bash ./docker/vapord/deploy.sh --rm-all ``` -## remove 2 images +## remove 2 node images ```bash -bash deploy.sh --rm=vapord_test-ade32,vapord_test-342de +bash ./docker/vapord/deploy.sh --rm=vapord_test-ade32,vapord_test-342de ``` -## build 2 vapord images (build only) +## build 2 node images (build only) ```bash -bash deploy.sh --build=2 +bash ./docker/vapord/deploy.sh --build=2 ``` -## run 2 vapor nodes from existing images +## run 2 vapor nodes instances from existing images ```bash -bash deploy.sh --run=vapord_test-ade32,vapord_test-342de +bash ./docker/vapord/deploy.sh --run=vapord_test-ade32,vapord_test-342de ``` -## run vapor node from all existing images +## run vapor node instances from all existing images ```bash -bash deploy.sh --run-all +bash ./docker/vapord/deploy.sh --run-all ``` -## bring down running nodes +## bring down running node instances ```bash -bash deploy.sh --down +bash ./docker/vapord/deploy.sh --down ``` ## node naming @@ -64,3 +66,7 @@ bash deploy.sh --down * wallet port : start from 9889, and increases by 1 every time a new node image is created. * log location: ~/vapord/log/${node_name} * docker-compose.yml location: ~/vapord/docker-compose.yml + +## customize + +* config.toml and federation.json are provided for reference only. They should be modified for your own test env. diff --git a/docker/vapord/deploy.sh b/docker/vapord/deploy.sh index 1bdf21b5..3708cca2 100644 --- a/docker/vapord/deploy.sh +++ b/docker/vapord/deploy.sh @@ -6,7 +6,7 @@ usage() { cat << EOF bash deploy.sh operation [options] operation - --build=num : build node images + --build=num : build node images only --run=image1,image2,...: run selected node images @@ -49,59 +49,56 @@ WALLET_PORT_BEGIN=9889 scale=1 # operation: build, run, run-all, all, list, remove, remove-all help op="all" -op_arg="vapord_test-2951a1" -# Call getopt to validate the provided input. -options=$(getopt -o brg --long build:run:run-all:list:rm:rm-all:scale:help:down -- "$@") -[ $? -eq 0 ] || { - echo "Incorrect options provided" - exit 1 -} - -eval set -- "$options" -while true; do - case "$1" in - --build) - shift; +for i in "$@" +do +case $i in + --scale=*) + op="all" + scale="${i#*=}" + shift # past argument=value + ;; + --build=*) op="build" - scale=$1 + scale="${i#*=}" + shift # past argument=value ;; - --run) - shift; + --run=*) op="run" - op_arg=$1 + op_arg="${i#*=}" + shift # past argument=value ;; --run-all) op="run-all" + shift ;; - --list) - op="list" - ;; - --rm) - shift; + --rm=*) op="remove" - op_arg=$1 + op_arg="${i#*=}" + shift # past argument=value ;; --rm-all) op="remove-all" + shift ;; - --scale) - shift; # The arg is next in position args - op="all" - scale=$1 - ;; - --help) - op="help" + --list) + op="list" + shift ;; --down) op="down" - ;; - --) shift - break ;; - esac - shift + --help) + op="help" + shift # past argument with no value + ;; + *) + echo "unknown option $i" + usage + exit 1 + ;; +esac done echo "options: scale:${scale}, op:${op} op_arg:${op_arg}" @@ -157,7 +154,7 @@ if [ "${op}" == "list" ]; then echo -e "${GREEN}list all node images${NC}" docker images --filter=reference="${IMG_PREFIX}-*:*" echo - echo "public keys" + printf "${CYAN}image name\t\tpublic key${NC}\n" img_array=(`docker images --filter=reference="${IMG_PREFIX}-*:*" --format "{{.Repository}}"`) for img in "${img_array[@]}"; do pubkey=$( get_pubkey ${img} ) @@ -235,7 +232,7 @@ elif [ "${op}" == "run-all" ]; then done fi -echo -e "image/node/pkey" +printf "${CYAN}image name\t\tnode name\tpublic key${NC}\n" for id in "${!img_array[@]}"; do node=${node_array[id]} diff --git a/docker/vapord/vapord.Dockerfile b/docker/vapord/vapord.Dockerfile index a669ac68..92a8b1dc 100644 --- a/docker/vapord/vapord.Dockerfile +++ b/docker/vapord/vapord.Dockerfile @@ -1,15 +1,15 @@ -FROM registry.cn-hangzhou.aliyuncs.com/matpool/golang-gcc-gpp:1.11.2 as builder +FROM bytom/golang-gcc-gpp:1.11.2 as builder LABEL stage=vapord_builder WORKDIR /go/src/github.com/vapor COPY . . -RUN go build -o /usr/local/vapord/vapord ./cmd/bytomd/main.go +RUN go build -o /usr/local/vapord/vapord ./cmd/vapord/main.go # save node public key in /usr/local/vapord/node_pubkey.txt RUN /usr/local/vapord/vapord init --chain_id vapor -r /usr/local/vapord 2>&1 | grep -o 'pubkey=[a-z0-9]*' | cut -d'=' -f 2 > /usr/local/vapord/node_pubkey.txt COPY ./docker/vapord/config.toml /usr/local/vapord/config.toml COPY ./docker/vapord/federation.json /usr/local/vapord/federation.json ### -FROM registry.cn-hangzhou.aliyuncs.com/matpool/alpine-ca-supervisord:latest +FROM bytom/alpine-ca-supervisord:latest COPY ./docker/vapord/supervisord.conf /etc/supervisor/conf.d/vapord.conf COPY --from=builder /usr/local/vapord /usr/local/vapord RUN mkdir -p /var/log/vapord -- 2.11.0