93 lines
4.6 KiB
Bash
Executable File
93 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
# 🚀 Nocr Services Deployment Script
|
|
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
# Usage: ./deploy.sh <tag> <commit-sha>
|
|
# Example: ./deploy.sh v1.2.3 abc1234
|
|
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
|
|
TAG=${1:-latest}
|
|
COMMIT_SHA=${2:-latest}
|
|
NAMESPACE="nocr"
|
|
DEPLOYMENT_FILE="../k8s/deployment.yaml"
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "🚀 Starting deployment of Nocr services"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "📦 Tag: $TAG"
|
|
echo "📝 Commit SHA: $COMMIT_SHA"
|
|
echo "🎯 Namespace: $NAMESPACE"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
# Check if kubectl is available
|
|
if ! command -v kubectl &> /dev/null; then
|
|
echo "❌ kubectl not found. Please install kubectl."
|
|
exit 1
|
|
fi
|
|
|
|
# Check cluster connection
|
|
echo "🔍 Checking connection to Kubernetes cluster..."
|
|
if ! kubectl cluster-info &> /dev/null; then
|
|
echo "❌ Cannot connect to Kubernetes cluster."
|
|
exit 1
|
|
fi
|
|
echo "✅ Connected to cluster"
|
|
|
|
# Create temporary deployment file with updated image tags
|
|
TEMP_DEPLOYMENT=$(mktemp)
|
|
cp "$DEPLOYMENT_FILE" "$TEMP_DEPLOYMENT"
|
|
|
|
echo "🔧 Updating image tags in deployment manifests..."
|
|
|
|
# Update image tags for all services
|
|
sed -i "s|hub.musk.fun/k8s/nocr/telegram_listener:.*|hub.musk.fun/k8s/nocr/telegram_listener:${COMMIT_SHA}|g" "$TEMP_DEPLOYMENT"
|
|
sed -i "s|hub.musk.fun/k8s/nocr/telegram_client:.*|hub.musk.fun/k8s/nocr/telegram_client:${COMMIT_SHA}|g" "$TEMP_DEPLOYMENT"
|
|
sed -i "s|hub.musk.fun/k8s/nocr/text_matcher:.*|hub.musk.fun/k8s/nocr/text_matcher:${COMMIT_SHA}|g" "$TEMP_DEPLOYMENT"
|
|
sed -i "s|hub.musk.fun/k8s/nocr/text_matcher_migrator:.*|hub.musk.fun/k8s/nocr/text_matcher_migrator:${COMMIT_SHA}|g" "$TEMP_DEPLOYMENT"
|
|
sed -i "s|hub.musk.fun/k8s/nocr/users:.*|hub.musk.fun/k8s/nocr/users:${COMMIT_SHA}|g" "$TEMP_DEPLOYMENT"
|
|
sed -i "s|hub.musk.fun/k8s/nocr/users_migrator:.*|hub.musk.fun/k8s/nocr/users_migrator:${COMMIT_SHA}|g" "$TEMP_DEPLOYMENT"
|
|
|
|
echo "✅ Image tags updated"
|
|
|
|
# Apply deployments
|
|
echo "📦 Applying deployment manifests to cluster..."
|
|
kubectl apply -f "$TEMP_DEPLOYMENT" -n "$NAMESPACE"
|
|
|
|
# Clean up temp file
|
|
rm "$TEMP_DEPLOYMENT"
|
|
|
|
echo "✅ Manifests applied"
|
|
echo ""
|
|
echo "⏳ Waiting for rollouts to complete..."
|
|
echo ""
|
|
|
|
# Wait for each deployment to roll out
|
|
DEPLOYMENTS=("telegram-listener" "text-matcher" "users" "telegram-client")
|
|
TIMEOUT="300s"
|
|
|
|
for deployment in "${DEPLOYMENTS[@]}"; do
|
|
echo "🔄 Rolling out $deployment..."
|
|
if kubectl rollout status deployment/"$deployment" -n "$NAMESPACE" --timeout="$TIMEOUT"; then
|
|
echo "✅ $deployment rolled out successfully"
|
|
else
|
|
echo "❌ $deployment rollout failed or timed out"
|
|
echo "🔍 Pod status:"
|
|
kubectl get pods -n "$NAMESPACE" -l app="$deployment"
|
|
echo "🔍 Recent events:"
|
|
kubectl get events -n "$NAMESPACE" --sort-by='.lastTimestamp' | grep "$deployment" | tail -10
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
done
|
|
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "✅ Deployment completed successfully!"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "📊 Pod status:"
|
|
kubectl get pods -n "$NAMESPACE" -o wide
|
|
echo ""
|
|
echo "🔍 Running health checks..."
|
|
bash "$(dirname "$0")/health-check.sh"
|