From 79ef0f3dd954af4a6ec4ab8fb612c3159b21b365 Mon Sep 17 00:00:00 2001 From: lenape Date: Mon, 14 Jul 2025 00:02:16 +0000 Subject: [PATCH] automated terminal push --- Jenkinsfile | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6e9636c..ad08c4e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -275,6 +275,43 @@ pipeline { } } + stage('Infrastructure Readiness Check') { + steps { + withCredentials([[ + $class: 'AmazonWebServicesCredentialsBinding', + credentialsId: env.AWS_CRED_ID + ]]) { + script { + echo "🔍 SECURITY: Checking if infrastructure is ready for deployment..." + + // Check if ECS service exists + def serviceExists = sh( + script: ''' + if aws ecs describe-services --cluster nvhi-atsila-cluster --services nvhi-atsila-cluster-service --region us-east-2 2>/dev/null | grep -q "ACTIVE"; then + echo "true" + else + echo "false" + fi + ''', + returnStdout: true + ).trim() + + if (serviceExists == "false") { + echo "🚨 SECURITY NOTICE: ECS service not found - forcing infrastructure deployment" + echo " This is normal for first deployment or after infrastructure cleanup" + env.DEPLOYMENT_TYPE = "INFRASTRUCTURE" + currentBuild.description = "INFRASTRUCTURE (auto-detected) | ${env.IMAGE_TAG}" + } + + echo "📋 SECURITY: Infrastructure readiness assessment completed" + echo " ECS Service Exists: ${serviceExists}" + echo " Final Deployment Type: ${env.DEPLOYMENT_TYPE}" + echo " Security Decision: ${serviceExists == 'true' ? 'Application-only deployment' : 'Infrastructure deployment required'}" + } + } + } + } + stage('Deploy Infrastructure') { when { expression { env.DEPLOYMENT_TYPE == "INFRASTRUCTURE" } @@ -400,8 +437,24 @@ pipeline { --container-definitions file://task-definition.json \\ --region ${AWS_REGION} - # Perform zero-downtime rolling deployment + # Perform zero-downtime rolling deployment with service check echo "🔄 Performing secure zero-downtime deployment..." + + # Wait for service to be active if it was just created + echo "⏳ Ensuring ECS service is ready for deployment..." + timeout=300 + while [ \$timeout -gt 0 ]; do + if aws ecs describe-services --cluster ${TF_VAR_cluster_name} --services ${TF_VAR_cluster_name}-service --region ${AWS_REGION} 2>/dev/null | grep -q "ACTIVE"; then + echo "✅ ECS service is active and ready" + break + else + echo "⏳ Waiting for ECS service to become active..." + sleep 10 + timeout=\$((timeout-10)) + fi + done + + # Update the service aws ecs update-service \\ --cluster ${TF_VAR_cluster_name} \\ --service ${TF_VAR_cluster_name}-service \\