Regular users should almost never attempt building and running from the master branch. Instead,
they should build and run the latest release tag. The tags can be listed using the git tag
command. Pre-release tags (eg things like 12.0.0-preX) should also be avoided in most cases.
git clone git@github.com:input-output-hk/cardano-db-sync.git
cd cardano-db-sync
git checkout <latest-official-tag> -b tag-<latest-official-tag>
docker-compose up -d && docker-compose logs -fThe PostgreSQL database is exposed on localhost port 5432
$ psql -h 0.0.0.0 -p 5432 -U postgres -d cexplorer (then enter secret password)
NETWORK=testnet docker-compose up && docker-compose logs -f
Excluding the NETWORK ENV will simply just call the cardano-db-sync executable
as the entrypoint, so you must pass a command and
arguments in this case to provide config at runtime. The --schema-dir argument is preset,
so is not required.
Using Docker run to demonstrate, but can be achieved using docker-compose too via
service.command
docker run \
-v $PWD/config/network/mainnet/cardano-db-sync:/config
-v $PWD/config/network/mainnet/genesis:/genesis
-v $PWD/node-ipc:/node-ipc \
inputoutput/cardano-db-sync \
run --config /config/config.yaml --socket-path /node-ipc/node.socket # command
docker load -i $(nix-build -A dockerImage --no-out-link)
Restoring a database by running from gensis can take a number of hours, snapshots are provided for
both networks (Mainnet and Testnet) to restore the postgres database. See the
latest releases for a recent snapshot
matched with the cardano-db-sync version.
To download and restore a snapshot include RESTORE_SNAPSHOT:
RESTORE_SNAPSHOT=https://update-cardano-mainnet.iohk.io/cardano-db-sync/db-sync-snapshot-schema-10-block-6014140-x86_64.tgz \
NETWORK=testnet docker-compose up && docker-compose logs -f
Create a pgpass-test file with the credentials of (taken from config/secrets/postgres_* files):
echo "localhost:5432:cexplorer:postgres:v8hlDV0yMAHHlIurYupj" > config/pgpass-test
chmod 0600 config/pgpass-testinside config/pgpass-test
Startup docker postgres via:
docker-compose -f docker-test.yml upSetup database with tables:
PGPASSFILE=$PWD/config/pgpass-test \
cabal run cardano-db-tool run-migrations -- --mdir schema/ --ldir .Running the tests:
PGPASSFILE=$PWD/config/pgpass-test \
cabal test cardano-dbWhen you've finished with testing either docker-compose down or Ctl-C the terminal session.
docker-compose down -f docker-test.ymlAssuming a base OSX machine with Nix installed. Building a Docker image for cardano-db-sync requires a Linux host to compile on. Nix provides a way to do remote builds
Prerequisites:
- shell account on NixOS Linux machine (ask on Slack) eg. builder@x86_64-linux.example.com
Assuming you want a Linux x86 image run:
nix-build -A dockerImage --no-out-link \
--builders 'ssh://builder@x86_64-linux.example.com x86_64-linux' \
--argstr system x86_64-linuxAt the end it will generate a tar.gz file
eg /nix/store/arbrn0fs54whkn64m0wrcbl9hjd35byn-docker-image-cardano-db-sync.tar.gz
that can be loaded into docker and run as a normal image.
$ docker load -i /nix/store/arbrn0fs54whkn64m0wrcbl9hjd35byn-docker-image-cardano-db-sync.tar.gz
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
inputoutput/cardano-db-sync 066b747a8bfd3791b06ea46c2e793f83ed64967f f34b029e9c5c 15 hours ago 911MB
# Run this as
$ docker run inputoutput/cardano-db-sync:066b747a8bfd3791b06ea46c2e793f83ed64967f