Merge pull request #65 from chapsuk/dev_env

Dockerized dev environment, geth rinkeby
This commit is contained in:
Rob Mulholand 2018-06-27 09:13:38 -05:00 committed by GitHub
commit 74d6046508
7 changed files with 137 additions and 0 deletions

View File

@ -82,3 +82,24 @@ migrate: $(MIGRATE) checkdbvars
import:
test -n "$(NAME)" # $$NAME
psql $(NAME) < db/schema.sql
#Rinkeby docker environment
RINKEBY_COMPOSE_FILE=dockerfiles/rinkeby/docker-compose.yml
.PHONY: rinkeby_env_up
rinkeby_env_up:
docker-compose -f $(RINKEBY_COMPOSE_FILE) up -d geth
docker-compose -f $(RINKEBY_COMPOSE_FILE) up --build migrations
docker-compose -f $(RINKEBY_COMPOSE_FILE) up -d --build vulcanizedb
.PHONY: rinkeby_env_deploy
rinkeby_env_deploy:
docker-compose -f $(RINKEBY_COMPOSE_FILE) up -d --build vulcanizedb
.PHONY: dev_env_migrate
rinkeby_env_migrate:
docker-compose -f $(RINKEBY_COMPOSE_FILE) up --build migrations
.PHONY: rinkeby_env_down
rinkeby_env_down:
docker-compose -f $(RINKEBY_COMPOSE_FILE) down

View File

@ -69,6 +69,29 @@ Sync VulcanizeDB from the LevelDB underlying a Geth node.
- `--ending-block-number`/`-e`: block number to sync to
- `--all`/`-a`: sync all missing blocks
## Start full environment in docker by single command
### Geth Rinkeby
make command | description
------------------- | ----------------
rinkeby_env_up | start geth, postgres and rolling migrations, after migrations done starting vulcanizedb container
rinkeby_env_deploy | build and run vulcanizedb container in rinkeby environment
rinkeby_env_migrate | build and run rinkeby env migrations
rinkeby_env_down | stop and remove all rinkeby env containers
Success run of the VulcanizeDB container require full geth state sync,
attach to geth console and check sync state:
```bash
$ docker exec -it rinkeby_vulcanizedb_geth geth --rinkeby attach
...
> eth.syncing
false
```
If you have full rinkeby chaindata you can move it to `rinkeby_vulcanizedb_geth_data` docker volume to skip long wait of sync.
## Running the Tests
### Unit Tests

View File

@ -39,6 +39,8 @@ func database(cmd *cobra.Command, args []string) {
Name: viper.GetString("database.name"),
Hostname: viper.GetString("database.hostname"),
Port: viper.GetInt("database.port"),
User: viper.GetString("database.user"),
Password: viper.GetString("database.password"),
}
viper.Set("database.config", databaseConfig)
}
@ -50,12 +52,16 @@ func init() {
rootCmd.PersistentFlags().String("database-name", "vulcanize_public", "database name")
rootCmd.PersistentFlags().Int("database-port", 5432, "database port")
rootCmd.PersistentFlags().String("database-hostname", "localhost", "database hostname")
rootCmd.PersistentFlags().String("database-user", "", "database user")
rootCmd.PersistentFlags().String("database-password", "", "database password")
rootCmd.PersistentFlags().String("client-ipcPath", "", "location of geth.ipc file")
rootCmd.PersistentFlags().String("client-levelDbPath", "", "location of levelDb chaindata")
viper.BindPFlag("database.name", rootCmd.PersistentFlags().Lookup("database-name"))
viper.BindPFlag("database.port", rootCmd.PersistentFlags().Lookup("database-port"))
viper.BindPFlag("database.hostname", rootCmd.PersistentFlags().Lookup("database-hostname"))
viper.BindPFlag("database.user", rootCmd.PersistentFlags().Lookup("database-user"))
viper.BindPFlag("database.password", rootCmd.PersistentFlags().Lookup("database-password"))
viper.BindPFlag("client.ipcPath", rootCmd.PersistentFlags().Lookup("client-ipcPath"))
viper.BindPFlag("client.levelDbPath", rootCmd.PersistentFlags().Lookup("client-levelDbPath"))
}

View File

@ -0,0 +1,9 @@
FROM golang:1.10.3-alpine3.7
RUN apk add --no-cache make gcc musl-dev
ADD . /go/src/github.com/vulcanize/vulcanizedb
WORKDIR /go/src/github.com/vulcanize/vulcanizedb
RUN go build -o /app main.go
ENTRYPOINT ["/app"]

View File

@ -0,0 +1,9 @@
[database]
name = "vulcanizedb"
hostname = "postgres"
port = 5432
user = "postgres"
password = "postgres"
[client]
ipcPath = "/geth/geth.ipc"

View File

@ -0,0 +1,63 @@
version: '2.2'
services:
vulcanizedb:
build:
context: ./../../
dockerfile: dockerfiles/rinkeby/Dockerfile
container_name: rinkeby_vulcanizedb
command: "sync --starting-block-number 0 --config /config.toml"
volumes:
- "./config.toml:/config.toml"
- "vulcanizedb_geth_data:/geth"
networks:
vulcanizedb_net:
migrations:
image: migrate/migrate:v3.3.0
container_name: rinkeby_vulcanizedb_migrations
depends_on:
postgres:
condition: service_healthy
command: -database postgresql://postgres:postgres@postgres:5432/vulcanizedb?sslmode=disable -path /migrations up
volumes:
- ./../../db/migrations:/migrations
networks:
vulcanizedb_net:
postgres:
image: postgres:9.6.5-alpine
container_name: rinkeby_vulcanizedb_postgres
environment:
POSTGRES_USER: postgres
POSTGRES_DB: vulcanizedb
POSTGRES_PASSWORD: postgres
volumes:
- "vulcanizedb_db_data:/var/lib/postgresql/data"
networks:
vulcanizedb_net:
healthcheck:
test: ["CMD", "pg_isready"]
interval: 5s
timeout: 5s
retries: 30
geth:
image: ethereum/client-go:v1.8.11
container_name: rinkeby_vulcanizedb_geth
cpus: 0.3
hostname: eth
command: '--rinkeby --rpc --rpcaddr="0.0.0.0" --rpcvhosts="geth"'
volumes:
- "vulcanizedb_geth_data:/root/.ethereum/rinkeby"
networks:
vulcanizedb_net:
volumes:
vulcanizedb_geth_data:
vulcanizedb_db_data:
networks:
vulcanizedb_net:
driver: bridge

View File

@ -5,9 +5,15 @@ import "fmt"
type Database struct {
Hostname string
Name string
User string
Password string
Port int
}
func DbConnectionString(dbConfig Database) string {
if len(dbConfig.User) > 0 && len(dbConfig.Password) > 0 {
return fmt.Sprintf("postgresql://%s:%s@%s:%d/%s?sslmode=disable",
dbConfig.User, dbConfig.Password, dbConfig.Hostname, dbConfig.Port, dbConfig.Name)
}
return fmt.Sprintf("postgresql://%s:%d/%s?sslmode=disable", dbConfig.Hostname, dbConfig.Port, dbConfig.Name)
}