#!/bin/bash # full-deploy.sh — Preflight + build + deploy auto-parse-email-content-and-extrac to AKS set -e GREEN='\033[0;32m' RED='\033[0;31m' NC='\033[0m' SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) ACR_NAME="bstagecjotdevacr" APP_NAME="auto-parse-email-content-and-extrac" NAMESPACE="agents" VERSION_FILE="${SCRIPT_DIR}/../.image-version" TAG="" while [[ "$#" -gt 0 ]]; do case $1 in --tag) TAG="$2"; shift ;; esac shift done print_success() { echo -e "${GREEN}✓ $1${NC}"; } print_error() { echo -e "${RED}✗ $1${NC}"; exit 1; } command -v kubectl &>/dev/null || print_error "kubectl not found." command -v az &>/dev/null || print_error "Azure CLI not found." az account show &>/dev/null || print_error "Not logged in to Azure." kubectl cluster-info &>/dev/null || print_error "Cannot connect to cluster." CLUSTER=$(kubectl config current-context) print_success "Connected to cluster: ${CLUSTER}" if [ -z "$TAG" ]; then if [ -f "$VERSION_FILE" ]; then CURRENT_VERSION=$(cat "$VERSION_FILE") else CURRENT_VERSION="1.0.0" fi IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" PATCH=$((PATCH + 1)) TAG="${MAJOR}.${MINOR}.${PATCH}" echo "$TAG" > "$VERSION_FILE" fi IMAGE="${ACR_NAME}.azurecr.io/${APP_NAME}:${TAG}" print_success "Image tag: ${TAG}" az acr build --registry ${ACR_NAME} \ --image ${APP_NAME}:${TAG} \ --image ${APP_NAME}:latest \ "${SCRIPT_DIR}/.." || print_error "ACR build failed." print_success "Image built: ${IMAGE}" kubectl apply -f "${SCRIPT_DIR}/../k8s/configmap.yaml" 2>/dev/null || true kubectl apply -f "${SCRIPT_DIR}/../k8s/deployment.yaml" || print_error "Failed to apply deployment." kubectl apply -f "${SCRIPT_DIR}/../k8s/service.yaml" || print_error "Failed to apply service." print_success "Manifests applied" kubectl set image deployment/${APP_NAME} ${APP_NAME}=${IMAGE} -n ${NAMESPACE} kubectl rollout status deployment/${APP_NAME} -n ${NAMESPACE} --timeout=180s || \ print_error "Rollout failed." print_success "Rollout complete" echo "" echo -e "${GREEN} auto-parse-email-content-and-extrac deployed: ${IMAGE}${NC}" echo " Port forward: kubectl port-forward -n ${NAMESPACE} deployment/${APP_NAME} 8080:8080"