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.
 
 
 
 

87 line
3.5 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. #
  14. # version : version to use, default is read from bubble-server/src/main/resources/META-INF/bubble/bubble.properties
  15. #
  16. # The docker tag used will be getbubble/launcher:version
  17. #
  18. # We build two images, a full one and a slim one.
  19. # The full image is larger (will take longer to download), but will startup faster.
  20. # The slim image is smaller (will be faster to download), but will take longer to start up.
  21. #
  22. # The full image has the Bubble jar, updated packages and packer pre-installed.
  23. # The slim image has default packages and installs packer and the Bubble jar when it first runs.
  24. #
  25. # If you want to change the "getbubble/launcher" part of the Docker tag, set the BUBBLE_DOCKER_REPO
  26. # environment variable in your shell environment.
  27. #
  28. # When using the 'run' mode, you'll be asked for an email address to associate with any LetsEncrypt
  29. # certificates that will be created.
  30. #
  31. # If you want to run this unattended, set the LETSENCRYPT_EMAIL environment variable
  32. # in your ~/.bubble.env file or in your shell environment.
  33. #
  34. SCRIPT="${0}"
  35. SCRIPT_DIR="$(cd "$(dirname "${SCRIPT}")" && pwd)"
  36. . "${SCRIPT_DIR}"/bubble_common
  37. BUBBLE_DIR="$(cd "${SCRIPT_DIR}"/.. && pwd)"
  38. MODE=${1:?no mode specified, use build or run}
  39. META_FILE="${BUBBLE_DIR}/bubble-server/src/main/resources/META-INF/bubble/bubble.properties"
  40. VERSION="${2:-$(cat "${META_FILE}" | grep bubble.version | awk -F '=' '{print $2}' | awk -F ' ' '{print $NF}' | awk '{$1=$1};1')}"
  41. if [[ -z "${VERSION}" ]] ; then
  42. die "Error determining version from: ${META_FILE}"
  43. fi
  44. DOCKER_REPO="getbubble"
  45. if [[ -n "${BUBBLE_DOCKER_REPO}" ]] ; then
  46. DOCKER_REPO="${BUBBLE_DOCKER_REPO}"
  47. fi
  48. BUBBLE_TAG="${DOCKER_REPO}/launcher:${VERSION}"
  49. BUBBLE_SLIM_TAG="${DOCKER_REPO}/slim-launcher:${VERSION}"
  50. BUBBLE_ENV="${HOME}/.bubble.env"
  51. if [[ "${MODE}" == "build" ]] ; then
  52. if [[ $(find bubble-server/target -type f -name "bubble-server-*-prod.jar" | wc -l | tr -d ' ') -eq 0 ]] ; then
  53. die "No bubble jar found in $(pwd)/bubble-server/target"
  54. fi
  55. docker build --no-cache -t "${BUBBLE_TAG}" . || die "Error building docker image"
  56. docker build --no-cache -f Dockerfile.slim -t "${BUBBLE_SLIM_TAG}" . || die "Error building slim docker image"
  57. elif [[ "${MODE}" == "run" ]] ; then
  58. if [[ $(cat "${BUBBLE_ENV}" | grep -v '^#' | grep -c LETSENCRYPT_EMAIL) -eq 0 ]] ; then
  59. if [[ -z "${LETSENCRYPT_EMAIL}" ]] ; then
  60. echo ; echo -n "Email address for LetsEncrypt certificates: "
  61. read -r LETSENCRYPT_EMAIL
  62. fi
  63. echo "
  64. export LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL}
  65. " >> "${BUBBLE_ENV}"
  66. fi
  67. if [[ -n "${BUBBLE_RUN_SLIM}" && "${BUBBLE_RUN_SLIM}" == "true" ]] ; then
  68. RUN_TAG="${BUBBLE_SLIM_TAG}"
  69. else
  70. RUN_TAG="${BUBBLE_TAG}"
  71. fi
  72. docker run --env-file <(cat "${BUBBLE_ENV}" | sed -e 's/export //' | tr -d '"' | tr -d "'") -p 8090:8090 -t "${RUN_TAG}" || die "Error running docker container"
  73. elif [[ "${MODE}" == "push" ]] ; then
  74. docker push "${BUBBLE_TAG}" || die "Error pushing docker image"
  75. docker push "${BUBBLE_SLIM_TAG}" || die "Error pushing slim docker image"
  76. else
  77. die "Invalid mode (expected build or run): ${MODE}"
  78. fi