diff --git a/app/data/compose/docker-compose-watcher-azimuth.yml b/app/data/compose/docker-compose-watcher-azimuth.yml index cc3a6e55..094eca94 100644 --- a/app/data/compose/docker-compose-watcher-azimuth.yml +++ b/app/data/compose/docker-compose-watcher-azimuth.yml @@ -32,11 +32,11 @@ services: environment: CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} working_dir: /app/packages/azimuth-watcher - command: "yarn server" + command: "./start-server.sh" volumes: - - ../config/watcher-azimuth/watcher-configs/azimuth-watcher.toml:/app/packages/azimuth-watcher/environments/local.toml - # ports: - # - "0.0.0.0:3001:3001" + - ../config/watcher-azimuth/watcher-config.toml:/app/packages/azimuth-watcher/environments/watcher-config.toml + - ../config/watcher-azimuth/merge-toml.js:/app/packages/azimuth-watcher/merge-toml.js + - ../config/watcher-azimuth/start-server.sh:/app/packages/azimuth-watcher/start-server.sh healthcheck: test: ["CMD", "nc", "-vz", "localhost", "3001"] interval: 20s @@ -56,11 +56,11 @@ services: environment: CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG} working_dir: /app/packages/censures-watcher - command: "yarn server" + command: "./start-server.sh" volumes: - - ../config/watcher-azimuth/watcher-configs/censures-watcher.toml:/app/packages/censures-watcher/environments/local.toml - # ports: - # - "0.0.0.0:3001:3001" + - ../config/watcher-azimuth/watcher-config.toml:/app/packages/censures-watcher/environments/watcher-config.toml + - ../config/watcher-azimuth/merge-toml.js:/app/packages/censures-watcher/merge-toml.js + - ../config/watcher-azimuth/start-server.sh:/app/packages/censures-watcher/start-server.sh healthcheck: test: ["CMD", "nc", "-vz", "localhost", "3002"] interval: 20s diff --git a/app/data/config/watcher-azimuth/merge-toml.js b/app/data/config/watcher-azimuth/merge-toml.js new file mode 100644 index 00000000..11b91b10 --- /dev/null +++ b/app/data/config/watcher-azimuth/merge-toml.js @@ -0,0 +1,33 @@ +const fs = require('fs'); +const tomlJS = require('toml-js'); +const toml = require('toml'); +const { merge } = require('lodash') + +const main = () => { + const overrideConfigString = fs.readFileSync('environments/watcher-config.toml', 'utf-8'); + const configString = fs.readFileSync('environments/local.toml', 'utf-8'); + const overrideConfig = toml.parse(overrideConfigString) + const config = toml.parse(configString) + + // Merge configs + const updatedConfig = merge(config, overrideConfig); + + // Form dbConnectionString for jobQueue DB + const parts = config.jobQueue.dbConnectionString.split("://"); + const credsAndDB = parts[1].split("@"); + const creds = credsAndDB[0].split(":"); + creds[0] = overrideConfig.database.username; + creds[1] = overrideConfig.database.password; + credsAndDB[0] = creds.join(":"); + const dbName = credsAndDB[1].split("/")[1] + credsAndDB[1] = [overrideConfig.database.host, dbName].join("/"); + parts[1] = credsAndDB.join("@"); + + updatedConfig.jobQueue.dbConnectionString = parts.join("://"); + + updatedConfig.jobQueue.dbConnectionString = parts.join("://"); + + fs.writeFileSync('environments/local.toml', tomlJS.dump(updatedConfig), 'utf-8'); +} + +main(); diff --git a/app/data/config/watcher-azimuth/start-server.sh b/app/data/config/watcher-azimuth/start-server.sh new file mode 100755 index 00000000..5df6a2d1 --- /dev/null +++ b/app/data/config/watcher-azimuth/start-server.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi + +CERC_IPLD_ETH_RPC="${CERC_IPLD_ETH_RPC:-${DEFAULT_CERC_IPLD_ETH_RPC}}" +CERC_IPLD_GQL="${CERC_IPLD_GQL:-${DEFAULT_CERC_IPLD_GQL}}" + +echo "Using IPLD ETH RPC endpoint ${CERC_IPLD_ETH_RPC}" +echo "Using IPLD GQL endpoint ${CERC_IPLD_GQL}" + +# # TODO: Replace env variables in template TOML file +# # Read in the config template TOML file and modify it +# WATCHER_CONFIG_TEMPLATE=$(cat environments/watcher-config-template.toml) +# WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \ +# sed -E "s|REPLACE_WITH_CERC_RELAY_PEERS|${CERC_RELAY_PEERS}|g; \ +# s|REPLACE_WITH_CERC_L2_GETH_RPC_ENDPOINT|${CERC_L2_GETH_RPC}| ") + +# # Write the modified content to a new file +# echo "$WATCHER_CONFIG" > environments/watcher-config.toml + +# Merge SO watcher config with existing config file +yarn add --dev --ignore-scripts toml-js +node merge-toml.js + + +echo 'yarn server' +yarn server diff --git a/app/data/config/watcher-azimuth/watcher-config.toml b/app/data/config/watcher-azimuth/watcher-config.toml new file mode 100644 index 00000000..eb5711f2 --- /dev/null +++ b/app/data/config/watcher-azimuth/watcher-config.toml @@ -0,0 +1,13 @@ +[server] + host = "0.0.0.0" + +[database] + host = "watcher-db" + port = 5432 + username = "vdbm" + password = "password" + +[upstream] + [upstream.ethServer] + gqlApiEndpoint = "http://host.docker.internal:8083/graphql" + rpcProviderEndpoint = "http://host.docker.internal:8082"