To build image holding Hivemind instance, please use [build_instance.sh](scripts/ci/build_instance.sh). This script requires several parameters:
- tag identifier to be set on built image
- directory where Hivemind source code is located
- docker registry url to produce fully qualified image name and allow to correctly resolve its dependencies
```bash
$ # Assuming you are in workdir directory, to perform out of source build
$ ../hivemind/scripts/ci/build_instance.sh local ../hivemind registry.gitlab.syncad.com/hive/hivemind/
```
### Running HAF instance container
Hivemind instance requires a HAF instance to process data collected by it like also to share its database for storing own data.
Easiest way to setup HAF instance is also used dockerized setup.
To start HAF instance we need to prepare a data directory containing:
- blockchain subdirectory (where can be put block_log file)
- optional, but very useful, copy of haf/doc/haf_postgresql_conf.d directory, what allows to simple customization of Postgres setup by modification of `custom_postgres.conf` and `custom_pg_hba.conf` stored inside
Please take care for correct permissions, to provide write access to the data directory for processes running inside started container.
For example, for testing purposes (assuming block_log file has been put into data-dir), you can spawn 5M replay to prepare HAF database for further quick testing:
By examining hived.log file or using docker logs haf-mainnet-instance you can examine state of started instance, once replay will be finished you can continue and start Hivemind sync process.
Example output of hived process stopped on 5000000 block:
```
2022-12-19T18:28:05.574637 chain_plugin.cpp:701 replay_blockchain ] Stopped blockchain replaying on user request. Last applied block numbe
r: 5000000.
2022-12-19T18:28:05.574658 chain_plugin.cpp:966 plugin_startup ] P2P enabling after replaying...
2022-12-19T18:28:05.574670 chain_plugin.cpp:721 work ] Started on blockchain with 5000000 blocks, LIB: 4999980
2022-12-19T18:28:05.574687 chain_plugin.cpp:727 work ] Started on blockchain with 5000000 blocks
$ ../hivemind/scripts/setup_db.sh --postgres-url=postgresql://haf_admin@172.17.0.2/haf_block_log # warning this command requires haf_admin access since super user permissions are required to install intarray extension
```
Above commands assume that running HAF container has IP: 172.17.0.2