The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

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