#!/bin/bash # Quick deployment script for Pager application set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Configuration NAMESPACE="learn" HARBOR_URL="192.168.1.83:8080" HARBOR_PROJECT="pager" echo -e "${GREEN}🚀 Pager Application Deployment Script${NC}" echo "============================================" echo "" # Function to print section headers section() { echo "" echo -e "${YELLOW}>>> $1${NC}" } # Function to check command exists check_command() { if ! command -v $1 &> /dev/null; then echo -e "${RED}❌ Error: $1 is not installed${NC}" exit 1 fi } # Check prerequisites section "Checking prerequisites" check_command kubectl check_command docker echo -e "${GREEN}✅ All prerequisites met${NC}" # Check kubectl connectivity section "Checking Kubernetes connectivity" if ! kubectl cluster-info &> /dev/null; then echo -e "${RED}❌ Error: Cannot connect to Kubernetes cluster${NC}" exit 1 fi echo -e "${GREEN}✅ Connected to Kubernetes cluster${NC}" # Create namespace if not exists section "Creating namespace: $NAMESPACE" if kubectl get namespace $NAMESPACE &> /dev/null; then echo -e "${YELLOW}⚠️ Namespace $NAMESPACE already exists${NC}" else kubectl apply -f k8s/namespace.yaml echo -e "${GREEN}✅ Namespace created${NC}" fi # Deploy PostgreSQL section "Deploying PostgreSQL" kubectl apply -f k8s/postgres.yaml echo "⏳ Waiting for PostgreSQL to be ready..." kubectl wait --for=condition=ready pod -l app=pager-postgres -n $NAMESPACE --timeout=300s || true echo -e "${GREEN}✅ PostgreSQL deployed${NC}" # Deploy secrets and config section "Deploying secrets and configuration" kubectl apply -f k8s/secret.yaml kubectl apply -f k8s/configmap.yaml echo -e "${GREEN}✅ Secrets and ConfigMaps deployed${NC}" # Check if we should deploy application read -p "Do you want to deploy application pods? (requires images in Harbor) [y/N]: " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then section "Deploying application" # Get current git commit GIT_SHA=$(git rev-parse --short HEAD) IMAGE_TAG="master-${GIT_SHA}" echo "Using image tag: $IMAGE_TAG" # Update deployment with image tag sed "s|IMAGE_TAG|$IMAGE_TAG|g" k8s/deployment.yaml > /tmp/deployment-temp.yaml kubectl apply -f /tmp/deployment-temp.yaml kubectl apply -f k8s/service.yaml kubectl apply -f k8s/ingress.yaml rm /tmp/deployment-temp.yaml echo "⏳ Waiting for deployments to be ready..." kubectl rollout status deployment/pager-backend -n $NAMESPACE --timeout=300s || true kubectl rollout status deployment/pager-frontend -n $NAMESPACE --timeout=300s || true echo -e "${GREEN}✅ Application deployed${NC}" else echo -e "${YELLOW}⏭️ Skipping application deployment${NC}" fi # Deploy monitoring read -p "Do you want to deploy monitoring (ServiceMonitor)? [y/N]: " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then section "Deploying monitoring" kubectl apply -f k8s/monitoring/servicemonitor.yaml echo -e "${GREEN}✅ Monitoring deployed${NC}" fi # Show deployment status section "Deployment Status" echo "" echo "📦 Pods:" kubectl get pods -n $NAMESPACE echo "" echo "🌐 Services:" kubectl get svc -n $NAMESPACE echo "" echo "🔌 Ingress:" kubectl get ingress -n $NAMESPACE echo "" echo -e "${GREEN}🎉 Deployment Complete!${NC}" echo "" echo "Next steps:" echo "1. Add to /etc/hosts: 192.168.1.83 pager.learn.local" echo "2. Access frontend: http://pager.learn.local" echo "3. Access API docs: http://pager.learn.local/api/docs" echo "4. View logs: kubectl logs -f -l app=pager-backend -n $NAMESPACE" echo "5. Monitor in Grafana" echo ""