Add js script to merge toml config files
This commit is contained in:
parent
1a993a2c6d
commit
2bef7c0044
@ -32,11 +32,11 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
|
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
|
||||||
working_dir: /app/packages/azimuth-watcher
|
working_dir: /app/packages/azimuth-watcher
|
||||||
command: "yarn server"
|
command: "./start-server.sh"
|
||||||
volumes:
|
volumes:
|
||||||
- ../config/watcher-azimuth/watcher-configs/azimuth-watcher.toml:/app/packages/azimuth-watcher/environments/local.toml
|
- ../config/watcher-azimuth/watcher-config.toml:/app/packages/azimuth-watcher/environments/watcher-config.toml
|
||||||
# ports:
|
- ../config/watcher-azimuth/merge-toml.js:/app/packages/azimuth-watcher/merge-toml.js
|
||||||
# - "0.0.0.0:3001:3001"
|
- ../config/watcher-azimuth/start-server.sh:/app/packages/azimuth-watcher/start-server.sh
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "nc", "-vz", "localhost", "3001"]
|
test: ["CMD", "nc", "-vz", "localhost", "3001"]
|
||||||
interval: 20s
|
interval: 20s
|
||||||
@ -56,11 +56,11 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
|
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
|
||||||
working_dir: /app/packages/censures-watcher
|
working_dir: /app/packages/censures-watcher
|
||||||
command: "yarn server"
|
command: "./start-server.sh"
|
||||||
volumes:
|
volumes:
|
||||||
- ../config/watcher-azimuth/watcher-configs/censures-watcher.toml:/app/packages/censures-watcher/environments/local.toml
|
- ../config/watcher-azimuth/watcher-config.toml:/app/packages/censures-watcher/environments/watcher-config.toml
|
||||||
# ports:
|
- ../config/watcher-azimuth/merge-toml.js:/app/packages/censures-watcher/merge-toml.js
|
||||||
# - "0.0.0.0:3001:3001"
|
- ../config/watcher-azimuth/start-server.sh:/app/packages/censures-watcher/start-server.sh
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "nc", "-vz", "localhost", "3002"]
|
test: ["CMD", "nc", "-vz", "localhost", "3002"]
|
||||||
interval: 20s
|
interval: 20s
|
||||||
|
33
app/data/config/watcher-azimuth/merge-toml.js
Normal file
33
app/data/config/watcher-azimuth/merge-toml.js
Normal file
@ -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();
|
29
app/data/config/watcher-azimuth/start-server.sh
Executable file
29
app/data/config/watcher-azimuth/start-server.sh
Executable file
@ -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
|
13
app/data/config/watcher-azimuth/watcher-config.toml
Normal file
13
app/data/config/watcher-azimuth/watcher-config.toml
Normal file
@ -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"
|
Loading…
Reference in New Issue
Block a user