From debc6565273eb7bd8ad73e08ebef3e56503060e6 Mon Sep 17 00:00:00 2001 From: Taylor Gunnoe Date: Thu, 15 Aug 2024 07:42:47 -0400 Subject: [PATCH] feat(process-compose): add preprod to stack --- flake.lock | 10 +- flake.nix | 2 +- nix/processes.nix | 415 ++++++++++++++++++++++++---------------------- 3 files changed, 220 insertions(+), 207 deletions(-) diff --git a/flake.lock b/flake.lock index 4611ae24b..2990884dc 100644 --- a/flake.lock +++ b/flake.lock @@ -244,15 +244,15 @@ }, "services-flake": { "locked": { - "lastModified": 1701369356, - "narHash": "sha256-dG76HIfz72mChsNa7ZDFYHlK/PzyU7tUtBIskaMdR9E=", - "owner": "tgunnoe", + "lastModified": 1723336031, + "narHash": "sha256-FJOvmGACkAPnnOQE02xxhUg913V5g+XoRrXWt40t/fQ=", + "owner": "juspay", "repo": "services-flake", - "rev": "292e978eae9d0db205f6e0cfdf8fa798c964fabb", + "rev": "034722b4046bf687e8fafa6626a88890abfad33f", "type": "github" }, "original": { - "owner": "tgunnoe", + "owner": "juspay", "repo": "services-flake", "type": "github" } diff --git a/flake.nix b/flake.nix index 83de778a5..b3ea0afa0 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,7 @@ }; blank.url = "github:input-output-hk/empty-flake"; process-compose.url = "github:Platonic-Systems/process-compose-flake"; - services-flake.url = "github:tgunnoe/services-flake"; + services-flake.url = "github:juspay/services-flake"; # Partner Chains deps smart-contracts = { diff --git a/nix/processes.nix b/nix/processes.nix index d98b05159..db1cac69f 100644 --- a/nix/processes.nix +++ b/nix/processes.nix @@ -11,224 +11,237 @@ system, ... }: let - data-dir = "./.run"; - node-socket = "${data-dir}/cardano-node/node.socket"; - configs-dir = "${inputs.configurations}/network/preview"; - node-config = "${configs-dir}/cardano-node/config.json"; - in { - process-compose."partnerchains-stack-unwrapped" = { - imports = [ - inputs.services-flake.processComposeModules.default - ]; - tui = true; - #port = 8081; - services.postgres."postgres" = { - enable = true; - port = 5432; - dataDir = "${data-dir}/db-sync/database"; - listen_addresses = "127.0.0.1"; - initialDatabases = [{name = "cexplorer";}]; - initdbArgs = [ - "--locale=C" - "--encoding=UTF8" - "--username=postgres" - "--pwfile=${pkgs.writeText "password" "password123"}" - ]; - }; - settings = { - processes = { - tip-status = { - namespace = "cardano-node"; + mkStack = network: let + data-dir = "./.run/${network}"; + node-socket = "${data-dir}/cardano-node/node.socket"; + configs-dir = "${inputs.configurations}/network/${network}"; + node-config = "${configs-dir}/cardano-node/config.json"; + magic = if network == "preview" then "2" else "1"; + in { + "tip-status-${network}" = { + namespace = network; + command = '' + export CARDANO_NODE_SOCKET_PATH=${node-socket} + while true; do + ${self'.packages.cardano-cli}/bin/cardano-cli \ + query tip --testnet-magic ${magic}; + sleep 10 + done + ''; + depends_on = { + "cardano-node-${network}".condition = "process_healthy"; + }; + + readiness_probe = { + exec = { command = '' export CARDANO_NODE_SOCKET_PATH=${node-socket} + ${self'.packages.cardano-cli}/bin/cardano-cli \ + query tip --testnet-magic ${magic} \ + | jq -e '.syncProgress == "100.00" | not' && exit 1 || exit 0 + ''; + }; + initial_delay_seconds = 25; + period_seconds = 30; + timeout_seconds = 10; + success_threshold = 1; + failure_threshold = 1000; + }; + }; + "cardano-node-${network}" = { + namespace = network; + liveness_probe = { + exec = { + command = '' + pgrep -f cardano-node + ''; + }; + initial_delay_seconds = 5; + period_seconds = 2; + timeout_seconds = 5; + success_threshold = 5; + failure_threshold = 3; + }; + readiness_probe = { + exec = { + command = '' while true; do - ${self'.packages.cardano-cli}/bin/cardano-cli \ - query tip --testnet-magic 2; - sleep 10 + if [ -S ${node-socket} ] && nc -U -z -w 1 ${node-socket}; then + exit 0 + fi + sleep 5 done ''; - #is_tty = true; - depends_on = { - cardano-node.condition = "process_healthy"; - }; - - readiness_probe = { - exec = { - command = '' - export CARDANO_NODE_SOCKET_PATH=${node-socket} - ${self'.packages.cardano-cli}/bin/cardano-cli \ - query tip --testnet-magic 2 \ - | jq -e '.syncProgress == "100.00" | not' && exit 1 || exit 0 - ''; - }; - initial_delay_seconds = 25; - period_seconds = 30; - timeout_seconds = 10; - success_threshold = 1; - failure_threshold = 1000; - }; }; - cardano-node = { - namespace = "cardano-node"; - liveness_probe = { - exec = { - command = '' - pgrep -f cardano-node - ''; - }; - initial_delay_seconds = 5; - period_seconds = 2; - timeout_seconds = 5; - success_threshold = 5; - failure_threshold = 3; - }; - readiness_probe = { - exec = { - command = '' - while true; do - if [ -S ${node-socket} ] && nc -U -z -w 1 ${node-socket}; then - exit 0 - fi - sleep 5 - done - ''; - }; - initial_delay_seconds = 25; - period_seconds = 5; - timeout_seconds = 20; - success_threshold = 1; - failure_threshold = 1000; - }; - availability.restart = "on_failure"; - shutdown = { - signal = 2; - }; - command = '' - ${self'.packages.cardano-node}/bin/cardano-node run +RTS -N -RTS \ - --topology ${configs-dir}/cardano-node/topology.json \ - --database-path ${data-dir}/cardano-node/data \ + initial_delay_seconds = 25; + period_seconds = 5; + timeout_seconds = 20; + success_threshold = 1; + failure_threshold = 1000; + }; + availability.restart = "on_failure"; + shutdown = { + signal = 2; + }; + command = '' + ${self'.packages.cardano-node}/bin/cardano-node run +RTS -N -RTS \ + --topology ${configs-dir}/cardano-node/topology.json \ + --database-path ${data-dir}/cardano-node/data \ + --socket-path ${node-socket} \ + --host-addr 0.0.0.0 \ + --port ${if network == "preview" then "3030" else "3031"} \ + --config ${node-config} + ''; + environment = { + NETWORK = network; + CARDANO_NODE_SOCKET_PATH = node-socket; + }; + }; + "db-sync-${network}" = let + pgpass = pkgs.writeText "pgpass-mainnet" '' + 127.0.0.1:${if network == "preview" then "5432" else "5433"}:cexplorer:postgres:password123 + ''; + in { + namespace = network; + command = pkgs.writeShellApplication { + name = "cardano-db-sync"; + runtimeInputs = [pkgs.postgresql]; + text = '' + ${self'.packages."cardano-db-sync:exe:cardano-db-sync"}/bin/cardano-db-sync \ + --config ${configs-dir}/cardano-db-sync/config.json \ --socket-path ${node-socket} \ - --host-addr 0.0.0.0 \ - --port 3030 \ - --config ${node-config} + --state-dir ${data-dir}/db-sync/ledger-state \ + --schema-dir ${inputs.cardano-dbsync}/schema/ + ''; + }; + depends_on = { + "postgres-${network}".condition = "process_healthy"; + "cardano-node-${network}".condition = "process_healthy"; + }; + liveness_probe = { + exec = { + command = '' + pgrep -f cardano-db-sync ''; - environment = { - NETWORK = "preview"; - CARDANO_NODE_SOCKET_PATH = node-socket; - }; }; - db-sync = let - pgpass = pkgs.writeText "pgpass-mainnet" '' - 127.0.0.1:5432:cexplorer:postgres:password123 + }; + availability.restart = "on_failure"; + environment = { + NETWORK = network; + PGPASSFILE = "${pgpass}"; + POSTGRES_HOST = "127.0.0.1"; + POSTGRES_PORT = if network == "preview" then "5432" else "5433"; + POSTGRES_DB = "cexplorer"; + POSTGRES_USER = "postgres"; + POSTGRES_PASSWORD = "password123"; + }; + }; + "ogmios-${network}" = { + namespace = network; + command = '' + ${self'.packages.ogmios}/bin/ogmios \ + --host 0.0.0.0 \ + --node-config ${node-config} \ + --node-socket ${node-socket} \ + --port ${if network == "preview" then "1337" else "1338"} + ''; + environment = { + DATA_DIR = "${data-dir}/ogmios"; + OGMIOS_PORT = if network == "preview" then "1337" else "1338"; + }; + liveness_probe = { + exec = { + command = '' + pgrep -f ogmios ''; - in { - command = pkgs.writeShellApplication { - name = "cardano-db-sync"; - runtimeInputs = [pkgs.postgresql]; - text = '' - ${self'.packages."cardano-db-sync:exe:cardano-db-sync"}/bin/cardano-db-sync \ - --config ${configs-dir}/cardano-db-sync/config.json \ - --socket-path ${node-socket} \ - --state-dir ${data-dir}/db-sync/ledger-state \ - --schema-dir ${inputs.cardano-dbsync}/schema/ - ''; - }; - depends_on = { - "postgres".condition = "process_healthy"; - cardano-node.condition = "process_healthy"; - }; - liveness_probe = { - exec = { - command = '' - pgrep -f cardano-db-sync - ''; - }; - }; - availability.restart = "on_failure"; - environment = { - NETWORK = "preview"; - PGPASSFILE = "${pgpass}"; - POSTGRES_HOST = "127.0.0.1"; - POSTGRES_PORT = "5432"; - POSTGRES_DB = "cexplorer"; - POSTGRES_USER = "postgres"; - POSTGRES_PASSWORD = "password123"; - }; }; - ogmios = { - command = '' - ${self'.packages.ogmios}/bin/ogmios \ - --host 0.0.0.0 --node-config ${node-config} --node-socket ${node-socket} - # ''; - environment = { - DATA_DIR = "${data-dir}/ogmios"; - OGMIOS_PORT = "1337"; - }; - liveness_probe = { - exec = { - command = '' - pgrep -f ogmios - ''; - }; - initial_delay_seconds = 5; - period_seconds = 2; - timeout_seconds = 5; - success_threshold = 5; - failure_threshold = 3; - }; - readiness_probe = { - http_get = { - host = "0.0.0.0"; - port = 1337; - }; - initial_delay_seconds = 5; - period_seconds = 5; - timeout_seconds = 20; - success_threshold = 1; - failure_threshold = 1000; - }; - availability.restart = "on_failure"; - depends_on.cardano-node.condition = "process_healthy"; + initial_delay_seconds = 5; + period_seconds = 2; + timeout_seconds = 5; + success_threshold = 5; + failure_threshold = 3; + }; + readiness_probe = { + http_get = { + host = "0.0.0.0"; + port = if network == "preview" then 1337 else 1338; }; - kupo = { + initial_delay_seconds = 5; + period_seconds = 5; + timeout_seconds = 20; + success_threshold = 1; + failure_threshold = 1000; + }; + availability.restart = "on_failure"; + depends_on."cardano-node-${network}".condition = "process_healthy"; + }; + "kupo-${network}" = { + namespace = network; + command = '' + ${self'.packages.kupo}/bin/kupo \ + --node-socket ${node-socket} \ + --node-config ${node-config} \ + --host 0.0.0.0 \ + --workdir ${data-dir}/kupo \ + --match "*" \ + --since origin \ + --port ${if network == "preview" then "1442" else "1443"} + ''; + liveness_probe = { + exec = { command = '' - ${self'.packages.kupo}/bin/kupo \ - --node-socket ${node-socket} \ - --node-config ${node-config} \ - --host 0.0.0.0 \ - --workdir ${data-dir}/kupo \ - --match "*" \ - --since origin + pgrep -f kupo ''; - liveness_probe = { - exec = { - command = '' - pgrep -f kupo - ''; - }; - initial_delay_seconds = 5; - period_seconds = 2; - timeout_seconds = 5; - success_threshold = 5; - failure_threshold = 3; - }; - readiness_probe = { - http_get = { - host = "0.0.0.0"; - port = 1442; - path = "/matches"; - }; - initial_delay_seconds = 5; - period_seconds = 5; - timeout_seconds = 20; - success_threshold = 1; - failure_threshold = 20; - }; - availability.restart = "on_failure"; - depends_on.cardano-node.condition = "process_healthy"; }; + initial_delay_seconds = 5; + period_seconds = 2; + timeout_seconds = 5; + success_threshold = 5; + failure_threshold = 3; + }; + readiness_probe = { + http_get = { + host = "0.0.0.0"; + port = if network == "preview" then 1442 else 1443; + path = "/matches"; + }; + initial_delay_seconds = 5; + period_seconds = 5; + timeout_seconds = 20; + success_threshold = 1; + failure_threshold = 20; }; + availability.restart = "on_failure"; + depends_on."cardano-node-${network}".condition = "process_healthy"; }; }; + mkService = network: let + data-dir = "./.run/${network}"; + in { + "postgres-${network}" = { + enable = true; + namespace = network; + port = if network == "preview" then 5432 else 5433; + dataDir = "${data-dir}/db-sync/database"; + listen_addresses = "127.0.0.1"; + initialDatabases = [{name = "cexplorer";}]; + superuser = "postgres"; + initdbArgs = [ + "--locale=C" + "--encoding=UTF8" + "--username=postgres" + "--pwfile=${pkgs.writeText "password" "password123"}" + ]; + }; + }; + in { + process-compose."partnerchains-stack-unwrapped" = { + imports = [ + inputs.services-flake.processComposeModules.default + ]; + tui = true; + settings.processes = mkStack "preview" // mkStack "preprod"; + services.postgres = mkService "preview" // mkService "preprod"; + }; }; }