|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +CONFIG_PATH="/root/.chia/mainnet/cadt/v1/config.yaml" |
| 4 | + |
| 5 | +# Function to update yaml value if environment variable exists |
| 6 | +update_yaml_if_env_exists() { |
| 7 | + local env_var=$1 |
| 8 | + local yaml_path=$2 |
| 9 | + |
| 10 | + if [ ! -z "${!env_var}" ]; then |
| 11 | + yq -i "$yaml_path = ${!env_var}" $CONFIG_PATH |
| 12 | + fi |
| 13 | +} |
| 14 | + |
| 15 | +# Create config directory if it doesn't exist |
| 16 | +mkdir -p /root/.chia/mainnet/cadt/v1 |
| 17 | + |
| 18 | +# If config doesn't exist, create it with default values from defaultConfig.js |
| 19 | +if [ ! -f $CONFIG_PATH ]; then |
| 20 | + # Use Node to convert defaultConfig.js to YAML |
| 21 | + node -e ' |
| 22 | + const yaml = require("yaml"); |
| 23 | + const { defaultConfig } = require("/app/src/utils/defaultConfig.js"); |
| 24 | + const fs = require("fs"); |
| 25 | + fs.writeFileSync(process.env.CONFIG_PATH, yaml.stringify(defaultConfig)); |
| 26 | + ' |
| 27 | +fi |
| 28 | + |
| 29 | +# MIRROR_DB section |
| 30 | +update_yaml_if_env_exists "DB_USERNAME" '.MIRROR_DB.DB_USERNAME' |
| 31 | +update_yaml_if_env_exists "DB_PASSWORD" '.MIRROR_DB.DB_PASSWORD' |
| 32 | +update_yaml_if_env_exists "DB_NAME" '.MIRROR_DB.DB_NAME' |
| 33 | +update_yaml_if_env_exists "DB_HOST" '.MIRROR_DB.DB_HOST' |
| 34 | + |
| 35 | +# APP section |
| 36 | +update_yaml_if_env_exists "CW_PORT" '.APP.CW_PORT' |
| 37 | +update_yaml_if_env_exists "BIND_ADDRESS" '.APP.BIND_ADDRESS' |
| 38 | +update_yaml_if_env_exists "DATALAYER_URL" '.APP.DATALAYER_URL' |
| 39 | +update_yaml_if_env_exists "WALLET_URL" '.APP.WALLET_URL' |
| 40 | +update_yaml_if_env_exists "USE_SIMULATOR" '.APP.USE_SIMULATOR' |
| 41 | +update_yaml_if_env_exists "READ_ONLY" '.APP.READ_ONLY' |
| 42 | +update_yaml_if_env_exists "CADT_API_KEY" '.APP.CADT_API_KEY' |
| 43 | +update_yaml_if_env_exists "CHIA_NETWORK" '.APP.CHIA_NETWORK' |
| 44 | +update_yaml_if_env_exists "USE_DEVELOPMENT_MODE" '.APP.USE_DEVELOPMENT_MODE' |
| 45 | +update_yaml_if_env_exists "IS_GOVERNANCE_BODY" '.APP.IS_GOVERNANCE_BODY' |
| 46 | +update_yaml_if_env_exists "DEFAULT_FEE" '.APP.DEFAULT_FEE' |
| 47 | +update_yaml_if_env_exists "DEFAULT_COIN_AMOUNT" '.APP.DEFAULT_COIN_AMOUNT' |
| 48 | +update_yaml_if_env_exists "CERTIFICATE_FOLDER_PATH" '.APP.CERTIFICATE_FOLDER_PATH' |
| 49 | +update_yaml_if_env_exists "DATALAYER_FILE_SERVER_URL" '.APP.DATALAYER_FILE_SERVER_URL' |
| 50 | +update_yaml_if_env_exists "AUTO_SUBSCRIBE_FILESTORE" '.APP.AUTO_SUBSCRIBE_FILESTORE' |
| 51 | +update_yaml_if_env_exists "AUTO_MIRROR_EXTERNAL_STORES" '.APP.AUTO_MIRROR_EXTERNAL_STORES' |
| 52 | +update_yaml_if_env_exists "LOG_LEVEL" '.APP.LOG_LEVEL' |
| 53 | + |
| 54 | +# APP.TASKS section |
| 55 | +update_yaml_if_env_exists "GOVERNANCE_SYNC_TASK_INTERVAL" '.APP.TASKS.GOVERNANCE_SYNC_TASK_INTERVAL' |
| 56 | +update_yaml_if_env_exists "ORGANIZATION_META_SYNC_TASK_INTERVAL" '.APP.TASKS.ORGANIZATION_META_SYNC_TASK_INTERVAL' |
| 57 | +update_yaml_if_env_exists "PICKLIST_SYNC_TASK_INTERVAL" '.APP.TASKS.PICKLIST_SYNC_TASK_INTERVAL' |
| 58 | +update_yaml_if_env_exists "MIRROR_CHECK_TASK_INTERVAL" '.APP.TASKS.MIRROR_CHECK_TASK_INTERVAL' |
| 59 | +update_yaml_if_env_exists "CHECK_ORG_TABLE_SUBSCRIPTIONS_TASK_INTERVAL" '.APP.TASKS.CHECK_ORG_TABLE_SUBSCRIPTIONS_TASK_INTERVAL' |
| 60 | + |
| 61 | +# GOVERNANCE section |
| 62 | +update_yaml_if_env_exists "GOVERNANCE_BODY_ID" '.GOVERNANCE.GOVERNANCE_BODY_ID' |
| 63 | + |
| 64 | +# Execute the command passed to docker run |
| 65 | +exec "$@" |
0 commit comments