#!/bin/bash # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # # Build, run or push a docker container for a Bubble launcher. Intended for developer use. # # bdocker [mode] [version] # # mode : build, run or push # build - build the docker images # run - run a docker image. set the BUBBLE_RUN_SLIM env var to `true` to run the slim image. # push - push images docker hub # # version : version to use, default is read from bubble-server/src/main/resources/META-INF/bubble/bubble.properties # # The docker tag used will be getbubble/launcher:version # # We build two images, a full one and a slim one. # The full image is larger (will take longer to download), but will startup faster. # The slim image is smaller (will be faster to download), but will take longer to start up. # # The full image has the Bubble jar, updated packages and packer pre-installed. # The slim image has default packages and installs packer and the Bubble jar when it first runs. # # If you want to change the "getbubble/launcher" part of the Docker tag, set the BUBBLE_DOCKER_REPO # environment variable in your shell environment. # # When using the 'run' mode, 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 # in your ~/.bubble.env file or in your shell environment. # function die { echo 1>&2 "${1}" exit 1 } THISDIR="$(cd "$(dirname "${0}")" && pwd)" BUBBLE_DIR="$(cd "${THISDIR}/.." && pwd)" MODE=${1:?no mode specified, use build or run} META_FILE="${BUBBLE_DIR}/bubble-server/src/main/resources/META-INF/bubble/bubble.properties" VERSION="${2:-$(cat "${META_FILE}" | grep bubble.version | awk -F '=' '{print $2}' | awk -F ' ' '{print $NF}' | awk '{$1=$1};1')}" if [[ -z "${VERSION}" ]] ; then die "Error determining version from: ${META_FILE}" fi DOCKER_REPO="getbubble" if [[ -n "${BUBBLE_DOCKER_REPO}" ]] ; then DOCKER_REPO="${BUBBLE_DOCKER_REPO}" fi BUBBLE_TAG="${DOCKER_REPO}/launcher:${VERSION}" BUBBLE_SLIM_TAG="${DOCKER_REPO}/slim-launcher:${VERSION}" BUBBLE_ENV="${HOME}/.bubble.env" if [[ "${MODE}" == "build" ]] ; then if [[ $(find bubble-server/target -type f -name "bubble-server-*.jar" | wc -l | tr -d ' ') -eq 0 ]] ; then die "No bubble jar found in $(pwd)/bubble-server/target" fi docker build --no-cache -t "${BUBBLE_TAG}" . || die "Error building docker image" docker build --no-cache -f Dockerfile.slim -t "${BUBBLE_SLIM_TAG}" . || die "Error building slim docker image" elif [[ "${MODE}" == "run" ]] ; then if [[ $(cat "${BUBBLE_ENV}" | grep -v '^#' | grep -c LETSENCRYPT_EMAIL) -eq 0 ]] ; then if [[ -z "${LETSENCRYPT_EMAIL}" ]] ; then echo ; echo -n "Email address for LetsEncrypt certificates: " read -r LETSENCRYPT_EMAIL fi echo " export LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL} " >> "${BUBBLE_ENV}" fi if [[ -n "${BUBBLE_RUN_SLIM}" && "${BUBBLE_RUN_SLIM}" == "true" ]] ; then RUN_TAG="${BUBBLE_SLIM_TAG}" else RUN_TAG="${BUBBLE_TAG}" fi docker run --env-file <(cat "${BUBBLE_ENV}" | sed -e 's/export //' | tr -d '"' | tr -d "'") -p 8090:8090 -t "${RUN_TAG}" || die "Error running docker container" elif [[ "${MODE}" == "push" ]] ; then docker push "${BUBBLE_TAG}" || die "Error pushing docker image" docker push "${BUBBLE_SLIM_TAG}" || die "Error pushing slim docker image" else die "Invalid mode (expected build or run): ${MODE}" fi