|
1 | 1 | #!/bin/sh |
2 | 2 | # ENV VARIABLES |
3 | | - # MVX_ENV - defines what config to copy (default devnet) |
4 | | - # ELASTICSEARCH_URL - defines custom elasticsearch url - eg https://devnet-index.multiversx.com |
5 | | - # GATEWAY_URL - defines custom gateway url - eg https://devnet-gateway.multiversx.com |
6 | | - # REDIS_IP - defines redis ip - default 127.0.0.1 |
7 | | - |
8 | | -# CHECK IF ENV IS DEFINED |
9 | | -if [ -n "$MVX_ENV" ] && [ "$MVX_ENV" = "devnet" ]; then |
10 | | - # Copy config file |
11 | | - cp ./config/config.${MVX_ENV}.yaml /app/dist/config/config.yaml |
12 | | - |
13 | | - if [ $? -eq 0 ]; then |
14 | | - echo "Config file copied successfully from config/config.${MVX_ENV}.yaml /app/dist/config/config.yaml" |
15 | | - else |
16 | | - echo "Failed to copy the file." |
17 | | - fi |
18 | | - |
19 | | -else |
20 | | - cp ./config/config.devnet.yaml /app/dist/config/config.yaml |
21 | | - |
22 | | - if [ $? -eq 0 ]; then |
23 | | - echo "Default config file copied successfully from config/config.devnet.yaml /app/dist/config/config.yaml" |
24 | | - else |
25 | | - echo "Failed to copy the file." |
26 | | - fi |
27 | | -fi |
28 | | - |
29 | | -# Replaces urls if defined |
30 | | -if [ -n "$REDIS_IP" ]; then |
31 | | - echo "Redis IP defined: ${REDIS_IP}, replacing in config" |
32 | | - sed -i "s|redis: '127.0.0.1'|redis: '${REDIS_IP}'|g" /app/dist/config/config.yaml |
33 | | -fi |
34 | | - |
35 | | -if [ -n "$ELASTICSEARCH_URL" ]; then |
36 | | - echo "Elasticsearch url defined: ${ELASTICSEARCH_URL}, replacing in config" |
37 | | - sed -i "/^ elastic:/!b; n; s|.*| - '${ELASTICSEARCH_URL}'|" /app/dist/config/config.yaml |
38 | | -fi |
39 | | - |
40 | | -if [ -n "$GATEWAY_URL" ]; then |
41 | | - echo "Gateway url defined: ${GATEWAY_URL}, replacing in config" |
42 | | - sed -i "/^ gateway:/!b; n; s|.*| - '${GATEWAY_URL}'|" /app/dist/config/config.yaml |
43 | | -fi |
| 3 | + # MVX_ENV=devnet |
| 4 | + # DAPP_CONFIG=devnet |
| 5 | + # REDIS_IP=127.0.0.1 |
| 6 | + # ELASTICSEARCH_URL=https://devnet-index.multiversx.com |
| 7 | + # GATEWAY_URL=https://devnet-gateway.multiversx.com |
| 8 | + # RABBITMQ_URL=amqp://127.0.0.1:5672 |
| 9 | + # PROVIDERS_URL=https://devnet-delegation-api.multiversx.com/providers |
| 10 | + # DELEGATION_URL=https://devnet-delegation-api.multiversx.com |
| 11 | + # SOCKET_URL=devnet-socket-api.multiversx.com |
| 12 | + # NODESFETCH_URL= https://devnet-api.multiversx.com |
| 13 | + # TOKENSFETCH_URL= https://devnet-api.multiversx.com |
| 14 | + # PROVIDERSFETCH_URL= https://devnet-api.multiversx.com |
| 15 | + # DATAAPI_URL=https://devnet-data-api.multiversx.com |
| 16 | + # EXCHANGE_URL=https://devnet-graph.xexchange.com/graphql |
| 17 | + # MARKETPLACE_URL=https://devnet-nfts-graph.multiversx.com/graphql |
| 18 | + # ASSETSFETCH_URL=https://tools.multiversx.com/assets-cdn |
| 19 | + # PLACEHOLDER_DAPP_id=devnet |
| 20 | + # PLACEHOLDER_DAPP_name=Devnet |
| 21 | + # PLACEHOLDER_DAPP_egldLabel=xEGLD |
| 22 | + # PLACEHOLDER_DAPP_walletAddress=https://devnet-wallet.multiversx.com |
| 23 | + # PLACEHOLDER_DAPP_apiAddress=https://devnet-api.multiversx.com |
| 24 | + # PLACEHOLDER_DAPP_explorerAddress=http://devnet-explorer.multiversx.com |
| 25 | + # PLACEHOLDER_DAPP_chainId=D |
44 | 26 |
|
| 27 | +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" |
| 28 | + |
| 29 | +replace_placeholder() { |
| 30 | + local var_name=$1 |
| 31 | + local var_value=$2 |
| 32 | + |
| 33 | + case $var_name in |
| 34 | + PLACEHOLDER_DAPP*) |
| 35 | + echo "Var ${var_name} defined, replacing ${var_value} in /app/config/dapp.config.placeholder.json" |
| 36 | + sed -i "s|${var_name}|${var_value}|g" /app/config/dapp.config.placeholder.json |
| 37 | + ;; |
| 38 | + *) |
| 39 | + echo "Var ${var_name} defined, replacing ${var_value} in /app/dist/config/config.yaml" |
| 40 | + sed -i "s|${var_name}|${var_value}|g" /app/dist/config/config.yaml |
| 41 | + ;; |
| 42 | + esac |
| 43 | + |
| 44 | +} |
| 45 | + |
| 46 | +# Loop through each environment variable |
| 47 | +for entry in $env_vars_with_defaults; do |
| 48 | + # Split the entry into name and value |
| 49 | + var_name=$(echo $entry | cut -d= -f1) |
| 50 | + default_value=$(echo $entry | cut -d= -f2) |
| 51 | + |
| 52 | + # Use the environment variable value if defined; otherwise, use the default |
| 53 | + eval "value=\${$var_name:-$default_value}" |
| 54 | + |
| 55 | + cp ./config/config.placeholder.yaml /app/dist/config/config.yaml |
| 56 | + if [ $? -eq 0 ]; then |
| 57 | + echo "Config file copied successfully from config/config.placeholder.yaml /app/dist/config/config.yaml" |
| 58 | + fi |
| 59 | + |
| 60 | + # Execute the function with the variable name and value |
| 61 | + replace_placeholder "$var_name" "$value" |
| 62 | + |
| 63 | +done |
45 | 64 |
|
46 | 65 | exec /usr/local/bin/node dist/src/main.js |
0 commit comments