node-utils.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env bash
  2. # style reference https://google.github.io/styleguide/shellguide.html
  3. set -e
  4. SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
  5. cd $SCRIPT_PATH
  6. # Log only to stderr
  7. # Only output from this script should be the container id of the node at the very end
  8. # Location that will be mounted as the /data volume in containers
  9. # This is where the initial members and balances files and generated chainspec files will be located.
  10. export DATA_PATH=${DATA_PATH:=$(pwd)/data}
  11. mkdir -p ${DATA_PATH}
  12. # Initial account balance for sudo account
  13. SUDO_INITIAL_BALANCE=${SUDO_INITIAL_BALANCE:=100000000}
  14. SUDO_ACCOUNT_URI=${SUDO_ACCOUNT_URI:="//Alice"}
  15. SUDO_ACCOUNT=$(docker run --rm --pull=always docker.io/parity/subkey:2.0.1 inspect ${SUDO_ACCOUNT_URI} --output-type json | jq .ss58Address -r)
  16. # Source of funds for all new accounts that are created in the tests.
  17. TREASURY_INITIAL_BALANCE=${TREASURY_INITIAL_BALANCE:=100000000}
  18. TREASURY_ACCOUNT_URI=${TREASURY_ACCOUNT_URI:=$SUDO_ACCOUNT_URI}
  19. TREASURY_ACCOUNT=$(docker run --rm --pull=always docker.io/parity/subkey:2.0.1 inspect ${TREASURY_ACCOUNT_URI} --output-type json | jq .ss58Address -r)
  20. >&2 echo "sudo account from suri: ${SUDO_ACCOUNT}"
  21. >&2 echo "treasury account from suri: ${TREASURY_ACCOUNT}"
  22. # Prevent joystream cli from prompting
  23. export AUTO_CONFIRM=true
  24. export JOYSTREAM_NODE_TAG=${RUNTIME_TAG}
  25. #######################################
  26. # create initial-balances.json & initial-members.json files
  27. # Globals:
  28. # SUDO_INITIAL_BALANCES
  29. # SUDO_ACCOUNT
  30. # TREASURY_ACCOUNT
  31. # TREASURY_INITIAL_BALANCE
  32. # DATA_PATH
  33. # Arguments:
  34. # None
  35. #######################################
  36. function create_initial_config {
  37. echo "{
  38. \"balances\":[
  39. [\"$SUDO_ACCOUNT\", $SUDO_INITIAL_BALANCE],
  40. [\"$TREASURY_ACCOUNT\", $TREASURY_INITIAL_BALANCE]
  41. ]
  42. }" > ${DATA_PATH}/initial-balances.json
  43. # Remember if there are initial members at genesis query-node needs to be bootstrapped
  44. # or any events processed for this member will cause processor to fail.
  45. if [ "${MAKE_SUDO_MEMBER}" == true ]
  46. then
  47. echo "
  48. [{
  49. \"member_id\":0,
  50. \"root_account\":\"$SUDO_ACCOUNT\",
  51. \"controller_account\":\"$SUDO_ACCOUNT\",
  52. \"handle\":\"sudosudo\",
  53. \"avatar_uri\":\"https://sudo.com/avatar.png\",
  54. \"about\":\"Sudo\",
  55. \"registered_at_time\":0
  56. }]
  57. " > ${DATA_PATH}/initial-members.json
  58. else
  59. echo "[]" > ${DATA_PATH}/initial-members.json
  60. fi
  61. }
  62. #######################################
  63. # create human-readable chainspec file
  64. # Globals:
  65. # SUDO_ACCOUNT
  66. # DATA_PATH
  67. # Arguments:
  68. # None
  69. #######################################
  70. function create_chainspec_file {
  71. # Create a chain spec file
  72. docker run --rm -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder \
  73. joystream/node:${RUNTIME_TAG} \
  74. new \
  75. --authority-seeds Alice \
  76. --sudo-account ${SUDO_ACCOUNT} \
  77. --deployment dev \
  78. --chain-spec-path /data/chain-spec.json \
  79. --initial-balances-path /data/initial-balances.json \
  80. --initial-members-path /data/initial-members.json
  81. }
  82. #######################################
  83. # convert human-readable chainspec into
  84. # raw chainspec
  85. # Globals:
  86. # DATA_PATH
  87. # Arguments:
  88. # None
  89. #######################################
  90. function convert_chainspec {
  91. docker run --rm -v ${DATA_PATH}:/data joystream/node:${RUNTIME_TAG} build-spec \
  92. --raw --disable-default-bootnode \
  93. --chain /data/chain-spec.json > ${DATA_PATH}/chain-spec-raw.json
  94. }
  95. #######################################
  96. # cleanup docker logs and shuts down container
  97. # Globals:
  98. # CONTAINER_ID
  99. # Arguments:
  100. # None
  101. #######################################
  102. function cleanup() {
  103. # if [[ -z $CONTAINER_ID ]]; then
  104. # docker logs ${CONTAINER_ID} --tail 15
  105. # fi
  106. docker-compose -f ../../docker-compose.yml down -v
  107. find ./assets/ -name '[A-Z0-9]*__rejectedContent.json' -delete
  108. rm -rf $DATA_PATH
  109. }
  110. #######################################
  111. # Start a chain with generated chain spec
  112. # Globals:
  113. # DATA_PATH
  114. # Arguments:
  115. # None
  116. #######################################
  117. function start_node {
  118. docker-compose -f ../../docker-compose.yml run \
  119. -d -v ${DATA_PATH}:/spec --name "${JOYSTREAM_NODE_TAG}" \
  120. -p 9944:9944 -p 9933:9933 joystream-node \
  121. --alice --validator --unsafe-ws-external --unsafe-rpc-external \
  122. --rpc-methods Unsafe --rpc-cors=all -l runtime \
  123. --chain /spec/chain-spec-raw.json \
  124. --base-path /data
  125. }