|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #!/bin/bash
- #
- # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
- #
- # Run bubble launcher in a docker container. Works on Linux or Mac OS.
- #
- # Does not require root privileges if you already have Docker installed and your
- # user account has permissions to pull docker images and run docker containers.
- #
- # Intended to be "run from anywhere" like this:
- #
- # /bin/bash -c "$(curl -sL https://git.bubblev.org/bubblev/bubble/raw/branch/master/launcher)"
- #
- # This command will:
- # - install docker if no "docker" command found
- # - pull bubble launcher docker image
- # - run bubble launcher docker image
- #
- # You'll be asked for an email address to associate with any LetsEncrypt certificates that will be created.
- #
- # If you want to run this unattended, set the LETSENCRYPT_EMAIL environment variable.
- #
- # Upon successful startup, the bubble launcher will be listening on port 8090
- # If you'd prefer to use a different port, set the BUBBLE_PORT environment variable.
- #
- # Open http://127.0.0.1:8090/ (or http://127.0.0.1:BUBBLE_PORT/) in a web browser
- # to continue with activation.
- #
- # By default this will grab the latest Bubble release. If you want a specific version,
- # set the BUBBLE_TAG environment variable to the release tag you'd like to run,
- # usually a semantic version number. For example: BUBBLE_TAG=1.5.2
- #
-
- function die() {
- echo 1>&2 "
-
- ***** ${1}
- "
- exit 1
- }
-
- function get_bubble_tag() {
- if [[ -n "${BUBBLE_TAG}" ]] ; then
- VERSION="${BUBBLE_TAG}"
- else
- BUBBLE_RELEASE_URL="https://jenkins.bubblev.org/public/releases/bubble/latest.txt"
- VERSION="$(curl -s ${BUBBLE_RELEASE_URL} | awk -F '_' '{print $2}' | awk -F '.' '{print $1"."$2"."$3}')"
- if [[ -z "${VERSION}" ]]; then
- die "Error determining version from URL: ${BUBBLE_RELEASE_URL}"
- fi
- fi
- echo -n "getbubble/launcher:${VERSION}"
- }
-
- function ensure_docker_group() {
- CALLER="$(whoami)"
- if [[ "${CALLER}" != "root" && "$(sudo id -Gn "${CALLER}" | grep -c docker | tr -d ' ')" -eq 0 ]]; then
- echo "Adding user ${CALLER} to docker group ..."
- sudo usermod -a -G docker "${CALLER}"
- fi
- }
-
- function setup_docker_debian() {
- # Ensure apt is up to date
- sudo apt update -y
-
- # Remove obsolete packages
- sudo apt-get remove docker docker-engine docker.io containerd runc
-
- # Ensure apt can install packages over https
- sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
-
- # Install docker GPG key
- curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
-
- # Add docker repo
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
-
- # Refresh apt after adding repo
- sudo apt update -y
-
- # Install docker
- sudo apt install -y docker-ce docker-ce-cli containerd.io
-
- ensure_docker_group
- }
-
- function setup_docker_ubuntu() {
- # Ensure apt is up to date
- sudo apt update -y
-
- # Remove obsolete packages
- sudo apt-get remove docker docker-engine docker.io containerd runc
-
- # Ensure apt can install packages over https
- sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
-
- # Install docker GPG key
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
-
- # Add docker repo
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
-
- # Refresh apt after adding repo
- sudo apt update -y
-
- # Install docker
- sudo apt install -y docker-ce
-
- ensure_docker_group
- }
-
- function setup_docker_generic_linux() {
- curl -fsSL https://get.docker.com | sudo sh -
- }
-
- function setup_docker_linux() {
- DISTRO="$(cat /etc/os-release | grep "^NAME" | awk -F '=' '{print $2}' | tr -d '"')"
- if [[ $(echo -n ${DISTRO} | grep -c Debian | tr -d ' ') -gt 0 ]]; then
- setup_docker_debian
- elif [[ $(echo -n ${DISTRO} | grep -c Ubuntu | tr -d ' ') -gt 0 ]]; then
- setup_docker_ubuntu
- else
- setup_docker_generic_linux
- fi
- }
-
- function setup_docker_macosx() {
- if [[ -z "$(which brew)" ]]; then
- die "Homebrew not installed (brew command not found). Install homebrew by running:
- /bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\"
- "
- fi
- brew install docker docker-machine || die "Error installing docker and docker-machine"
- brew install --cask virtualbox || die "Error installing virtualbox (check Security Settings)"
- docker-machine create --driver virtualbox default || die "Error creating docker-machine"
- }
-
- function setup_docker() {
- echo "Installing docker via sudo ..."
-
- if [[ "${PLATFORM}" == "Linux" ]]; then
- if [[ $(whoami) != "root" ]]; then
- echo "Note: you may need to enter your password (for Linux user $(whoami)) to enable sudo commands"
- fi
- setup_docker_linux
-
- elif [[ "${PLATFORM}" == "Darwin" ]]; then
- if [[ $(whoami) != "root" ]]; then
- echo "Note: you may need to enter your password (for MacOS user $(whoami)) to enable sudo commands"
- fi
- setup_docker_macosx
- eval "$(docker-machine env default)"
- docker-machine start default
-
- else
- die "Don't know how to install docker on ${PLATFORM}"
- fi
- }
-
- function run_launcher() {
- PLATFORM="$(uname -s)"
- if [[ -z "${PLATFORM}" ]]; then
- die "'uname -s' returned empty string!"
- fi
-
- DOCKER="$(which docker)"
- if [[ -z "${DOCKER}" ]]; then
- setup_docker
- DOCKER="$(which docker)"
- if [[ -z "${DOCKER}" ]]; then
- die "***** Error installing docker
- Install docker manually from https://docs.docker.com/engine/install/
- Then re-run this script.
- "
- fi
- fi
- if [[ "${PLATFORM}" == "Linux" ]]; then
- ensure_docker_group
- fi
-
- # Determine bubble docker tag
- DOCKER_TAG=$(get_bubble_tag)
-
- # Determine OS user
- CALLER="$(whoami)"
-
- # Pull bubble docker image
- if [[ "${CALLER}" == "root" ]] ; then
- ${DOCKER} pull "${DOCKER_TAG}" || die "Error pulling docker image: ${DOCKER_TAG}"
- else
- ${DOCKER} pull "${DOCKER_TAG}" || \
- echo "***** error running '${DOCKER} pull' as ${CALLER}, trying via sudo ..." && \
- sudo su - "${CALLER}" -c "${DOCKER} pull ${DOCKER_TAG}" || die "Error pulling docker image: ${DOCKER_TAG}"
- fi
-
- # Determine email for LetsEncrypt certs
- if [[ -z "${LETSENCRYPT_EMAIL}" ]]; then
- echo
- echo -n "Email address for LetsEncrypt certificates: "
- read -r LETSENCRYPT_EMAIL
- fi
-
- # Determine port
- EXPOSE=""
- if [[ -z "${BUBBLE_PORT}" ]] ; then
- BUBBLE_PORT=8090
- else
- EXPOSE="--expose ${BUBBLE_PORT}"
- fi
-
- # Run bubble docker image
- if [[ "${CALLER}" == "root" ]] ; then
- run ${EXPOSE} \
- -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
- -e LETSENCRYPT_EMAIL="${LETSENCRYPT_EMAIL}" \
- -e BUBBLE_SERVER_PORT=${BUBBLE_PORT} \
- -e PUBLIC_BASE_URI=http://127.0.0.1:${BUBBLE_PORT} \
- -t "${DOCKER_TAG}"
- else
- ${DOCKER} run ${EXPOSE} \
- -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
- -e LETSENCRYPT_EMAIL="${LETSENCRYPT_EMAIL}" \
- -e BUBBLE_SERVER_PORT=${BUBBLE_PORT} \
- -e PUBLIC_BASE_URI=http://127.0.0.1:${BUBBLE_PORT} \
- -t "${DOCKER_TAG}" || \
- echo "***** error running '${DOCKER} run' as ${CALLER}, trying via sudo ..." && \
- sudo su - "${CALLER}" -c "${DOCKER} run ${EXPOSE} \
- -p ${BUBBLE_PORT}:${BUBBLE_PORT} \
- -e BUBBLE_SERVER_PORT=${BUBBLE_PORT} \
- -e LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL} \
- -e PUBLIC_BASE_URI=http://127.0.0.1:${BUBBLE_PORT} \
- -t ${DOCKER_TAG}"
- fi
- }
-
- run_launcher
|