Skip to content

Commit

Permalink
Merge pull request #1609 from IntersectMBO/fix/1464-add-enable-future…
Browse files Browse the repository at this point in the history
…-genesis-to-dbsync-configuration

[#1464] Enable future genesis in DBSync config
  • Loading branch information
placek authored Jul 24, 2024
2 parents 1a86aa9 + c51f482 commit 10aff0c
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/resync-cardano-node-and-db-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
description: "Enable proposal discussion forum"
required: true
type: choice
default: "disabled"
default: "enabled"
options:
- "enabled"
- "disabled"
Expand Down Expand Up @@ -65,9 +65,10 @@ jobs:
TRAEFIK_LE_EMAIL: "[email protected]"
USERSNAP_SPACE_API_KEY: ${{ secrets.USERSNAP_SPACE_API_KEY }}
IS_PROPOSAL_DISCUSSION_FORUM_ENABLED: ${{ inputs.isProposalDiscussionForumEnabled == 'enabled' }}
PDF_API_URL: ${{ secrets.PDF_API_URL }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ treefmt.toml
local/

# used by haskell
govtool/backend/dist-newstyle/
govtool/backend/.stack-work/
dist-newstyle/
.stack-work/

# target environment config dir
scripts/govtool/config/target
Expand All @@ -141,4 +141,4 @@ scripts/govtool/dev-postgres_password
node_modules

# sonar scanner
.scannerwork/
.scannerwork/
12 changes: 11 additions & 1 deletion infra/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ module "govtool-ecr-analytics-dashboard" {
repo_name = "analytics-dashboard"
}

module "govtool-ecr-custom-cardano-db-sync" {
source = "./modules/ecr"
repo_name = "custom-cardano-db-sync"
}

resource "aws_iam_policy" "cicd_ecr" {
name = "CICD_ECR"
policy = jsonencode({
Expand All @@ -57,7 +62,8 @@ resource "aws_iam_policy" "cicd_ecr" {
module.govtool-ecr-frontend.repo_arn,
module.govtool-ecr-status-service.repo_arn,
module.govtool-ecr-metadata-validation.repo_arn,
module.govtool-ecr-analytics-dashboard.repo_arn
module.govtool-ecr-analytics-dashboard.repo_arn,
module.govtool-ecr-custom-cardano-db-sync.repo_arn
]
},
{
Expand Down Expand Up @@ -135,6 +141,10 @@ output "govtool-ecr-analytics-dashboard-url" {
value = module.govtool-ecr-analytics-dashboard.repo_url
}

output "govtool-ecr-custom-cardano-db-sync-url" {
value = module.govtool-ecr-custom-cardano-db-sync.repo_url
}

output "govtool-dev-sanchonet-frontend-domain" {
value = module.govtool-dev-sanchonet.frontend_domain
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/govtool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include frontend.mk
include status-service.mk
include metadata-validation.mk
include analytics-dashboard.mk
include custom-cardano-db-sync.mk
include utils.mk
include info.mk
include config.mk
Expand All @@ -17,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
7 changes: 6 additions & 1 deletion scripts/govtool/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ target_config_dir := $(config_dir)/target

# files
docker_compose_file := $(target_config_dir)/docker-compose.yml
cardano_configs := alonzo-genesis byron-genesis conway-genesis db-sync-config shelley-genesis submit-api-config topology
cardano_configs := alonzo-genesis byron-genesis conway-genesis shelley-genesis submit-api-config topology
cardano_config_files := $(addprefix $(target_config_dir)/cardano-node/,$(addsuffix .json,$(cardano_configs)))
outputs := cardano-node/config.json \
cardano-node/db-sync-config.json \
dbsync-secrets/postgres_user \
dbsync-secrets/postgres_db \
dbsync-secrets/postgres_password \
Expand Down Expand Up @@ -67,6 +68,10 @@ $(target_config_dir)/cardano-node/config.json: $(target_config_dir)/cardano-node
$(curl) -s "$(cardano_config_provider)/environments/$(cardano_network)/$(notdir $@)" -o $@
sed -i '/"hasPrometheus"/ { N; s/"127\.0\.0\.1"/"0.0.0.0"/ }' "$(target_config_dir)/cardano-node/config.json"

$(target_config_dir)/cardano-node/db-sync-config.json: $(target_config_dir)/cardano-node/
$(curl) -s "$(cardano_config_provider)/environments/$(cardano_network)/$(notdir $@)" -o $@
sed -i '1a\ "EnableFutureGenesis" : true,' "$(target_config_dir)/cardano-node/db-sync-config.json"

$(target_config_dir)/dbsync-secrets/postgres_user: $(target_config_dir)/dbsync-secrets/
echo "$${DBSYNC_POSTGRES_USER}" > $@

Expand Down
4 changes: 3 additions & 1 deletion scripts/govtool/config/templates/docker-compose.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,13 @@ 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
- POSTGRES_PORT=5432
- RESTORE_RECREATE_DB=N
- DB_SYNC_ENABLE_FUTURE_GENESIS=Y
depends_on:
cardano-node:
condition: service_healthy
Expand All @@ -164,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
6 changes: 6 additions & 0 deletions scripts/govtool/custom-cardano-db-sync.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ghcr.io/intersectmbo/cardano-db-sync:sancho-5.1.0

COPY custom-cardano-db-sync.entrypoint.sh /usr/local/bin/custom-cardano-db-sync.entrypoint.sh
RUN chmod +x /usr/local/bin/custom-cardano-db-sync.entrypoint.sh

ENTRYPOINT [ "/usr/local/bin/custom-cardano-db-sync.entrypoint.sh" ]
39 changes: 39 additions & 0 deletions scripts/govtool/custom-cardano-db-sync.entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
echo "Custom Cardano DB Sync entrypoint"
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"
22 changes: 22 additions & 0 deletions scripts/govtool/custom-cardano-db-sync.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
common_mk := common.mk
ifeq ($(origin $(common_mk)), undefined)
$(eval $(common_mk) := included)
include $(common_mk)
endif

.DEFAULT_GOAL := push-custom-cardano-db-sync

# image tags
custom-cardano-db-sync_image_tag := latest

.PHONY: build-custom-cardano-db-sync
build-custom-cardano-db-sync: docker-login
@:$(call check_defined, cardano_network)
$(call check_image_on_ecr,custom-cardano-db-sync,$(custom-cardano-db-sync_image_tag)) || \
$(docker) build --tag "$(repo_url)/custom-cardano-db-sync:$(custom-cardano-db-sync_image_tag)" --file "$(root_dir)/scripts/govtool/custom-cardano-db-sync.Dockerfile"\
$(root_dir)/scripts/govtool

.PHONY: push-custom-cardano-db-sync
push-custom-cardano-db-sync: build-custom-cardano-db-sync
$(call check_image_on_ecr,custom-cardano-db-sync,$(custom-cardano-db-sync_image_tag)) || \
$(docker) push $(repo_url)/custom-cardano-db-sync:$(custom-cardano-db-sync_image_tag)

0 comments on commit 10aff0c

Please sign in to comment.