Newer
Older
netbox-docker / hooks / common
@Christian Maฬˆder Christian Maฬˆder on 6 Feb 2019 2 KB Fix build target
#!/bin/bash

ensure_jq() {
  echo "๐Ÿ› ๐Ÿ› ๐Ÿ›  Installing JQ via apt-get"
  [ -x "$(command -v jq)" ] || ( apt-get update && apt-get install -y jq )
}

ensure_dockerfile_present() {
  if [ "${VARIANT}" == "main" ]; then
    DOCKERFILE="Dockerfile"
  else
    DOCKERFILE="Dockerfile.${VARIANT}"

    # Fail fast
    if [ ! -f "${DOCKERFILE}" ]; then
      echo "๐Ÿšจ The Dockerfile '${DOCKERFILE}' for variant '${VARIANT}' doesn't exist."

      if [ -z "$DEBUG" ]; then
        exit 1
      else
        echo "โš ๏ธ Would skip this, but DEBUG is enabled."
      fi
    fi

    if [ "${DOCKERFILE}" != "${DOCKERFILE_PATH}" ]; then
      echo "โš ๏ธ The specified Dockerfile '${DOCKERFILE_PATH}' does not match the expected Dockerfile '${DOCKERFILE}'."
      echo "   This script will use '${DOCKERFILE}' and ignore '${DOCKERFILE_PATH}'."
    fi
  fi
}

# Passes args to the scripts
run_build() {
  echo "๐Ÿณ๐Ÿณ๐Ÿณ Building '${BUILD}' images, the '${VARIANT:-main}' variant"
  case $BUILD in
    release)
      # build the latest release
      # shellcheck disable=SC2068
      ./build-latest.sh $@
      ;;
    prerelease)
      # build the latest pre-release
      # shellcheck disable=SC2068
      PRERELEASE=true ./build-latest.sh $@
      ;;
    branches)
      # build all branches
      # shellcheck disable=SC2068
      ./build-branches.sh $@
      ;;
    special)
      # special build
      # shellcheck disable=SC2068
      #SRC_ORG=lampwins TAG=webhooks-backend ./build.sh "feature/webhooks-backend" $@
      echo "โœ… No special builds today."
      ;;
    *)
      echo "๐Ÿšจ Unrecognized build '$BUILD'."

      if [ -z "$DEBUG" ]; then
        exit 1
      else
        echo "โš ๏ธ Would exit here with code '1', but DEBUG is enabled."
      fi
      ;;
  esac
}

echo "๐Ÿค–๐Ÿค–๐Ÿค– Preparing build"
export DOCKER_ORG="index.docker.io/netboxcommunity"
export DOCKER_REPO=netbox
export DOCKERHUB_REPO=netboxcommunity/netbox

# mis-using the "${DOCKER_TAG}" variable as "branch to build"
export BUILD="${DOCKER_TAG%-*}"
export VARIANT="${DOCKER_TAG#*-}"

unset DOCKER_TAG

ensure_dockerfile_present

ensure_jq