The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

224 lines
6.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. # 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. if [[ -z "$(which docker)" ]]; then
  136. setup_docker
  137. if [[ -z "$(which docker)" ]]; then
  138. die "***** Error installing docker
  139. Install docker manually from https://docs.docker.com/engine/install/
  140. Then re-run this script.
  141. "
  142. fi
  143. fi
  144. if [[ "${PLATFORM}" == "Linux" ]]; then
  145. ensure_docker_group
  146. fi
  147. # Determine bubble docker tag
  148. DOCKER_TAG=$(get_bubble_tag)
  149. # Determine OS user
  150. CALLER="$(whoami)"
  151. # Pull bubble docker image
  152. if [[ "${CALLER}" == "root" ]] ; then
  153. docker pull "${DOCKER_TAG}" || die "Error pulling docker image: ${DOCKER_TAG}"
  154. else
  155. docker pull "${DOCKER_TAG}" || \
  156. echo "***** error running 'docker pull' as ${CALLER}, trying via sudo ..." && \
  157. sudo su - "${CALLER}" -c "docker pull ${DOCKER_TAG}" || die "Error pulling docker image: ${DOCKER_TAG}"
  158. fi
  159. # Determine email for LetsEncrypt certs
  160. if [[ -z "${LETSENCRYPT_EMAIL}" ]]; then
  161. echo
  162. echo -n "Email address for LetsEncrypt certificates: "
  163. read -r LETSENCRYPT_EMAIL
  164. fi
  165. # Determine port
  166. if [[ -z "${BUBBLE_PORT}" ]] ; then
  167. BUBBLE_PORT=8090
  168. fi
  169. # Run bubble docker image
  170. if [[ "${CALLER}" == "root" ]] ; then
  171. docker run \
  172. -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
  173. -e LETSENCRYPT_EMAIL="${LETSENCRYPT_EMAIL}" \
  174. -t "${DOCKER_TAG}"
  175. else
  176. docker run \
  177. -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
  178. -e LETSENCRYPT_EMAIL="${LETSENCRYPT_EMAIL}" \
  179. -t "${DOCKER_TAG}" || \
  180. echo "***** error running 'docker run' as ${CALLER}, trying via sudo ..." && \
  181. sudo su - "${CALLER}" -c "docker run \
  182. -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
  183. -e LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL} \
  184. -t ${DOCKER_TAG}"
  185. fi
  186. }
  187. run_launcher