Skip to content

Commit

Permalink
Add entrypoint that customizes DBSync configuration
Browse files Browse the repository at this point in the history
Updated the custom entrypoint script for the Cardano DB Sync container
to include advanced configuration capabilities. Changes were made to
`scripts/govtool/custom-cardano-db-sync.entrypoint.sh` to set up
necessary environment variables, handle PostgreSQL authentication via a
`pgpass` file, and include the path to `db-sync-config.json`. The
`scripts/govtool/Makefile` and
`scripts/govtool/config/templates/docker-compose.yml.tpl` files were
adjusted to support these changes by implementing new build and
deployment targets for the custom Cardano DB Sync image and updating the
Docker Compose template.

These changes ensure the DBSync process uses the correct settings,
allowing it to adapt to future updates and ensuring better
synchronization with the Cardano blockchain.
  • Loading branch information
placek committed Jul 24, 2024
1 parent 78a591c commit c51f482
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/govtool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cardano_db_sync_image_tag := sancho-5.1.0
all: deploy-stack notify

.PHONY: deploy-stack
deploy-stack: upload-config push-backend push-frontend push-status-service push-metadata-validation push-analytics-dashboard
deploy-stack: upload-config push-backend push-frontend push-status-service push-metadata-validation push-analytics-dashboard push-custom-cardano-db-sync
@:$(call check_defined, cardano_network)
@:$(call check_defined, env)
export CARDANO_NETWORK=$(cardano_network); \
Expand Down
3 changes: 2 additions & 1 deletion scripts/govtool/config/templates/docker-compose.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ services:
logging: *logging

cardano-db-sync:
image: ghcr.io/intersectmbo/cardano-db-sync:${CARDANO_DB_SYNC_TAG}
image: <REPO_URL>/custom-cardano-db-sync:latest
environment:
- NETWORK=${CARDANO_NETWORK}
- POSTGRES_HOST=postgres
Expand All @@ -165,6 +165,7 @@ services:
volumes:
- db-sync-data:/var/lib/cexplorer
- node-ipc:/node-ipc
- /home/<DOCKER_USER>/config/cardano-node:/configuration
restart: always
logging: *logging

Expand Down
39 changes: 37 additions & 2 deletions scripts/govtool/custom-cardano-db-sync.entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
#!/bin/sh
echo "Custom Cardano DB Sync entrypoint"
# TODO: Add custom logic here
exec "$@"
set -euo pipefail
mkdir -p -m 1777 /tmp
mkdir -p /configuration
CARDANO_NODE_SOCKET_PATH=/node-ipc/node.socket
CARDANO_DB_SYNC_CONFIG_PATH=/configuration/db-sync-config.json

# set pgpass file
echo "-> Generating PGPASS file"
SECRET_DIR=/run/secrets
POSTGRES_DB=${POSTGRES_DB:-$(< ${SECRET_DIR}/postgres_db)}
POSTGRES_USER=${POSTGRES_USER:-$(< ${SECRET_DIR}/postgres_user)}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-$(< ${SECRET_DIR}/postgres_password)}
echo "${POSTGRES_HOST}:${POSTGRES_PORT}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}" > /configuration/pgpass
chmod 0600 /configuration/pgpass
export PGPASSFILE=/configuration/pgpass

# wait for cardano node to start
echo -n "-> Waiting for $CARDANO_NODE_SOCKET_PATH"
until [ -S "$CARDANO_NODE_SOCKET_PATH" ]; do
echo -n "."
sleep 10
done
echo

# find schema directory
echo "-> Finding schema directory"
SCHEMA_DIR=$(find /nix/store -type d -name '*-schema')

echo "-> Running Cardano DB Sync"
exec cardano-db-sync \
--config "$CARDANO_DB_SYNC_CONFIG_PATH" \
--socket-path "$CARDANO_NODE_SOCKET_PATH" \
--schema-dir "$SCHEMA_DIR" \
--state-dir /state \
$@

echo "-> Cleaning up"

0 comments on commit c51f482

Please sign in to comment.