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.

prep_bubble_jar 4.2 KiB

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