|
- #!/bin/bash
- #
- # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
- #
- # Build and push a docker image to docker hub, if needed.
- # Run by jenkins after a successful build of the main Bubble repository.
- #
- # If an image has already been pushed with the current version, we do nothing.
- # If no image has been pushed with the current version, we build it and push it.
- #
- # Environment Variables:
- #
- # BUBBLE_DOCKER_USER - dockerhub username for "docker login"
- # BUBBLE_DOCKER_PASS - dockerhub password for "docker login"
- #
-
- function die {
- echo 1>&2 "${1}"
- exit 1
- }
-
- function ensure_docker_experimental_enabled() {
- DOCKER_DIR=${HOME}/.docker
- mkdir -p "${DOCKER_DIR}" || die "Error creating ${DOCKER_DIR}"
- if [[ -f ${DOCKER_DIR}/config.json ]] ; then
- TMP_CONFIG=$(mktemp /tmp/config.json.XXXX) &&
- jq '. + {"experimental": "enabled"}' < "${DOCKER_DIR}/config.json" > "${TMP_CONFIG}" &&
- mv "${TMP_CONFIG}" "${DOCKER_DIR}/config.json" || ( rm -f "${TMP_CONFIG}" ; die "Error adding experimental flag to ${DOCKER_DIR}/config.json" )
- if [[ -f ${TMP_CONFIG} ]] ; then rm -f "${TMP_CONFIG}" ; fi
- echo "ensure_docker_experimental_enabled: updated ${DOCKER_DIR}/config.json --> "
- cat "${DOCKER_DIR}/config.json"
- else
- echo '{"experimental": "enabled"}' > ~/.docker/config.json
- echo "ensure_docker_experimental_enabled: created ${DOCKER_DIR}/config.json --> "
- cat "${DOCKER_DIR}/config.json"
- fi
- }
-
- if [[ -z "${BUBBLE_DOCKER_USER}" ]] ; then
- die "No BUBBLE_DOCKER_USER env var found"
- fi
- if [[ -z "${BUBBLE_DOCKER_PASS}" ]] ; then
- die "No BUBBLE_DOCKER_PASS env var found"
- fi
-
- set +x
-
- THISDIR="$(cd "$(dirname "${0}")" && pwd)"
- BUBBLE_DIR="$(cd "${THISDIR}/../.." && pwd)"
-
- echo ">>> Logging in to docker ..."
- echo -n "${BUBBLE_DOCKER_PASS}" | docker login -u "${BUBBLE_DOCKER_USER}" --password-stdin || die "Error logging in to docker"
-
- echo ">>> Determining Bubble version ..."
- META_FILE="${BUBBLE_DIR}/bubble-server/src/main/resources/META-INF/bubble/bubble.properties"
- VERSION="$(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
- echo ">>> Found Bubble version ${VERSION}"
-
- echo ">>> Building docker bubble version ${VERSION} ..."
- BUBBLE_DOCKER="${BUBBLE_DIR}/bin/bdocker"
- ${BUBBLE_DOCKER} build "${VERSION}" || die "Error building docker image"
-
- ensure_docker_experimental_enabled
- BUBBLE_TAG="getbubble/launcher:${VERSION}"
-
- echo ">>> Checking to see if ${BUBBLE_TAG} already exists on dockerhub..."
- if docker manifest inspect "${BUBBLE_TAG}" > /dev/null 2> /dev/null ; then
- echo ">>> ${BUBBLE_TAG} already exists on dockerhub, not re-publishing"
- else
- echo ">>> ${BUBBLE_TAG} does not exist on dockerhub, pushing it ..."
- ${BUBBLE_DOCKER} push "${VERSION}" || die "Error pushing ${BUBBLE_TAG}"
- echo ">>> Successfully pushed to dockerhub: ${BUBBLE_TAG}"
- fi
|