From 9aa2e7bb8c099246a9d81051fffb7d2bdd9d5b9e Mon Sep 17 00:00:00 2001 From: Liviu Ancas <83750585+liviuf-ancas@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:00:26 +0200 Subject: [PATCH] Ft/multiple entry/docker file2 (#1434) * added sovereign * added placeholder config * added placeholder config * added placeholder config --------- Co-authored-by: liviuancas-elrond --- config/config.placeholder.yaml | 171 ++++++++++++++++++++++++++++ config/dapp.config.placeholder.json | 17 +++ entrypoint.sh | 101 +++++++++------- 3 files changed, 248 insertions(+), 41 deletions(-) create mode 100644 config/config.placeholder.yaml create mode 100644 config/dapp.config.placeholder.json mode change 100644 => 100755 entrypoint.sh diff --git a/config/config.placeholder.yaml b/config/config.placeholder.yaml new file mode 100644 index 000000000..e764432d9 --- /dev/null +++ b/config/config.placeholder.yaml @@ -0,0 +1,171 @@ +network: 'DAPP_CONFIG' +metaChainShardId: 4294967295 +api: + public: true + publicPort: 3001 + private: true + privatePort: 4001 + websocket: true +cron: + cacheWarmer: true + fastWarm: true + queueWorker: true + elasticUpdater: false +flags: + useRequestCaching: true + useKeepAliveAgent: true + useTracing: false + useRequestLogging: false + useVmQueryTracing: false + processNfts: true + collectionPropertiesFromGateway: false +features: + eventsNotifier: + enabled: false + port: 5674 + url: 'amqp://guest:guest@127.0.0.1:5673' + exchange: 'all_events' + queue: 'api-process-logs-and-events' + guestCaching: + enabled: false + hitsThreshold: 100 + ttl: 12 + transactionPool: + enabled: false + transactionPoolWarmer: + enabled: false + cronExpression: '*/5 * * * * *' + ttlInSeconds: 60 + updateCollectionExtraDetails: + enabled: false + updateAccountExtraDetails: + enabled: false + marketplace: + enabled: false + serviceUrl: 'MARKETPLACE_URL' + exchange: + enabled: false + serviceUrl: 'EXCHANGE_URL' + dataApi: + enabled: false + serviceUrl: 'DATAAPI_URL' + assetsFetch: + enabled: true + assetesUrl: 'ASSETSFETCH_URL' + auth: + enabled: false + maxExpirySeconds: 86400 + acceptedOrigins: + - '' + admins: + - '' + jwtSecret: '' + stakingV4: + enabled: false + cronExpression: '*/5 * * * * *' + activationEpoch: 1043 + nodeEpochsLeft: + enabled: false + transactionProcessor: + enabled: false + maxLookBehind: 100 + transactionCompleted: + enabled: false + maxLookBehind: 100 + logLevel: 'Error' + transactionBatch: + enabled: true + maxLookBehind: 100 + statusChecker: + enabled: false + thresholds: + tokens: 500 + nodes: 3000 + providers: 10 + tokenSupplyCount: 20 + tokenAssets: 20 + tokenAccounts: 500 + tokenTransactions: 500 + nodeValidators: 300 + nftScamInfo: + enabled: false + processNfts: + enabled: false + nftQueueName: 'api-process-nfts' + deadLetterQueueName: 'api-process-nfts-dlq' + tps: + enabled: false + maxLookBehindNonces: 100 + nodesFetch: + enabled: true + serviceUrl: 'NODESFETCH_URL' + tokensFetch: + enabled: true + serviceUrl: 'TOKENSFETCH_URL' + providersFetch: + enabled: true + serviceUrl: 'PROVIDERSFETCH_URL' +image: + width: 600 + height: 600 + type: 'png' +aws: + s3KeyId: '' + s3Secret: '' + s3Bucket: 'devnet-media.elrond.com' + s3Region: '' +urls: + self: 'https://devnet-api.multiversx.com' + elastic: + - 'ELASTICSEARCH_URL' + gateway: + - 'GATEWAY_URL' + verifier: 'https://play-api.multiversx.com' + redis: 'REDIS_IP' + rabbitmq: 'RABBITMQ_URL' + providers: 'PROVIDERS_URL' + delegation: 'DELEGATION_URL' + media: 'https://devnet-media.elrond.com' + nftThumbnails: 'https://devnet-media.elrond.com/nfts/thumbnail' + tmp: '/tmp' + ipfs: 'https://ipfs.io/ipfs' + socket: 'SOCKET_URL' + maiarId: 'https://devnet-id-api.multiversx.com' +indexer: + type: 'elastic' + maxPagination: 10000 +database: + enabled: false + url: 'mongodb://127.0.0.1:27017/api?authSource=admin' + type: 'mysql' + host: 'localhost' + port: 3306 + username: 'root' + password: 'root' + database: 'api' +caching: + cacheTtl: 6 + processTtl: 600 + poolLimit: 50 + cacheDuration: 3 +keepAliveTimeout: + downstream: 61000 + upstream: 60000 +contracts: + esdt: 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u' + auction: 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqplllst77y4l' + staking: 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqllls0lczs7' + delegationManager: 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6' + delegation: 'erd1qqqqqqqqqqqqqpgq97wezxw6l7lgg7k9rxvycrz66vn92ksh2tssxwf7ep' + metabonding: 'erd1qqqqqqqqqqqqqpgqkg7we73j769ew5we4yyx7uyvnn0nefqgd8ssm6vjc2' +inflation: + - 1952123 + - 1746637 + - 1541150 + - 1335663 + - 1130177 + - 924690 + - 719203 +nftProcess: + parallelism: 1 + maxRetries: 3 diff --git a/config/dapp.config.placeholder.json b/config/dapp.config.placeholder.json new file mode 100644 index 000000000..b042458a2 --- /dev/null +++ b/config/dapp.config.placeholder.json @@ -0,0 +1,17 @@ +{ + "id": "PLACEHOLDER_DAPP_id", + "name": "PLACEHOLDER_DAPP_name", + "egldLabel": "PLACEHOLDER_DAPP_egldLabel", + "decimals": "4", + "egldDenomination": "18", + "gasPerDataByte": "1500", + "apiTimeout": "4000", + "walletConnectDeepLink": "https://maiar.page.link/?apn=com.multiversx.maiar.wallet&isi=1519405832&ibi=com.multiversx.maiar.wallet&link=https://maiar.com/", + "walletConnectBridgeAddresses": [ + "https://bridge.walletconnect.org" + ], + "walletAddress": "PLACEHOLDER_DAPP_walletAddress", + "apiAddress": "PLACEHOLDER_DAPP_apiAddress", + "explorerAddress": "PLACEHOLDER_DAPP_explorerAddress", + "chainId": "PLACEHOLDER_DAPP_chainId" +} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh old mode 100644 new mode 100755 index 4d199798f..6f380f09a --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,46 +1,65 @@ #!/bin/sh # ENV VARIABLES - # MVX_ENV - defines what config to copy (default devnet) - # ELASTICSEARCH_URL - defines custom elasticsearch url - eg https://devnet-index.multiversx.com - # GATEWAY_URL - defines custom gateway url - eg https://devnet-gateway.multiversx.com - # REDIS_IP - defines redis ip - default 127.0.0.1 - -# CHECK IF ENV IS DEFINED -if [ -n "$MVX_ENV" ] && [ "$MVX_ENV" = "devnet" ]; then - # Copy config file - cp ./config/config.${MVX_ENV}.yaml /app/dist/config/config.yaml - - if [ $? -eq 0 ]; then - echo "Config file copied successfully from config/config.${MVX_ENV}.yaml /app/dist/config/config.yaml" - else - echo "Failed to copy the file." - fi - -else - cp ./config/config.devnet.yaml /app/dist/config/config.yaml - - if [ $? -eq 0 ]; then - echo "Default config file copied successfully from config/config.devnet.yaml /app/dist/config/config.yaml" - else - echo "Failed to copy the file." - fi -fi - -# Replaces urls if defined -if [ -n "$REDIS_IP" ]; then - echo "Redis IP defined: ${REDIS_IP}, replacing in config" - sed -i "s|redis: '127.0.0.1'|redis: '${REDIS_IP}'|g" /app/dist/config/config.yaml -fi - -if [ -n "$ELASTICSEARCH_URL" ]; then - echo "Elasticsearch url defined: ${ELASTICSEARCH_URL}, replacing in config" - sed -i "/^ elastic:/!b; n; s|.*| - '${ELASTICSEARCH_URL}'|" /app/dist/config/config.yaml -fi - -if [ -n "$GATEWAY_URL" ]; then - echo "Gateway url defined: ${GATEWAY_URL}, replacing in config" - sed -i "/^ gateway:/!b; n; s|.*| - '${GATEWAY_URL}'|" /app/dist/config/config.yaml -fi + # MVX_ENV=devnet + # DAPP_CONFIG=devnet + # REDIS_IP=127.0.0.1 + # ELASTICSEARCH_URL=https://devnet-index.multiversx.com + # GATEWAY_URL=https://devnet-gateway.multiversx.com + # RABBITMQ_URL=amqp://127.0.0.1:5672 + # PROVIDERS_URL=https://devnet-delegation-api.multiversx.com/providers + # DELEGATION_URL=https://devnet-delegation-api.multiversx.com + # SOCKET_URL=devnet-socket-api.multiversx.com + # NODESFETCH_URL= https://devnet-api.multiversx.com + # TOKENSFETCH_URL= https://devnet-api.multiversx.com + # PROVIDERSFETCH_URL= https://devnet-api.multiversx.com + # DATAAPI_URL=https://devnet-data-api.multiversx.com + # EXCHANGE_URL=https://devnet-graph.xexchange.com/graphql + # MARKETPLACE_URL=https://devnet-nfts-graph.multiversx.com/graphql + # ASSETSFETCH_URL=https://tools.multiversx.com/assets-cdn + # PLACEHOLDER_DAPP_id=devnet + # PLACEHOLDER_DAPP_name=Devnet + # PLACEHOLDER_DAPP_egldLabel=xEGLD + # PLACEHOLDER_DAPP_walletAddress=https://devnet-wallet.multiversx.com + # PLACEHOLDER_DAPP_apiAddress=https://devnet-api.multiversx.com + # PLACEHOLDER_DAPP_explorerAddress=http://devnet-explorer.multiversx.com + # PLACEHOLDER_DAPP_chainId=D +env_vars_with_defaults="MVX_ENV=devnet DAPP_CONFIG=devnet REDIS_IP=127.0.0.1 ELASTICSEARCH_URL=https://devnet-index.multiversx.com GATEWAY_URL=https://devnet-gateway.multiversx.com RABBITMQ_URL=amqp://127.0.0.1:5672 PROVIDERS_URL=https://devnet-delegation-api.multiversx.com/providers DATAAPI_URL=https://devnet-data-api.multiversx.com EXCHANGE_URL=https://devnet-graph.xexchange.com/graphql MARKETPLACE_URL=https://devnet-nfts-graph.multiversx.com/graphql ASSETSFETCH_URL=https://tools.multiversx.com/assets-cdn DELEGATION_URL=https://devnet-delegation-api.multiversx.com SOCKET_URL=devnet-socket-api.multiversx.com NODESFETCH_URL=https://devnet-api.multiversx.com TOKENSFETCH_URL=https://devnet-api.multiversx.com PROVIDERSFETCH_URL=https://devnet-api.multiversx.com PLACEHOLDER_DAPP_id=devnet PLACEHOLDER_DAPP_name=Devnet PLACEHOLDER_DAPP_egldLabel=xEGLD PLACEHOLDER_DAPP_walletAddress=https://devnet-wallet.multiversx.com PLACEHOLDER_DAPP_apiAddress=https://devnet-api.multiversx.com PLACEHOLDER_DAPP_explorerAddress=http://devnet-explorer.multiversx.com PLACEHOLDER_DAPP_chainId=D" + +replace_placeholder() { + local var_name=$1 + local var_value=$2 + + case $var_name in + PLACEHOLDER_DAPP*) + echo "Var ${var_name} defined, replacing ${var_value} in /app/config/dapp.config.placeholder.json" + sed -i "s|${var_name}|${var_value}|g" /app/config/dapp.config.placeholder.json + ;; + *) + echo "Var ${var_name} defined, replacing ${var_value} in /app/dist/config/config.yaml" + sed -i "s|${var_name}|${var_value}|g" /app/dist/config/config.yaml + ;; + esac + +} + +# Loop through each environment variable +for entry in $env_vars_with_defaults; do + # Split the entry into name and value + var_name=$(echo $entry | cut -d= -f1) + default_value=$(echo $entry | cut -d= -f2) + + # Use the environment variable value if defined; otherwise, use the default + eval "value=\${$var_name:-$default_value}" + + cp ./config/config.placeholder.yaml /app/dist/config/config.yaml + if [ $? -eq 0 ]; then + echo "Config file copied successfully from config/config.placeholder.yaml /app/dist/config/config.yaml" + fi + + # Execute the function with the variable name and value + replace_placeholder "$var_name" "$value" + +done exec /usr/local/bin/node dist/src/main.js