mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
Interim - Adjust Scripts & PG Connection Params to facilitate Docker DB option
This commit is contained in:
parent
905021b5e2
commit
122c62ca81
6 changed files with 86 additions and 49 deletions
21
core/db.go
21
core/db.go
|
|
@ -3,18 +3,23 @@ package core
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var blockExplorerDb *sql.DB
|
||||
|
||||
// @NOTE:SHYFT - TODO: Move connection parameters into an env file
|
||||
// @NOTE: SHYFT - could be refactored to add a test db environment
|
||||
const (
|
||||
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"
|
||||
)
|
||||
|
||||
var connStr = connectionStr()
|
||||
|
||||
// InitDB - initalizes a Postgresql Database for use by the Blockexplorer
|
||||
func InitDB() (*sql.DB, error) {
|
||||
// To set the environment you can run the program with an ENV variable DBENV.
|
||||
// DBENV defaults to local for purposes of running the correct local
|
||||
// database connection parameters but will use docker connection parameters if DBENV=docker
|
||||
db, err := sql.Open("postgres", connStr)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR OPENING DB, NOT INITIALIZING")
|
||||
|
|
@ -26,6 +31,16 @@ func InitDB() (*sql.DB, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func connectionStr() string {
|
||||
dbEnv := os.Getenv("DBENV")
|
||||
switch dbEnv {
|
||||
default:
|
||||
return "user=postgres dbname=shyftdb host=localhost sslmode=disable"
|
||||
case "docker":
|
||||
return "user=postgres dbname=shyftdb host=pg password=docker sslmode=disable"
|
||||
}
|
||||
}
|
||||
|
||||
func InitDBTest() (*sql.DB, error) {
|
||||
db, err := sql.Open("postgres", connStrTest)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ import (
|
|||
"math/big"
|
||||
"strings"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
"database/sql"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/ShyftNetwork/go-empyrean/common"
|
||||
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
|
||||
"github.com/ShyftNetwork/go-empyrean/common/math"
|
||||
|
|
@ -35,9 +38,7 @@ import (
|
|||
"github.com/ShyftNetwork/go-empyrean/log"
|
||||
"github.com/ShyftNetwork/go-empyrean/params"
|
||||
"github.com/ShyftNetwork/go-empyrean/rlp"
|
||||
"database/sql"
|
||||
"strconv"
|
||||
"time"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
|
||||
|
|
@ -188,7 +189,9 @@ func WriteShyftGen(gen *Genesis, block *types.Block) {
|
|||
}
|
||||
default:
|
||||
log.Info("Found Genesis Block")
|
||||
}}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WriteShyftBlockZero(block *types.Block, gen *Genesis) error {
|
||||
|
||||
|
|
@ -229,6 +232,7 @@ func WriteShyftBlockZero(block *types.Block, gen *Genesis) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetupGenesisBlock writes or updates the genesis block in db.
|
||||
// The block that will be used is:
|
||||
//
|
||||
|
|
@ -315,6 +319,7 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
|
|||
return params.AllEthashProtocolChanges
|
||||
}
|
||||
}
|
||||
|
||||
// ToBlock creates the genesis block and writes state of a genesis specification
|
||||
// to the given database (or discards it if nil).
|
||||
func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
|
||||
|
|
@ -439,6 +444,7 @@ func DefaultRinkebyGenesisBlock() *Genesis {
|
|||
Alloc: decodePrealloc(rinkebyAllocData),
|
||||
}
|
||||
}
|
||||
|
||||
// DeveloperGenesisBlock returns the 'geth --dev' genesis block. Note, this must
|
||||
// be seeded with the
|
||||
func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ services:
|
|||
- shyftnet
|
||||
command: >
|
||||
sh -c '/go/src/ShyftNetwork/go-empyrean/wait-for.sh pg:5432 &&
|
||||
DBENV=docker export DBENV &&
|
||||
/initShyftGeth.sh &&
|
||||
/startShyftGeth.sh'
|
||||
pg:
|
||||
|
|
@ -28,7 +29,7 @@ services:
|
|||
context: $PWD
|
||||
dockerfile: containers/docker/develop-alpine/pg/Dockerfile
|
||||
volumes:
|
||||
- ./pg-data/data:/var/lib/postgresql/data
|
||||
- ./pg-data:/var/lib/postgresql/
|
||||
ports:
|
||||
- "8001:5432"
|
||||
networks:
|
||||
|
|
@ -36,12 +37,19 @@ services:
|
|||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSGRES_PASSWORD=docker
|
||||
- PGDATA=/pg-data
|
||||
# api:
|
||||
# build:
|
||||
# context: $PWD
|
||||
# dockerfile: containers/docker/develop-alpine/shyftApi/Dockerfile
|
||||
# volumes: -
|
||||
|
||||
|
||||
|
||||
networks:
|
||||
shyftnet:
|
||||
driver: bridge
|
||||
|
||||
# volumes:
|
||||
# pg-data:
|
||||
|
||||
# api:
|
||||
# build:
|
||||
|
|
|
|||
|
|
@ -1,2 +1,6 @@
|
|||
#!/bin/sh
|
||||
if [[ -z "${DBENV}" ]]; then
|
||||
./build/bin/geth --identity "ShyftTestnetNode" --keystore ./ --datadir "./shyftData" init ShyftNetwork.json
|
||||
else
|
||||
/bin/geth --identity "ShyftTestnetNode" --keystore ./ --datadir "./shyftData" init ShyftNetwork.json
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,2 +1,6 @@
|
|||
#!/bin/sh
|
||||
if [[ -z "${DBENV}" ]]; then
|
||||
./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
|
||||
else
|
||||
/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
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
# https://github.com/eficode/wait-for.git
|
||||
log() {
|
||||
echo "[wait-for] [`date +'%Y%m%d%H%M%S'`] $@"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue