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.
 
 
 
 

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