143 lines
5.4 KiB
Bash
Executable File
143 lines
5.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# ============================================================================
|
|
# Pager Application - One-Click Deployment Script
|
|
# Deploys to learn namespace in Kubernetes
|
|
# ============================================================================
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
NAMESPACE="learn"
|
|
BACKEND_IMAGE="pager-backend:latest"
|
|
FRONTEND_IMAGE="pager-frontend:latest"
|
|
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}"
|
|
echo -e "${BLUE}║ Pager Application Deployment Tool ║${NC}"
|
|
echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}"
|
|
echo ""
|
|
|
|
# Function to print step
|
|
print_step() {
|
|
echo -e "${YELLOW}▶ $1${NC}"
|
|
}
|
|
|
|
# Function to print success
|
|
print_success() {
|
|
echo -e "${GREEN}✓ $1${NC}"
|
|
}
|
|
|
|
# Function to print error
|
|
print_error() {
|
|
echo -e "${RED}✗ $1${NC}"
|
|
}
|
|
|
|
# Check if kubectl is available
|
|
if ! command -v kubectl &> /dev/null; then
|
|
print_error "kubectl is not installed or not in PATH"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if docker is available
|
|
if ! command -v docker &> /dev/null; then
|
|
print_error "Docker is not installed or not in PATH"
|
|
exit 1
|
|
fi
|
|
|
|
# Step 1: Build Docker images
|
|
print_step "Step 1/5: Building Docker images..."
|
|
|
|
echo " Building backend image..."
|
|
cd "$PROJECT_ROOT/backend"
|
|
docker build -t $BACKEND_IMAGE . || {
|
|
print_error "Backend Docker build failed"
|
|
exit 1
|
|
}
|
|
print_success "Backend image built: $BACKEND_IMAGE"
|
|
|
|
echo " Building frontend image..."
|
|
cd "$PROJECT_ROOT/frontend"
|
|
docker build -t $FRONTEND_IMAGE . || {
|
|
print_error "Frontend Docker build failed"
|
|
exit 1
|
|
}
|
|
print_success "Frontend image built: $FRONTEND_IMAGE"
|
|
|
|
# Step 2: Create namespace if it doesn't exist
|
|
print_step "Step 2/5: Setting up Kubernetes namespace..."
|
|
kubectl create namespace $NAMESPACE --dry-run=client -o yaml | kubectl apply -f - >/dev/null 2>&1
|
|
print_success "Namespace '$NAMESPACE' ready"
|
|
|
|
# Step 3: Apply Kubernetes configurations
|
|
print_step "Step 3/5: Deploying to Kubernetes..."
|
|
|
|
cd "$PROJECT_ROOT/k8s"
|
|
|
|
# Deploy in correct order
|
|
echo " Applying configurations..."
|
|
kubectl apply -f learn-deployment.yaml -n $NAMESPACE || {
|
|
print_error "Failed to apply Kubernetes configurations"
|
|
exit 1
|
|
}
|
|
print_success "Kubernetes configurations applied"
|
|
|
|
# Step 4: Wait for deployments
|
|
print_step "Step 4/5: Waiting for deployments to be ready..."
|
|
|
|
echo " Waiting for backend deployment..."
|
|
kubectl rollout status deployment/pager-backend -n $NAMESPACE --timeout=5m 2>&1 | grep -v "Waiting for" | tail -1
|
|
if [ ${PIPESTATUS[0]} -eq 0 ]; then
|
|
print_success "Backend deployment ready"
|
|
else
|
|
print_error "Backend deployment timeout"
|
|
fi
|
|
|
|
echo " Waiting for frontend deployment..."
|
|
kubectl rollout status deployment/pager-frontend -n $NAMESPACE --timeout=5m 2>&1 | grep -v "Waiting for" | tail -1
|
|
if [ ${PIPESTATUS[0]} -eq 0 ]; then
|
|
print_success "Frontend deployment ready"
|
|
else
|
|
print_error "Frontend deployment timeout"
|
|
fi
|
|
|
|
# Step 5: Display deployment status
|
|
print_step "Step 5/5: Deployment Summary"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}Pods:${NC}"
|
|
kubectl get pods -n $NAMESPACE
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}Services:${NC}"
|
|
kubectl get svc -n $NAMESPACE
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}Ingress:${NC}"
|
|
kubectl get ingress -n $NAMESPACE
|
|
|
|
echo ""
|
|
echo -e "${GREEN}╔══════════════════════════════════════════════════════════════╗${NC}"
|
|
echo -e "${GREEN}║ Deployment Complete! ║${NC}"
|
|
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════╝${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}Access the application at:${NC}"
|
|
echo -e " ${BLUE}https://learn.omniverseai.net${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}Useful commands:${NC}"
|
|
echo -e " View logs (backend): ${GREEN}kubectl logs -n $NAMESPACE -l app=pager-backend -f${NC}"
|
|
echo -e " View logs (frontend): ${GREEN}kubectl logs -n $NAMESPACE -l app=pager-frontend -f${NC}"
|
|
echo -e " View pods: ${GREEN}kubectl get pods -n $NAMESPACE${NC}"
|
|
echo -e " Restart backend: ${GREEN}kubectl rollout restart deployment/pager-backend -n $NAMESPACE${NC}"
|
|
echo -e " Restart frontend: ${GREEN}kubectl rollout restart deployment/pager-frontend -n $NAMESPACE${NC}"
|
|
echo ""
|