The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

129 line
5.0 KiB

  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
  4. #
  5. #
  6. # Prepares the bubble.jar file for active usage.
  7. #
  8. # 1. Update role JSON in bubble-server/src/main/resources/ansible/default_roles.json
  9. # Inserts "tgzB64" value with file://path to tarball
  10. #
  11. # 2. Copy scripts to bubble-server/target/classes/scripts
  12. #
  13. # 3. If the environment variable INSTALL_WEB is equal to "web", also build and install the bubble-web
  14. # site to bubble-server/target/classes/site
  15. #
  16. # Usage:
  17. #
  18. # prep_bubble_jar
  19. #
  20. # Environment variables:
  21. #
  22. # INSTALL_WEB : if this is equal to 'web' then the frontend will be built and included in the jar
  23. # DEBUG_BUILD : if this is equal to 'debug' then nothing will be done, the jar will be left as-is
  24. #
  25. SCRIPT="${0}"
  26. SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd)
  27. . ${SCRIPT_DIR}/bubble_common
  28. if [[ ! -z "${DEBUG_BUILD}" && "${DEBUG_BUILD}" == "debug" ]] ; then
  29. echo "DEBUG_BUILD is set, not doing anything further"
  30. exit 0
  31. fi
  32. BUBBLE_SERVER="$(cd "${SCRIPT_DIR}/../bubble-server" && pwd)"
  33. CLASSES_DIR="${BUBBLE_SERVER}/target/classes"
  34. DEFAULT_ROLES_RELATIVE="ansible/default_roles.json"
  35. DEFAULT_ROLES="${CLASSES_DIR}/${DEFAULT_ROLES_RELATIVE}"
  36. if [[ ! -f ${DEFAULT_ROLES} ]] ; then
  37. die "default roles file not found: ${DEFAULT_ROLES}"
  38. fi
  39. if [[ -z "${LOCALSTORAGE_BASE_DIR}" ]] ; then
  40. for f in "${HOME}/bubble/current/bubble.env" "${HOME}/.bubble.env" ; do
  41. if [[ -f "${f}" ]] ; then
  42. LOCALSTORAGE_BASE_DIR=$(cat ${f} | grep -v '^#' | grep LOCALSTORAGE_BASE_DIR | awk -F '=' '{print $2}' | tr -d ' ')
  43. break
  44. fi
  45. done
  46. fi
  47. if [[ -z "${LOCALSTORAGE_BASE_DIR}" ]] ; then
  48. echo "Warning: LOCALSTORAGE_BASE_DIR env var not defined and no bubble.env found, using ${HOME}/.bubble_local_storage"
  49. LOCALSTORAGE_BASE_DIR="${HOME}/.bubble_local_storage"
  50. fi
  51. if [[ -z "${BUBBLE_JAR}" ]] ; then
  52. die "bubble jar not found: ${BUBBLE_JAR}"
  53. fi
  54. ROLES_DIR="$(cd "${SCRIPT_DIR}/../automation/roles" && pwd)"
  55. if [[ ! -d ${ROLES_DIR} ]] ; then
  56. die "automation/roles dir not found: ${ROLES_DIR}"
  57. fi
  58. LOCAL_NET_ID="$("${SCRIPT_DIR}/bconst" bubble.ApiConstants.ROOT_NETWORK_UUID 2> /dev/null)"
  59. if [[ -z "${LOCAL_NET_ID}" ]] ; then
  60. # try to read from source file
  61. LOCAL_NET_ID="$(cat "${BUBBLE_SERVER}/src/main/java/bubble/ApiConstants.java" | grep -v '//' | egrep '\s+String\s+ROOT_NETWORK_UUID' | awk -F '"' '{print $2}')"
  62. if [[ -z "${LOCAL_NET_ID}" ]] ; then
  63. die "ROOT_NETWORK_UUID could not be read from ApiConstants"
  64. fi
  65. fi
  66. echo "lbs = ${LOCALSTORAGE_BASE_DIR}"
  67. UPDATED="$(mktemp /tmp/default_roles.XXXXXXX.json)"
  68. cd ${ROLES_DIR}
  69. echo "[" > "${UPDATED}"
  70. for role in $(ls -1) ; do
  71. echo "Processing role: ${role}"
  72. ROLE_JSON="${role}/files/bubble_role.json"
  73. if [[ ! -f "${ROLE_JSON}" ]] ; then
  74. die "Json file not found for role ${role}: ${ROLE_JSON}"
  75. fi
  76. if [[ $(cat ${UPDATED} | wc -c) -gt 2 ]] ; then
  77. echo "," >> ${UPDATED}
  78. fi
  79. role_name="$(cat "${ROLE_JSON}" | jq -r .name)"
  80. role_path="automation/roles/${role_name}.tgz"
  81. TGZ_PATH="${LOCALSTORAGE_BASE_DIR}/${role_path}"
  82. mkdir -p $(dirname ${TGZ_PATH}) || die "Error creating parent dir for ${TGZ_PATH}"
  83. tar czf ${TGZ_PATH} ${role}
  84. cat ${ROLE_JSON} | jq --arg tgzB64 "storage://LocalStorage/${role_path}" '. + {tgzB64: $tgzB64}' >> ${UPDATED}
  85. echo "------------------------------"
  86. echo "Generated role JSON: ${role}"
  87. echo "------------------------------"
  88. done
  89. echo "]" >> ${UPDATED}
  90. jq . < ${UPDATED} > ${DEFAULT_ROLES} || die "Error writing ${DEFAULT_ROLES}, maybe some problems with ${UPDATED} ?"
  91. echo "------------------------------------------------------------"
  92. cat "${UPDATED}"
  93. echo "------------------------------------------------------------"
  94. cd ${LOCALSTORAGE_BASE_DIR} && jar uvf ${BUBBLE_JAR} automation || die "Error updating ${BUBBLE_JAR} with default role archives"
  95. mkdir -p ${LOCALSTORAGE_BASE_DIR}/${LOCAL_NET_ID} && cp -R ${LOCALSTORAGE_BASE_DIR}/automation ${LOCALSTORAGE_BASE_DIR}/${LOCAL_NET_ID}/ || die "Error creating/copying network storage dir: ${LOCALSTORAGE_BASE_DIR}/${LOCAL_NET_ID}"
  96. mkdir -p ${CLASSES_DIR}/scripts
  97. for script in $(cat ${BUBBLE_SERVER}/src/main/resources/ansible/bubble_scripts.txt) ; do
  98. cp ${SCRIPT_DIR}/${script} ${CLASSES_DIR}/scripts || die "Error copying ${SCRIPT_DIR}/${script} -> ${CLASSES_DIR}/scripts"
  99. done
  100. cd ${CLASSES_DIR} && jar uvf ${BUBBLE_JAR} scripts ${DEFAULT_ROLES_RELATIVE} || die "Error updating ${BUBBLE_JAR} with scripts"
  101. echo "Updated $(ls -1 ${ROLES_DIR} | wc -l) roles in ${DEFAULT_ROLES}"
  102. rm -f "${UPDATED}"
  103. if [[ ! -z "${INSTALL_WEB}" && "${INSTALL_WEB}" == "web" ]] ; then
  104. mkdir -p ${CLASSES_DIR}/site
  105. BUBBLE_WEB="$(cd "${SCRIPT_DIR}/../bubble-web" && pwd)"
  106. cd ${BUBBLE_WEB} && npm install && webpack || die "Error building bubble-web"
  107. cp -R ${BUBBLE_WEB}/dist/* ${CLASSES_DIR}/site/ || die "Error copying ${BUBBLE_WEB}/dist/* -> ${CLASSES_DIR}/site/"
  108. cd ${CLASSES_DIR} && jar uvf ${BUBBLE_JAR} site || die "Error updating ${BUBBLE_JAR} with site"
  109. echo "Installed bubble-web to ${CLASSES_DIR}/site/"
  110. fi