The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

153 řádky
5.8 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. # Build, run or push a docker container for a Bubble launcher. Intended for developer use.
  6. #
  7. # bdocker [mode] [version]
  8. #
  9. # mode : build, run or push
  10. # build - build the docker images
  11. # run - run a docker image. set the BUBBLE_RUN_SLIM env var to `true` to run the slim image.
  12. # push - push images docker hub
  13. # term - open a bash terminal on a running container
  14. # clean - remove containers and images related to the version
  15. #
  16. # version : version to use, default is read from bubble-server/src/main/resources/META-INF/bubble/bubble.properties
  17. #
  18. # The docker tag used will be getbubble/launcher:version
  19. #
  20. # We build two images, a full one and a slim one.
  21. # The full image is larger (will take longer to download), but will startup faster.
  22. # The slim image is smaller (will be faster to download), but will take longer to start up.
  23. #
  24. # The full image has the Bubble jar, updated packages and packer pre-installed.
  25. # The slim image has default packages and installs packer and the Bubble jar when it first runs.
  26. #
  27. # If you want to change the "getbubble/launcher" part of the Docker tag, set the BUBBLE_DOCKER_REPO
  28. # environment variable in your shell environment.
  29. #
  30. # When using the 'run' mode, you'll be asked for an email address to associate with any LetsEncrypt
  31. # certificates that will be created.
  32. #
  33. # Upon successful startup, the bubble launcher will be listening on port 8090
  34. # If you'd prefer to use a different port, set the BUBBLE_PORT environment variable.
  35. #
  36. # If you want to run this unattended, set the LETSENCRYPT_EMAIL environment variable
  37. # in your ~/.bubble.env file or in your shell environment.
  38. #
  39. # By default, this does not use the docker cache. If you want to use the cache,
  40. # set the BUBBLE_DOCKER_CACHE environment variable to any value.
  41. #
  42. SCRIPT="${0}"
  43. SCRIPT_DIR="$(cd "$(dirname "${SCRIPT}")" && pwd)"
  44. . "${SCRIPT_DIR}"/bubble_common
  45. BUBBLE_DIR="$(cd "${SCRIPT_DIR}"/.. && pwd)"
  46. MODE=${1:?no mode specified, use: build, run, term, push or clean}
  47. META_FILE="${BUBBLE_DIR}/bubble-server/src/main/resources/META-INF/bubble/bubble.properties"
  48. VERSION="${2:-$(cat "${META_FILE}" | grep bubble.version | awk -F '=' '{print $2}' | awk -F ' ' '{print $NF}' | awk '{$1=$1};1')}"
  49. if [[ -z "${VERSION}" ]] ; then
  50. die "Error determining version from: ${META_FILE}"
  51. fi
  52. DOCKER_REPO="getbubble"
  53. if [[ -n "${BUBBLE_DOCKER_REPO}" ]] ; then
  54. DOCKER_REPO="${BUBBLE_DOCKER_REPO}"
  55. fi
  56. REPO_LAUNCHER="${DOCKER_REPO}/launcher"
  57. BUBBLE_TAG="${REPO_LAUNCHER}:${VERSION}"
  58. REPO_SLIM_LAUNCHER="${DOCKER_REPO}/slim-launcher"
  59. BUBBLE_SLIM_TAG="${REPO_SLIM_LAUNCHER}:${VERSION}"
  60. BUBBLE_ENV="${HOME}/.bubble.env"
  61. CACHE="--no-cache"
  62. if [[ -n "${BUBBLE_DOCKER_CACHE}" ]] ; then
  63. CACHE=""
  64. fi
  65. EXPOSE=""
  66. if [[ -z "${BUBBLE_PORT}" ]] ; then
  67. BUBBLE_PORT=8090
  68. else
  69. EXPOSE="--expose ${BUBBLE_PORT}"
  70. fi
  71. if [[ "${MODE}" == "build" ]] ; then
  72. if [[ $(find bubble-server/target -type f -name "bubble-server-*-prod.jar" | wc -l | tr -d ' ') -eq 0 ]] ; then
  73. die "No bubble jar found in $(pwd)/bubble-server/target"
  74. fi
  75. docker build ${CACHE} -t "${BUBBLE_TAG}" . || die "Error building docker image"
  76. docker build ${CACHE} -f Dockerfile.slim -t "${BUBBLE_SLIM_TAG}" . || die "Error building slim docker image"
  77. elif [[ "${MODE}" == "run" ]] ; then
  78. # Copy existing env if found
  79. ENV_FILE=$(mktemp /tmp/.bubble.env.XXXXXXX)
  80. if [[ -z "${BUBBLE_ENV}" ]] ; then
  81. BUBBLE_ENV="${HOME}/.bubble.env"
  82. fi
  83. if [[ -f "${BUBBLE_ENV}" ]] ; then
  84. cat "${BUBBLE_ENV}" > "${ENV_FILE}"
  85. fi
  86. # Define API port
  87. echo "
  88. export BUBBLE_SERVER_PORT=${BUBBLE_PORT}
  89. export PUBLIC_BASE_URI=http://127.0.0.1:${BUBBLE_PORT}
  90. " >> "${ENV_FILE}"
  91. # Define LetsEncrypt email, from env var or stdin
  92. if [[ $(cat "${BUBBLE_ENV}" | grep -v '^#' | grep -c LETSENCRYPT_EMAIL) -eq 0 ]] ; then
  93. if [[ -z "${LETSENCRYPT_EMAIL}" ]] ; then
  94. echo ; echo -n "Email address for LetsEncrypt certificates: "
  95. read -r LETSENCRYPT_EMAIL
  96. fi
  97. echo "
  98. export LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL}" >> "${ENV_FILE}"
  99. fi
  100. if [[ -n "${BUBBLE_RUN_SLIM}" && "${BUBBLE_RUN_SLIM}" == "true" ]] ; then
  101. RUN_TAG="${BUBBLE_SLIM_TAG}"
  102. else
  103. RUN_TAG="${BUBBLE_TAG}"
  104. fi
  105. DOCKER_ENV_FILE=$(mktemp /tmp/.docker.env.XXXXXX)
  106. cat "${ENV_FILE}" | sed -e 's/export //' | tr -d '"' | tr -d "'" > "${DOCKER_ENV_FILE}"
  107. docker run ${EXPOSE} --env-file "${DOCKER_ENV_FILE}" -p ${BUBBLE_PORT}:${BUBBLE_PORT} -t "${RUN_TAG}"
  108. rm -f "${ENV_FILE}" "${DOCKER_ENV_FILE}"
  109. elif [[ "${MODE}" == "push" ]] ; then
  110. docker push "${BUBBLE_TAG}" || die "Error pushing docker image"
  111. docker push "${BUBBLE_SLIM_TAG}" || die "Error pushing slim docker image"
  112. elif [[ "${MODE}" == "term" ]] ; then
  113. # Expect only one container running that matches BUBBLE_TAG
  114. CONTAINER_CT="$(docker container ls | grep -c "${BUBBLE_TAG}" | tr -d ' ')"
  115. if [[ -z "${CONTAINER_CT}" || "${CONTAINER_CT}" == "0" ]] ; then
  116. die "No docker container found with tag ${BUBBLE_TAG}"
  117. fi
  118. if [[ ${CONTAINER_CT} -gt 1 ]] ; then
  119. die "Multiple docker containers found with tag ${BUBBLE_TAG}"
  120. fi
  121. # Run bash in that container
  122. exec docker exec -it "$(docker container ls | grep "${BUBBLE_TAG}" | awk '{print $1}')" /bin/bash
  123. elif [[ "${MODE}" == "clean" ]] ; then
  124. # Remove containers
  125. docker container ls | grep "${BUBBLE_TAG}" | awk '{print $1}' | xargs docker container rm -f
  126. docker container ls | grep "${BUBBLE_SLIM_TAG}" | awk '{print $1}' | xargs docker container rm -f
  127. # Remove images
  128. docker image ls | grep "${REPO_LAUNCHER}" | grep "${VERSION}" | awk '{print $3}' | xargs docker image rm -f
  129. docker image ls | grep "${REPO_SLIM_LAUNCHER}" | grep "${VERSION}" | awk '{print $3}' | xargs docker image rm -f
  130. else
  131. die "$("${0}" --help)
  132. ***** invalid mode: ${MODE}"
  133. fi