From 905021b5e274b84d1f3e3e313289919a79ed3939 Mon Sep 17 00:00:00 2001 From: David Krett Date: Thu, 26 Jul 2018 14:13:00 -0400 Subject: [PATCH] Interim ShyftGeth & PG Docker Working - TODO: ShyftBlockExplorerApi ShyftBlockExplorerUI & Monitoring --- .gitignore | 3 + .../develop-alpine/shyftGeth/Dockerfile | 8 +-- core/db.go | 5 +- docker-compose.yml | 26 ++++++--- shyft-cli/initShyftGeth.sh | 2 +- shyft-cli/startShyftGeth.sh | 2 +- wait-for-postgres.sh | 16 ------ wait-for.sh | 57 +++++++++++++++++++ 8 files changed, 84 insertions(+), 35 deletions(-) delete mode 100755 wait-for-postgres.sh create mode 100755 wait-for.sh diff --git a/.gitignore b/.gitignore index 720b4764e5..c7061f7d2b 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ shyftData/* shyft-cli/web3/token_test/node_modules shyft-cli/web3/transfer-through-master/node_modules shyft-cli/web3/transfer-through-master/build + +# Remove pg data +pg-data/* diff --git a/containers/docker/develop-alpine/shyftGeth/Dockerfile b/containers/docker/develop-alpine/shyftGeth/Dockerfile index dd7efeaf35..994d7611fd 100644 --- a/containers/docker/develop-alpine/shyftGeth/Dockerfile +++ b/containers/docker/develop-alpine/shyftGeth/Dockerfile @@ -7,8 +7,7 @@ WORKDIR /go/src/github.com/ShyftEthereum/go-empyrean RUN \ apk add --update git make gcc musl-dev linux-headers ca-certificates && \ (cd /go/src/github.com/ShyftEthereum/go-empyrean && make geth) && \ - cp /go/src/github.com/ShyftEthereum/go-empyrean/build/bin/geth /geth - + cp -v /go/src/github.com/ShyftEthereum/go-empyrean/build/bin/geth /bin COPY ./shyft-cli/initShyftGeth.sh / COPY ./shyft-cli/resetShyftGeth.sh / COPY ./shyft-cli/startShyftGeth.sh / @@ -23,9 +22,6 @@ COPY UTC--2018-03-18T22-37-04.212101982Z--5bd738164c61fb50eb12e227846cbaef2de965 COPY UTC--2018-03-18T22-37-12.082606217Z--c04ee4131895f1d0c294d508af65d94060aa42bb / COPY UTC--2018-03-18T22-37-19.650676366Z--07d899c4ac0c1725c35c5f816e60273b33a964f7 / -RUN cd / && ls -a -# EXPOSE 8545 -# EXPOSE 30303 WORKDIR / -CMD ["./initShyftGeth.sh"] \ No newline at end of file +CMD ["./initShyftGeth.sh", "/go/src/ShyftNetwork/go-empyrean/shyft-cli/initShyftGeth.sh/startShyftGeth.sh"] diff --git a/core/db.go b/core/db.go index 304d499fe0..4c69bfa338 100644 --- a/core/db.go +++ b/core/db.go @@ -7,9 +7,10 @@ import ( var blockExplorerDb *sql.DB +// @NOTE:SHYFT - TODO: Move connection parameters into an env file const ( - // connStr = "user=postgres dbname=shyftdb password=docker sslmode=disable" - connStr = "postgresql://postgres:docker@pg:5432/shyftdb" + connStr = "user=postgres dbname=shyftdb host=pg password=docker sslmode=disable" + // connStr = "postgresql://postgres:docker@pg:5432/shyftdb" connStrTest = "user=postgres dbname=shyftdbtest password=docker sslmode=disable" ) diff --git a/docker-compose.yml b/docker-compose.yml index 5579fd38ad..bd0281fc6b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ - version: '3' +version: '3' - services: +services: shyftgeth: build: context: $PWD @@ -14,26 +14,34 @@ - "5432:5432" volumes: - .:/go/src/ShyftNetwork/go-empyrean - # working_dir: /go/src/ShyftNetwork/go-empyrean + working_dir: /go/src/ShyftNetwork/go-empyrean depends_on: - pg - # command: ["./wait-for-postgres.sh", "pg:5432","./initShyftGeth.sh" ] - entrypoint: ["/go/src/ShyftNetwork/go-empyrean/wait-for-postgres.sh", "pg:5432","/go/src/ShyftNetwork/go-empyrean/shyft-cli/initShyftGeth.sh"] + networks: + - shyftnet + command: > + sh -c '/go/src/ShyftNetwork/go-empyrean/wait-for.sh pg:5432 && + /initShyftGeth.sh && + /startShyftGeth.sh' pg: build: context: $PWD dockerfile: containers/docker/develop-alpine/pg/Dockerfile volumes: - - ./pg-data:/var/lib/postgresql/data + - ./pg-data/data:/var/lib/postgresql/data ports: - - "5432" + - "8001:5432" + networks: + - shyftnet environment: - POSTGRES_USER=postgres - POSGRES_PASSWORD=docker - PGDATA=/pg-data - - +networks: + shyftnet: + driver: bridge + # api: # build: diff --git a/shyft-cli/initShyftGeth.sh b/shyft-cli/initShyftGeth.sh index 942fa66f45..eccb4303f8 100755 --- a/shyft-cli/initShyftGeth.sh +++ b/shyft-cli/initShyftGeth.sh @@ -1,2 +1,2 @@ #!/bin/sh -./geth --identity "ShyftTestnetNode" --keystore ./ --datadir "./shyftData" init ShyftNetwork.json \ No newline at end of file +/bin/geth --identity "ShyftTestnetNode" --keystore ./ --datadir "./shyftData" init ShyftNetwork.json \ No newline at end of file diff --git a/shyft-cli/startShyftGeth.sh b/shyft-cli/startShyftGeth.sh index 9085f628d3..19a5376e76 100755 --- a/shyft-cli/startShyftGeth.sh +++ b/shyft-cli/startShyftGeth.sh @@ -1,2 +1,2 @@ #!/bin/sh -./build/bin/geth --config config.toml --ws --wsaddr="0.0.0.0" --wsorigins "*" --nat=none --mine --minerthreads 4 --targetgaslimit 80000000 --unlock "0x43EC6d0942f7fAeF069F7F63D0384a27f529B062,0x9e602164C5826ebb5A6B68E4AFD9Cd466043dc4A,0x5Bd738164C61FB50eb12E227846CbaeF2dE965Aa,0xC04eE4131895F1d0C294D508AF65D94060AA42BB,0x07D899C4aC0c1725C35C5f816e60273B33a964F7" --password ./unlockPasswords.txt +/bin/geth --config config.toml --ws --wsaddr="0.0.0.0" --wsorigins "*" --nat=none --mine --minerthreads 4 --targetgaslimit 80000000 --unlock "0x43EC6d0942f7fAeF069F7F63D0384a27f529B062,0x9e602164C5826ebb5A6B68E4AFD9Cd466043dc4A,0x5Bd738164C61FB50eb12E227846CbaeF2dE965Aa,0xC04eE4131895F1d0C294D508AF65D94060AA42BB,0x07D899C4aC0c1725C35C5f816e60273B33a964F7" --password ./unlockPasswords.txt diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh deleted file mode 100755 index ed3fc41dfd..0000000000 --- a/wait-for-postgres.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# wait-for-postgres.sh - -set -e - -host="$1" -shift -cmd="$@" - -until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U "postgres" -c '\q'; do - >&2 echo "Postgres is unavailable - sleeping" - sleep 1 -done - ->&2 echo "Postgres is up - executing command" -exec $cmd \ No newline at end of file diff --git a/wait-for.sh b/wait-for.sh new file mode 100755 index 0000000000..daca546968 --- /dev/null +++ b/wait-for.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +log() { + echo "[wait-for] [`date +'%Y%m%d%H%M%S'`] $@" +} + +usage() { + echo "Usage: `basename "$0"` [--timeout=15] : [:]" +} + +unknown_arg() { + log "[ERROR] unknown argument: '$@'" + usage + exit 2 +} + +wait_for() { + timeout=$1 && host=$2 && port=$3 + log "wait '$host':'$port' up to '$timeout'" + for i in `seq $timeout` ; do + if nc -z "$host" "$port" > /dev/null 2>&1 ; then + log "wait finish '$host:$port' [`expr $(date +%s) - $START`] seconds" + exit 0 + fi + log "wait attempt '${host}:${port}' [$i]" + sleep 1 + done + log "[ERROR] wait timeout of '$timeout' on '$host:$port'" + exit 1 +} + +trap 'kill $(jobs -p) &>/dev/null' EXIT + +START=$(date +%s) +timeout=15 +pids="" +for i in $@ ; do + case $i in + --timeout=*) timeout="${i#*=}" ;; + -t=*) timeout="${i#*=}" ;; + *:* ) + wait_for "$timeout" "${i%%:*}" "${i##*:}" & + pids="$pids $!" + ;; + *) unknown_arg "$i" ;; + esac +done + +status=0 +for pid in $pids; do + if ! wait $pid ; then + status=1 + fi +done + +log "wait done with status=$status" +exit $status