Add interactive menu and package checks to deployment script
- Add interactive numbered menu for manual deployments (7 options) - Add --no-cache flag support for forcing Docker rebuilds - Add package publication verification before Docker build - Display configuration summary before deployment - Maintain backward compatibility with CLI arguments Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
788794b740
commit
5d55bd1720
@ -4,17 +4,29 @@ set -euo pipefail
|
|||||||
# ═══════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════
|
||||||
# ByteLyst Investment Trading - Production Deployment Script
|
# ByteLyst Investment Trading - Production Deployment Script
|
||||||
# ═══════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════
|
||||||
# Usage: ./deploy-invttrdg.sh [--force] [--skip-health-check]
|
# Usage: ./deploy-invttrdg.sh [--force] [--skip-health-check] [--no-cache]
|
||||||
|
# (No arguments = interactive menu)
|
||||||
#
|
#
|
||||||
# What it does:
|
# What it does:
|
||||||
# 1. Dirty check: uncommitted changes, unpushed commits
|
# 1. Dirty check: uncommitted changes, unpushed commits
|
||||||
# 2. Pull and rebase origin/main
|
# 2. Pull and rebase origin/main
|
||||||
# 3. Build and deploy Docker containers
|
# 3. Check @bytelyst package publication
|
||||||
# 4. Verify endpoints: https://api.bytelyst.com/invttrdg, https://invttrdg.bytelyst.com
|
# 4. Build and deploy Docker containers
|
||||||
|
# 5. Verify endpoints: https://api.bytelyst.com/invttrdg, https://invttrdg.bytelyst.com
|
||||||
#
|
#
|
||||||
# Options:
|
# Options:
|
||||||
# --force Skip dirty checks and force deployment
|
# --force Skip dirty checks and force deployment
|
||||||
# --skip-health-check Skip endpoint health verification
|
# --skip-health-check Skip endpoint health verification
|
||||||
|
# --no-cache Build Docker images without cache
|
||||||
|
#
|
||||||
|
# Interactive Menu (no arguments):
|
||||||
|
# 1 - Normal deployment (with cache, with health checks)
|
||||||
|
# 2 - Force deployment (skip dirty checks, with cache)
|
||||||
|
# 3 - Skip health checks (with cache)
|
||||||
|
# 4 - No-cache build (force rebuild, with health checks)
|
||||||
|
# 5 - Force + No-cache (skip checks, force rebuild)
|
||||||
|
# 6 - Force + Skip health checks (skip both)
|
||||||
|
# 7 - All options: Force + Skip health + No-cache
|
||||||
# ═══════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
|
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
|
||||||
@ -31,15 +43,76 @@ cd "$SCRIPT_DIR"
|
|||||||
|
|
||||||
FORCE=false
|
FORCE=false
|
||||||
SKIP_HEALTH_CHECK=false
|
SKIP_HEALTH_CHECK=false
|
||||||
|
NO_CACHE=false
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--force) FORCE=true; shift ;;
|
--force) FORCE=true; shift ;;
|
||||||
--skip-health-check) SKIP_HEALTH_CHECK=true; shift ;;
|
--skip-health-check) SKIP_HEALTH_CHECK=true; shift ;;
|
||||||
|
--no-cache) NO_CACHE=true; shift ;;
|
||||||
*) fail "Unknown option: $1" ;;
|
*) fail "Unknown option: $1" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# ── Interactive Menu ────────────────────────────────────────────────────
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
echo ""
|
||||||
|
echo -e "${CYAN}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||||
|
echo -e "${CYAN}║${NC} ByteLyst Investment Trading - Deployment Options ${CYAN}║${NC}"
|
||||||
|
echo -e "${CYAN}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e " ${GREEN}1${NC} - Normal deployment (with cache, with health checks)"
|
||||||
|
echo -e " ${GREEN}2${NC} - Force deployment (skip dirty checks, with cache)"
|
||||||
|
echo -e " ${GREEN}3${NC} - Skip health checks (with cache)"
|
||||||
|
echo -e " ${GREEN}4${NC} - No-cache build (force rebuild, with health checks)"
|
||||||
|
echo -e " ${GREEN}5${NC} - Force + No-cache (skip checks, force rebuild)"
|
||||||
|
echo -e " ${GREEN}6${NC} - Force + Skip health checks (skip both)"
|
||||||
|
echo -e " ${GREEN}7${NC} - All options: Force + Skip health + No-cache"
|
||||||
|
echo ""
|
||||||
|
read -r -p "Select option [1-7]: " choice
|
||||||
|
|
||||||
|
case "$choice" in
|
||||||
|
1)
|
||||||
|
# Normal deployment (defaults)
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
FORCE=true
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
SKIP_HEALTH_CHECK=true
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
NO_CACHE=true
|
||||||
|
;;
|
||||||
|
5)
|
||||||
|
FORCE=true
|
||||||
|
NO_CACHE=true
|
||||||
|
;;
|
||||||
|
6)
|
||||||
|
FORCE=true
|
||||||
|
SKIP_HEALTH_CHECK=true
|
||||||
|
;;
|
||||||
|
7)
|
||||||
|
FORCE=true
|
||||||
|
SKIP_HEALTH_CHECK=true
|
||||||
|
NO_CACHE=true
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
fail "Invalid option. Please run again and select 1-7."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
log "Selected configuration:"
|
||||||
|
[ "$FORCE" = true ] && echo " - Force deployment (skip dirty checks)"
|
||||||
|
[ "$SKIP_HEALTH_CHECK" = true ] && echo " - Skip health checks"
|
||||||
|
[ "$NO_CACHE" = true ] && echo " - No-cache build (force rebuild)"
|
||||||
|
[ "$FORCE" = false ] && [ "$SKIP_HEALTH_CHECK" = false ] && [ "$NO_CACHE" = false ] && echo " - Normal deployment"
|
||||||
|
echo ""
|
||||||
|
read -r -p "Press Enter to continue or Ctrl+C to cancel..."
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
# ── Prerequisites ────────────────────────────────────────────────────
|
# ── Prerequisites ────────────────────────────────────────────────────
|
||||||
if [ ! -d "$REPO_DIR" ]; then
|
if [ ! -d "$REPO_DIR" ]; then
|
||||||
fail "Repo directory not found: $REPO_DIR"
|
fail "Repo directory not found: $REPO_DIR"
|
||||||
@ -105,6 +178,43 @@ if [ "$SKIP_HEALTH_CHECK" = false ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ── Check Package Publication ──────────────────────────────────────────
|
||||||
|
log "Checking @bytelyst package publication..."
|
||||||
|
|
||||||
|
# Check if required packages are published to Gitea registry
|
||||||
|
GITEA_REGISTRY="http://localhost:3300/api/packages/bytelyst/npm/"
|
||||||
|
REQUIRED_PACKAGES=(
|
||||||
|
"@bytelyst/config"
|
||||||
|
"@bytelyst/cosmos"
|
||||||
|
"@bytelyst/auth"
|
||||||
|
"@bytelyst/llm"
|
||||||
|
"@bytelyst/telemetry-client"
|
||||||
|
"@bytelyst/devops"
|
||||||
|
"@bytelyst/errors"
|
||||||
|
"@bytelyst/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
MISSING_PACKAGES=()
|
||||||
|
|
||||||
|
for package in "${REQUIRED_PACKAGES[@]}"; do
|
||||||
|
# Check if package is published (Gitea API returns 200 if package exists)
|
||||||
|
if ! curl -sf "${GITEA_REGISTRY}${package}" > /dev/null 2>&1; then
|
||||||
|
MISSING_PACKAGES+=("$package")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ${#MISSING_PACKAGES[@]} -gt 0 ]; then
|
||||||
|
fail "Required @bytelyst packages not published to Gitea registry:
|
||||||
|
${MISSING_PACKAGES[*]}
|
||||||
|
|
||||||
|
Please publish the packages first by running:
|
||||||
|
python3 /opt/bytelyst/republish_packages.py
|
||||||
|
|
||||||
|
This will publish all @bytelyst/* packages to https://gitea.bytelyst.com/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ok "All required @bytelyst packages are published"
|
||||||
|
|
||||||
# ── Build and Deploy ──────────────────────────────────────────────────
|
# ── Build and Deploy ──────────────────────────────────────────────────
|
||||||
log "Building and deploying Docker containers..."
|
log "Building and deploying Docker containers..."
|
||||||
|
|
||||||
@ -115,6 +225,11 @@ fi
|
|||||||
|
|
||||||
# Build and start services
|
# Build and start services
|
||||||
log "Building Docker images..."
|
log "Building Docker images..."
|
||||||
|
if [ "$NO_CACHE" = true ]; then
|
||||||
|
warn "Building without cache (--no-cache enabled)"
|
||||||
|
else
|
||||||
|
log "Building with cache (use --no-cache to force rebuild)"
|
||||||
|
fi
|
||||||
|
|
||||||
# Resolve Gitea npm token for BuildKit secret
|
# Resolve Gitea npm token for BuildKit secret
|
||||||
if [ -z "${GITEA_NPM_TOKEN:-}" ]; then
|
if [ -z "${GITEA_NPM_TOKEN:-}" ]; then
|
||||||
@ -147,7 +262,11 @@ BYTELYST_COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s' 2>/dev/null | head -c
|
|||||||
build_image() {
|
build_image() {
|
||||||
local dockerfile="$1"
|
local dockerfile="$1"
|
||||||
local tag="$2"
|
local tag="$2"
|
||||||
docker build --network host \
|
local cache_flag=""
|
||||||
|
if [ "$NO_CACHE" = true ]; then
|
||||||
|
cache_flag="--no-cache"
|
||||||
|
fi
|
||||||
|
docker build --network host $cache_flag \
|
||||||
--secret id=gitea_npm_token,env=GITEA_NPM_TOKEN \
|
--secret id=gitea_npm_token,env=GITEA_NPM_TOKEN \
|
||||||
--build-arg "BYTELYST_COMMIT_SHA=${BYTELYST_COMMIT_SHA}" \
|
--build-arg "BYTELYST_COMMIT_SHA=${BYTELYST_COMMIT_SHA}" \
|
||||||
--build-arg "BYTELYST_COMMIT_SHA_FULL=${BYTELYST_COMMIT_SHA_FULL}" \
|
--build-arg "BYTELYST_COMMIT_SHA_FULL=${BYTELYST_COMMIT_SHA_FULL}" \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user