From c51f4823d486efa2a2252400d5c2090bbc3d1b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Placzy=C5=84ski?= Date: Wed, 24 Jul 2024 12:47:43 +0200 Subject: [PATCH] Add entrypoint that customizes DBSync configuration 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. --- scripts/govtool/Makefile | 2 +- .../config/templates/docker-compose.yml.tpl | 3 +- .../custom-cardano-db-sync.entrypoint.sh | 39 ++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/scripts/govtool/Makefile b/scripts/govtool/Makefile index df87dbd00..9040e048f 100644 --- a/scripts/govtool/Makefile +++ b/scripts/govtool/Makefile @@ -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); \ diff --git a/scripts/govtool/config/templates/docker-compose.yml.tpl b/scripts/govtool/config/templates/docker-compose.yml.tpl index 4d75bd3ce..653312e82 100644 --- a/scripts/govtool/config/templates/docker-compose.yml.tpl +++ b/scripts/govtool/config/templates/docker-compose.yml.tpl @@ -146,7 +146,7 @@ services: logging: *logging cardano-db-sync: - image: ghcr.io/intersectmbo/cardano-db-sync:${CARDANO_DB_SYNC_TAG} + image: /custom-cardano-db-sync:latest environment: - NETWORK=${CARDANO_NETWORK} - POSTGRES_HOST=postgres @@ -165,6 +165,7 @@ services: volumes: - db-sync-data:/var/lib/cexplorer - node-ipc:/node-ipc + - /home//config/cardano-node:/configuration restart: always logging: *logging diff --git a/scripts/govtool/custom-cardano-db-sync.entrypoint.sh b/scripts/govtool/custom-cardano-db-sync.entrypoint.sh index 6e408c071..f9e9c621c 100644 --- a/scripts/govtool/custom-cardano-db-sync.entrypoint.sh +++ b/scripts/govtool/custom-cardano-db-sync.entrypoint.sh @@ -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"