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.
 
 
 
 

221 lines
6.6 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. # Run bubble launcher in a docker container. Works on Linux or Mac OS.
  6. #
  7. # Intended to be "run from anywhere" like this:
  8. #
  9. # /bin/bash -c "$(curl -sL https://git.bubblev.org/bubblev/bubble/raw/branch/master/launcher)"
  10. #
  11. # This command will:
  12. # - install docker if no "docker" command found
  13. # - pull bubble launcher docker image
  14. # - run bubble launcher docker image
  15. #
  16. # You'll be asked for an email address to associate with any LetsEncrypt certificates that will be created.
  17. #
  18. # If you want to run this unattended, set the LETSENCRYPT_EMAIL environment variable.
  19. #
  20. # Upon successful startup, the bubble launcher will be listening on port 8090
  21. # If you'd prefer to use a different port, set the BUBBLE_PORT environment variable.
  22. #
  23. # Open http://127.0.0.1:8090/ (or http://127.0.0.1:BUBBLE_PORT/) in a web browser
  24. # to continue with activation.
  25. #
  26. # By default this will grab the latest Bubble release. If you want a specific version,
  27. # set the BUBBLE_TAG environment variable to the release tag you'd like to run,
  28. # usually a semantic version number. For example: BUBBLE_TAG=1.5.2
  29. #
  30. function die() {
  31. echo 1>&2 "
  32. ***** ${1}
  33. "
  34. exit 1
  35. }
  36. function get_bubble_tag() {
  37. if [[ -n "${BUBBLE_TAG}" ]] ; then
  38. VERSION="${BUBBLE_TAG}"
  39. else
  40. BUBBLE_RELEASE_URL="https://jenkins.bubblev.org/public/releases/bubble/latest.txt"
  41. VERSION="$(curl -s ${BUBBLE_RELEASE_URL} | awk -F '_' '{print $2}' | awk -F '.' '{print $1"."$2"."$3}')"
  42. if [[ -z "${VERSION}" ]]; then
  43. die "Error determining version from URL: ${BUBBLE_RELEASE_URL}"
  44. fi
  45. fi
  46. echo -n "getbubble/launcher:${VERSION}"
  47. }
  48. function ensure_docker_group() {
  49. CALLER="$(whoami)"
  50. if [[ "${CALLER}" != "root" && "$(sudo id -Gn "${CALLER}" | grep -c docker | tr -d ' ')" -eq 0 ]]; then
  51. echo "Adding user ${CALLER} to docker group ..."
  52. sudo usermod -a -G docker "${CALLER}"
  53. fi
  54. }
  55. function setup_docker_debian() {
  56. # Ensure apt is up to date
  57. sudo apt update -y
  58. # Remove obsolete packages
  59. sudo apt-get remove docker docker-engine docker.io containerd runc
  60. # Ensure apt can install packages over https
  61. sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  62. # Install docker GPG key
  63. curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
  64. # Add docker repo
  65. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
  66. # Refresh apt after adding repo
  67. sudo apt update -y
  68. # Install docker
  69. sudo apt install -y docker-ce docker-ce-cli containerd.io
  70. ensure_docker_group
  71. }
  72. function setup_docker_ubuntu() {
  73. # Ensure apt is up to date
  74. sudo apt update -y
  75. # Remove obsolete packages
  76. sudo apt-get remove docker docker-engine docker.io containerd runc
  77. # Ensure apt can install packages over https
  78. sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  79. # Install docker GPG key
  80. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  81. # Add docker repo
  82. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  83. # Refresh apt after adding repo
  84. sudo apt update -y
  85. # Install docker
  86. sudo apt install -y docker-ce
  87. ensure_docker_group
  88. }
  89. function setup_docker_generic_linux() {
  90. curl -fsSL https://get.docker.com | sudo sh -
  91. }
  92. function setup_docker_linux() {
  93. DISTRO="$(cat /etc/os-release | grep "^NAME" | awk -F '=' '{print $2}' | tr -d '"')"
  94. if [[ $(echo -n ${DISTRO} | grep -c Debian | tr -d ' ') -gt 0 ]]; then
  95. setup_docker_debian
  96. elif [[ $(echo -n ${DISTRO} | grep -c Ubuntu | tr -d ' ') -gt 0 ]]; then
  97. setup_docker_ubuntu
  98. else
  99. setup_docker_generic_linux
  100. fi
  101. }
  102. function setup_docker_macosx() {
  103. if [[ -z "$(which brew)" ]]; then
  104. die "Homebrew not installed (brew command not found). Install homebrew by running:
  105. /bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\"
  106. "
  107. fi
  108. brew install docker docker-machine || die "Error installing docker and docker-machine"
  109. brew cask install virtualbox || die "Error installing virtualbox (check Security Settings)"
  110. docker-machine create --driver virtualbox default
  111. }
  112. function setup_docker() {
  113. echo "Installing docker via sudo ..."
  114. if [[ $(whoami) != "root" ]]; then
  115. echo "Note: you may need to enter your password (for Linux user $(whoami)) to enable sudo commands"
  116. fi
  117. if [[ "${PLATFORM}" == "Linux" ]]; then
  118. setup_docker_linux
  119. elif [[ "${PLATFORM}" == "Darwin" ]]; then
  120. setup_docker_macosx
  121. eval "$(docker-machine env default)"
  122. docker-machine start default
  123. else
  124. die "Don't know how to install docker on ${PLATFORM}"
  125. fi
  126. }
  127. function run_launcher() {
  128. PLATFORM="$(uname -s)"
  129. if [[ -z "${PLATFORM}" ]]; then
  130. die "'uname -s' returned empty string!"
  131. fi
  132. if [[ -z "$(which docker)" ]]; then
  133. setup_docker
  134. if [[ -z "$(which docker)" ]]; then
  135. die "***** Error installing docker
  136. Install docker manually from https://docs.docker.com/engine/install/
  137. Then re-run this script.
  138. "
  139. fi
  140. fi
  141. if [[ "${PLATFORM}" == "Linux" ]]; then
  142. ensure_docker_group
  143. fi
  144. # Determine bubble docker tag
  145. DOCKER_TAG=$(get_bubble_tag)
  146. # Determine OS user
  147. CALLER="$(whoami)"
  148. # Pull bubble docker image
  149. if [[ "${CALLER}" == "root" ]] ; then
  150. docker pull "${DOCKER_TAG}" || die "Error pulling docker image: ${DOCKER_TAG}"
  151. else
  152. docker pull "${DOCKER_TAG}" || \
  153. echo "***** error running 'docker pull' as ${CALLER}, trying via sudo ..." && \
  154. sudo su - "${CALLER}" -c "docker pull ${DOCKER_TAG}" || die "Error pulling docker image: ${DOCKER_TAG}"
  155. fi
  156. # Determine email for LetsEncrypt certs
  157. if [[ -z "${LETSENCRYPT_EMAIL}" ]]; then
  158. echo
  159. echo -n "Email address for LetsEncrypt certificates: "
  160. read -r LETSENCRYPT_EMAIL
  161. fi
  162. # Determine port
  163. if [[ -z "${BUBBLE_PORT}" ]] ; then
  164. BUBBLE_PORT=8090
  165. fi
  166. # Run bubble docker image
  167. if [[ "${CALLER}" == "root" ]] ; then
  168. docker run \
  169. -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
  170. -e LETSENCRYPT_EMAIL="${LETSENCRYPT_EMAIL}" \
  171. -t "${DOCKER_TAG}"
  172. else
  173. docker run \
  174. -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
  175. -e LETSENCRYPT_EMAIL="${LETSENCRYPT_EMAIL}" \
  176. -t "${DOCKER_TAG}" || \
  177. echo "***** error running 'docker run' as ${CALLER}, trying via sudo ..." && \
  178. sudo su - "${CALLER}" -c "docker run \
  179. -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
  180. -e LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL} \
  181. -t ${DOCKER_TAG}"
  182. fi
  183. }
  184. run_launcher