142 lines
3.6 KiB
Bash
142 lines
3.6 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# Docker Compose Startup Script for Rerank
|
|
#
|
|
# Usage: ./deploy/deploy.sh [OPTIONS]
|
|
#
|
|
# Options:
|
|
# --profile <api|vllm|llamacpp> Docker compose profile
|
|
# --detach Run in detached mode
|
|
# --down Stop and remove containers
|
|
# --logs Show logs
|
|
# --help Show this help message
|
|
#
|
|
# Required: Set environment variables in .env file or export them before running.
|
|
# See .env.example for the full list of required variables.
|
|
|
|
set -euo pipefail
|
|
|
|
# Script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Load .env file if it exists (check deploy/ first, then module root)
|
|
ENV_FILE=""
|
|
if [[ -f "$SCRIPT_DIR/.env" ]]; then
|
|
ENV_FILE="$SCRIPT_DIR/.env"
|
|
elif [[ -f "$SCRIPT_DIR/../.env" ]]; then
|
|
ENV_FILE="$SCRIPT_DIR/../.env"
|
|
fi
|
|
|
|
if [[ -n "$ENV_FILE" ]]; then
|
|
echo "Loading environment from: $ENV_FILE"
|
|
set -a
|
|
source "$ENV_FILE"
|
|
set +a
|
|
fi
|
|
|
|
PROFILE=""
|
|
DETACH=""
|
|
ACTION="up"
|
|
|
|
show_help() {
|
|
sed -n '2,14p' "$0" | sed 's/^# //' | sed 's/^#//'
|
|
exit 0
|
|
}
|
|
|
|
check_required_var() {
|
|
local var_name="$1"
|
|
if [[ -z "${!var_name:-}" ]]; then
|
|
echo "ERROR: Required environment variable $var_name is not set"
|
|
echo "Set it in .env file or export it before running this script"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Parse arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--profile)
|
|
PROFILE="$2"
|
|
shift 2
|
|
;;
|
|
--detach|-d)
|
|
DETACH="-d"
|
|
shift
|
|
;;
|
|
--down)
|
|
ACTION="down"
|
|
shift
|
|
;;
|
|
--logs)
|
|
ACTION="logs"
|
|
shift
|
|
;;
|
|
--help|-h)
|
|
show_help
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
echo "Use --help for usage information"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Require profile to be specified
|
|
if [[ -z "$PROFILE" && "$ACTION" == "up" ]]; then
|
|
echo "ERROR: --profile is required"
|
|
echo "Options: api, vllm, llamacpp"
|
|
exit 1
|
|
fi
|
|
|
|
# Check required variables
|
|
check_required_var "RERANK_DEFAULT_BACKEND"
|
|
check_required_var "RERANK_ENABLE_VLLM"
|
|
check_required_var "RERANK_ENABLE_LLAMACPP"
|
|
check_required_var "RERANK_EXTERNAL_URL"
|
|
|
|
# Check profile-specific variables
|
|
case $PROFILE in
|
|
vllm)
|
|
check_required_var "RERANK_VLLM_MODEL"
|
|
;;
|
|
llamacpp)
|
|
check_required_var "MODELS_DIR"
|
|
check_required_var "RERANK_LLAMACPP_MODEL"
|
|
;;
|
|
esac
|
|
|
|
cd "$SCRIPT_DIR"
|
|
|
|
case $ACTION in
|
|
up)
|
|
echo "Starting Rerank with profile: $PROFILE"
|
|
echo " Default backend: $RERANK_DEFAULT_BACKEND"
|
|
echo " vLLM enabled: $RERANK_ENABLE_VLLM"
|
|
echo " llama.cpp enabled: $RERANK_ENABLE_LLAMACPP"
|
|
if [[ "$PROFILE" == "vllm" ]]; then
|
|
echo " vLLM model: ${RERANK_VLLM_MODEL:-BAAI/bge-reranker-v2-m3}"
|
|
fi
|
|
if [[ "$PROFILE" == "llamacpp" ]]; then
|
|
echo " llama.cpp model: ${RERANK_LLAMACPP_MODEL:-bge-reranker-v2-m3-q4_k_m.gguf}"
|
|
fi
|
|
echo ""
|
|
# shellcheck disable=SC2086
|
|
exec docker compose --profile "$PROFILE" up $DETACH
|
|
;;
|
|
down)
|
|
if [[ -z "$PROFILE" ]]; then
|
|
echo "ERROR: --profile is required with --down"
|
|
exit 1
|
|
fi
|
|
echo "Stopping Rerank containers..."
|
|
exec docker compose --profile "$PROFILE" down
|
|
;;
|
|
logs)
|
|
if [[ -z "$PROFILE" ]]; then
|
|
echo "ERROR: --profile is required with --logs"
|
|
exit 1
|
|
fi
|
|
exec docker compose --profile "$PROFILE" logs -f
|
|
;;
|
|
esac
|