Sandbox database empty
Closed this issue · 2 comments
Possibly I'm missing something crucial, but after starting the flextesa sandbox with
make flextesa-sandbox
the database does not get initialised (no migrations are run, I suppose). Here's an excerpt from the logs:
db_1 | 2021-11-17 17:08:40.888 UTC [84] ERROR: relation "head_stats" does not exist
db_1 | 2021-11-17 17:08:40.888 UTC [84] STATEMENT: REFRESH MATERIALIZED VIEW CONCURRENTLY head_stats;
metrics_1 |
metrics_1 | 2021/11/17 17:08:40 /go/src/github.com/baking-bad/bcdhub/cmd/metrics/services/view.go:30 ERROR: relation "head_stats" does not exist (SQLSTATE 42P01)
metrics_1 | [0.712ms] [rows:0] REFRESH MATERIALIZED VIEW CONCURRENTLY head_stats;
metrics_1 | ERR error="ERROR: relation \"head_stats\" does not exist (SQLSTATE 42P01)"
db_1 | 2021-11-17 17:08:40.891 UTC [86] ERROR: relation "states" does not exist at character 15
db_1 | 2021-11-17 17:08:40.891 UTC [86] STATEMENT: SELECT * FROM "states" WHERE name = $1 ORDER BY "states"."name" LIMIT 1
metrics_1 |
metrics_1 | 2021/11/17 17:08:40 /go/src/github.com/baking-bad/bcdhub/internal/postgres/service/storage.go:23 ERROR: relation "states" does not exist (SQLSTATE 42P01)
metrics_1 | [4.832ms] [rows:0] SELECT * FROM "states" WHERE name = 'projects' ORDER BY "states"."name" LIMIT 1
metrics_1 | ERR error="ERROR: relation \"states\" does not exist (SQLSTATE 42P01)"
metrics_1 | INF starting service... name=projects
db_1 | 2021-11-17 17:08:41.501 UTC [87] ERROR: relation "head_stats" does not exist
db_1 | 2021-11-17 17:08:41.501 UTC [87] STATEMENT: REFRESH MATERIALIZED VIEW CONCURRENTLY head_stats;
Dumping the database with
COMPOSE_PROJECT_NAME=bcdbox docker-compose exec db pg_dump -c indexer > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
confirms this.
Ok so I figured it out in the end. Part my lack of understanding of docker and its networks.
To start off with, the felxtesa binding to 172.17.0.1:8732:20000 failed for me, so I took that out and hoped it would just work. It didn't. That made the indexer fail to connect to the node and the migrations would not be run.
What worked for me was to use links
instead of extra_hosts
, there probably is a better, more general, way to do this, but I'll just leave my solution here for posterity.
docker-compose.sandbox.yml
version: "3.6"
services:
elastic:
image: bakingbad/bcdhub-elastic:4.0
restart: always
volumes:
- esdata:/usr/share/elasticsearch/data
environment:
- bootstrap.memory_lock=true
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms256m -Xmx256m"
logging: &bcd-logging
options:
max-size: 10m
max-file: "5"
db:
image: postgres:12
shm_size: 1g
restart: always
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
- POSTGRES_DB=indexer
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- db:/var/lib/postgresql/data
logging: *bcd-logging
api:
restart: always
image: bakingbad/bcdhub-api:4.0
environment:
- BCD_ENV=sandbox
- GIN_MODE=debug
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
- SANDBOX_NODE_URI=http://sandbox:20000
- SANDBOX_IPFS_GATEWAY=https://cloudflare-ipfs.com
depends_on:
- elastic
- db
ports:
- 127.0.0.1:14000:14000
volumes:
- bcdshare:/etc/bcd
links:
- "flextesa:sandbox"
logging: *bcd-logging
indexer:
restart: always
image: bakingbad/bcdhub-indexer:4.0
environment:
- BCD_ENV=sandbox
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
- SANDBOX_NODE_URI=http://sandbox:20000
- SANDBOX_IPFS_GATEWAY=https://cloudflare-ipfs.com
depends_on:
- db
- metrics
links:
- "flextesa:sandbox"
volumes:
- bcdshare:/etc/bcd
logging: *bcd-logging
metrics:
restart: always
image: bakingbad/bcdhub-metrics:4.0
environment:
- BCD_ENV=sandbox
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
- SANDBOX_NODE_URI=http://sandbox:20000
- SANDBOX_IPFS_GATEWAY=https://cloudflare-ipfs.com
depends_on:
- elastic
- db
links:
- "flextesa:sandbox"
volumes:
- bcdshare:/etc/bcd
logging: *bcd-logging
flextesa:
restart: always
image: tqtezos/flextesa:20211025
command: granabox start
environment:
- block_time=4
ports:
- "20000:20000"
expose:
- 20000/tcp
logging: *bcd-logging
gui:
container_name: sandbox-gui
restart: always
image: bakingbad/bcdhub-gui:4.0
depends_on:
- api
ports:
- 127.0.0.1:8000:80
logging: *bcd-logging
volumes:
esdata:
bcdshare:
db:
driver: local
Hey @852Kerfunkle, sorry for the late reply!
Indeed extra_hosts
is not a pretty solution, but kinda working on all platforms (as turned out not :))
It also works with the setup when Tezos node is run on the host machine (exposed at 0.0.0.0)
Thanks for the recipe! I'll update the compose file