diff --git a/containers/docker/develop-alpine/pg/Dockerfile b/containers/docker/develop-alpine/pg/Dockerfile index 53bf37ed04..f37803b4c8 100644 --- a/containers/docker/develop-alpine/pg/Dockerfile +++ b/containers/docker/develop-alpine/pg/Dockerfile @@ -1,3 +1,9 @@ FROM postgres:10.4-alpine +# @NOTE:Shyft - need to modify scripts to check db/table existence +WORKDIR / +COPY ./shyft-cli/postgres_setup/docker_init_user_db.sh /docker-entrypoint-initdb.d/docker_init_user_db.sh +RUN cd /docker-entrypoint-initdb.d && ls -a + + EXPOSE 5432 \ No newline at end of file diff --git a/containers/docker/develop-alpine/shyftGeth/Dockerfile b/containers/docker/develop-alpine/shyftGeth/Dockerfile index 6f87485cd0..dd7efeaf35 100644 --- a/containers/docker/develop-alpine/shyftGeth/Dockerfile +++ b/containers/docker/develop-alpine/shyftGeth/Dockerfile @@ -12,6 +12,7 @@ RUN \ COPY ./shyft-cli/initShyftGeth.sh / COPY ./shyft-cli/resetShyftGeth.sh / COPY ./shyft-cli/startShyftGeth.sh / +# COPY ./containers/docker/develop-alpine/shyftGeth/wait-for-postgres.sh / COPY config.toml / COPY unlockPasswords.txt / COPY ShyftNetwork.json / @@ -26,6 +27,5 @@ RUN cd / && ls -a # EXPOSE 8545 # EXPOSE 30303 WORKDIR / -RUN ["./initShyftGeth.sh"] -ENTRYPOINT ["./startShyftGeth.sh"] \ No newline at end of file +CMD ["./initShyftGeth.sh"] \ No newline at end of file diff --git a/core/db.go b/core/db.go index 31911822f9..304d499fe0 100644 --- a/core/db.go +++ b/core/db.go @@ -8,8 +8,9 @@ import ( var blockExplorerDb *sql.DB const ( - connStr = "user=postgres dbname=shyftdb sslmode=disable" - connStrTest = "user=postgres dbname=shyftdbtest sslmode=disable" + // connStr = "user=postgres dbname=shyftdb password=docker sslmode=disable" + connStr = "postgresql://postgres:docker@pg:5432/shyftdb" + connStrTest = "user=postgres dbname=shyftdbtest password=docker sslmode=disable" ) func InitDB() (*sql.DB, error) { diff --git a/docker-compose.yml b/docker-compose.yml index 68ff2fb428..5579fd38ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,9 +14,11 @@ - "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"] pg: build: context: $PWD @@ -29,6 +31,7 @@ - POSTGRES_USER=postgres - POSGRES_PASSWORD=docker - PGDATA=/pg-data + diff --git a/shyft-cli/postgres_setup/docker_init_user_db.sh b/shyft-cli/postgres_setup/docker_init_user_db.sh new file mode 100755 index 0000000000..de3db488e8 --- /dev/null +++ b/shyft-cli/postgres_setup/docker_init_user_db.sh @@ -0,0 +1,65 @@ +#!/bin/bash +set -e +echo $POSTGRES_USER +echo $POSTGRES_DB +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE DATABASE shyftdb; + \connect shyftdb; + CREATE TABLE IF NOT EXISTS blocks ( + hash text primary key, + coinbase text, + gasUsed numeric, + gasLimit numeric, + txCount numeric, + uncleCount numeric, + age timestamp, + parentHash text, + uncleHash text, + difficulty bigint, + size text, + nonce numeric, + rewards numeric, + number bigint + ); + CREATE TABLE IF NOT EXISTS txs ( + txHash text primary key unique, + to_addr text, + from_addr text, + blockhash text references blocks(hash), + blocknumber text, + amount numeric, + gasprice numeric, + gas numeric, + gasLimit numeric, + txFee numeric, + nonce numeric, + txStatus text, + isContract bool, + age timestamp, + data bytea + ); + + CREATE TABLE IF NOT EXISTS accounts ( + addr text primary key unique, + balance numeric, + txCountAccount numeric + ); + + CREATE TABLE IF NOT EXISTS contracts ( + txHash text + ); + + CREATE TABLE IF NOT EXISTS internalTxs ( + id SERIAL PRIMARY KEY, + txHash text references txs(txHash), + type text, + to_addr text, + from_addr text, + amount text, + gas numeric, + gasUsed numeric, + time text, + input text, + output text + ); +EOSQL diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh new file mode 100755 index 0000000000..ed3fc41dfd --- /dev/null +++ b/wait-for-postgres.sh @@ -0,0 +1,16 @@ +#!/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