nxtgauge-backend-rust/scripts/deploy-changed.sh
Ashwin Kumar dbe1706a07 feat(deployment): add optimized build system for faster deployments
- Add Dockerfile.optimized with cargo-chef caching

- Add build-changed.sh script to build only modified services

- Add deploy-changed.sh script for selective deployment

- Add comprehensive deployment optimization guide

- Support independent service rollouts (no full redeploy needed)
2026-04-10 05:14:27 +02:00

105 lines
3.1 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# deploy-changed.sh - Deploy only changed services to Kubernetes
# Usage: ./deploy-changed.sh [service-name] or ./deploy-changed.sh --detect
set -e
NAMESPACE="nxtgauge"
KUSTOMIZE_DIR="/Users/ashwin/workspace/nxtgauge-gitops/apps/nxtgauge-backend-rust/base"
# Services mapping (service_name:deployment_name)
declare -A SERVICES=(
["gateway"]="nxtgauge-rust-gateway"
["users"]="nxtgauge-rust-users"
["companies"]="nxtgauge-rust-companies"
["job_seekers"]="nxtgauge-rust-job-seekers"
["customers"]="nxtgauge-rust-customers"
["photographers"]="nxtgauge-rust-photographers"
["makeup_artists"]="nxtgauge-rust-makeup-artists"
["tutors"]="nxtgauge-rust-tutors"
["developers"]="nxtgauge-rust-developers"
["video_editors"]="nxtgauge-rust-video-editors"
["graphic_designers"]="nxtgauge-rust-graphic-designers"
["social_media_managers"]="nxtgauge-rust-social-media-managers"
["fitness_trainers"]="nxtgauge-rust-fitness-trainers"
["catering_services"]="nxtgauge-rust-catering-services"
["ugc_content_creators"]="nxtgauge-rust-ugc-content-creators"
["employees"]="nxtgauge-rust-employees"
["payments"]="nxtgauge-rust-payments"
["cron"]="nxtgauge-cron"
)
deploy_service() {
local service=$1
local deployment=${SERVICES[$service]}
if [ -z "$deployment" ]; then
echo "❌ Unknown service: $service"
return 1
fi
echo "🚀 Deploying ${service} (${deployment})..."
# Trigger rolling restart to pick up new image
kubectl rollout restart deployment/${deployment} -n ${NAMESPACE}
# Wait for rollout to complete
echo "⏳ Waiting for rollout to complete..."
kubectl rollout status deployment/${deployment} -n ${NAMESPACE} --timeout=300s
echo "${service} deployed successfully"
}
# If specific service provided
if [ "$1" != "--detect" ] && [ -n "$1" ]; then
deploy_service "$1"
exit 0
fi
# Auto-detect changed services
if [ "$1" == "--detect" ]; then
echo "🔍 Detecting changed services from git..."
# Get changed files from last commit
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
if [ -z "$CHANGED_FILES" ]; then
echo "⚠️ No changes detected"
exit 0
fi
# Check if shared crates changed
SHARED_CHANGED=false
if echo "$CHANGED_FILES" | grep -q "^crates/"; then
SHARED_CHANGED=true
echo "⚠️ Shared crates changed - will redeploy ALL services"
fi
# Check if K8s manifests changed
K8S_CHANGED=false
if echo "$CHANGED_FILES" | grep -q "^apps/nxtgauge-gitops/"; then
K8S_CHANGED=true
fi
# Track if any service was deployed
DEPLOYED=0
# Check each service
for service in "${!SERVICES[@]}"; do
# Convert service name to path (replace _ with -)
service_path=$(echo "$service" | tr '_' '-')
if [ "$SHARED_CHANGED" = true ] || echo "$CHANGED_FILES" | grep -q "^apps/${service_path}/"; then
deploy_service "$service"
DEPLOYED=$((DEPLOYED + 1))
else
echo "⏭️ ${service} - no changes, skipping"
fi
done
if [ $DEPLOYED -eq 0 ]; then
echo " No services needed deployment"
else
echo "🎉 Deployed $DEPLOYED service(s)"
fi
fi