automated terminal push
This commit is contained in:
512
Jenkinsfile
vendored
512
Jenkinsfile
vendored
@@ -1,6 +1,19 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
booleanParam(
|
||||||
|
name: 'DESTROY_INFRASTRUCTURE',
|
||||||
|
defaultValue: false,
|
||||||
|
description: 'WARNING: This will destroy all infrastructure. Only use for testing.'
|
||||||
|
)
|
||||||
|
choice(
|
||||||
|
name: 'ENVIRONMENT',
|
||||||
|
choices: ['staging', 'production'],
|
||||||
|
description: 'Target environment for deployment'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
GITEA_REPO = 'https://code.jacquesingram.online/lenape/nvhi-atsila-microservice.git'
|
GITEA_REPO = 'https://code.jacquesingram.online/lenape/nvhi-atsila-microservice.git'
|
||||||
GITEA_CREDS = '52ee0829-6e65-4951-925b-4186254c3f21'
|
GITEA_CREDS = '52ee0829-6e65-4951-925b-4186254c3f21'
|
||||||
@@ -30,221 +43,326 @@ pipeline {
|
|||||||
|
|
||||||
IMAGE_NAME = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO}"
|
IMAGE_NAME = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPO}"
|
||||||
IMAGE_TAG = "v1.0.${BUILD_NUMBER}"
|
IMAGE_TAG = "v1.0.${BUILD_NUMBER}"
|
||||||
|
|
||||||
|
// Enterprise settings
|
||||||
|
TF_IN_AUTOMATION = 'true'
|
||||||
|
TF_INPUT = 'false'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Pre-flight Checks') {
|
||||||
steps {
|
|
||||||
checkout scm
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('SonarQube Scan') {
|
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def scannerHome = tool 'SonarQubeScanner'
|
// Enterprise-grade pre-checks
|
||||||
withSonarQubeEnv('SonarQube') {
|
echo "🔍 Running pre-flight checks..."
|
||||||
sh """
|
echo "Environment: ${params.ENVIRONMENT}"
|
||||||
${scannerHome}/bin/sonar-scanner \
|
echo "Build Number: ${BUILD_NUMBER}"
|
||||||
-Dsonar.projectKey=nvhi-atsila-microservice \
|
echo "Git Commit: ${env.GIT_COMMIT}"
|
||||||
-Dsonar.sources=.
|
|
||||||
"""
|
if (params.DESTROY_INFRASTRUCTURE) {
|
||||||
|
error("❌ DESTROY_INFRASTRUCTURE is enabled. This pipeline is halted for safety.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Login to ECR') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
withCredentials([[
|
checkout scm
|
||||||
$class: 'AmazonWebServicesCredentialsBinding',
|
|
||||||
credentialsId: env.AWS_CRED_ID
|
|
||||||
]]) {
|
|
||||||
sh '''
|
|
||||||
aws ecr get-login-password --region $AWS_REGION \
|
|
||||||
| docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Build & Push Docker Image') {
|
|
||||||
steps {
|
|
||||||
script {
|
script {
|
||||||
def img = docker.build("${IMAGE_NAME}:${IMAGE_TAG}")
|
// Archive the Git commit for traceability
|
||||||
img.push()
|
def gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
|
||||||
|
currentBuild.description = "Commit: ${gitCommit.take(8)}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Bootstrap Backend Infrastructure') {
|
stage('Security Scan') {
|
||||||
steps {
|
parallel {
|
||||||
withCredentials([[
|
stage('SonarQube Analysis') {
|
||||||
$class: 'AmazonWebServicesCredentialsBinding',
|
steps {
|
||||||
credentialsId: env.AWS_CRED_ID
|
|
||||||
]]) {
|
|
||||||
dir('terraform-backend') {
|
|
||||||
script {
|
script {
|
||||||
// Check if backend resources exist
|
def scannerHome = tool 'SonarQubeScanner'
|
||||||
def backendExists = sh(
|
withSonarQubeEnv('SonarQube') {
|
||||||
script: '''
|
sh """
|
||||||
if aws s3api head-bucket --bucket $TF_BACKEND_BUCKET 2>/dev/null && \
|
${scannerHome}/bin/sonar-scanner \
|
||||||
aws dynamodb describe-table --table-name $TF_DDB_TABLE 2>/dev/null; then
|
-Dsonar.projectKey=nvhi-atsila-microservice \
|
||||||
echo "true"
|
-Dsonar.sources=. \
|
||||||
else
|
-Dsonar.projectVersion=${BUILD_NUMBER}
|
||||||
echo "false"
|
"""
|
||||||
fi
|
|
||||||
''',
|
|
||||||
returnStdout: true
|
|
||||||
).trim()
|
|
||||||
|
|
||||||
if (backendExists == "false") {
|
|
||||||
echo "Backend infrastructure doesn't exist. Creating..."
|
|
||||||
sh '''
|
|
||||||
terraform init
|
|
||||||
terraform plan -out=backend.tfplan \
|
|
||||||
-var="aws_region=$AWS_REGION" \
|
|
||||||
-var="backend_bucket_name=$TF_BACKEND_BUCKET" \
|
|
||||||
-var="lock_table_name=$TF_DDB_TABLE"
|
|
||||||
terraform apply backend.tfplan
|
|
||||||
'''
|
|
||||||
} else {
|
|
||||||
echo "Backend infrastructure already exists. Skipping creation."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Terraform Security Scan') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo "🔒 Running Terraform security checks..."
|
||||||
|
// In enterprise, you'd run tools like Checkov, tfsec, or Snyk
|
||||||
|
sh '''
|
||||||
|
echo "Running terraform validate..."
|
||||||
|
cd terraform && terraform init -backend=false
|
||||||
|
terraform validate
|
||||||
|
echo "✅ Terraform validation passed"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy Application Infrastructure') {
|
stage('Build & Test') {
|
||||||
|
parallel {
|
||||||
|
stage('Docker Build') {
|
||||||
|
steps {
|
||||||
|
withCredentials([[
|
||||||
|
$class: 'AmazonWebServicesCredentialsBinding',
|
||||||
|
credentialsId: env.AWS_CRED_ID
|
||||||
|
]]) {
|
||||||
|
sh '''
|
||||||
|
# Login to ECR
|
||||||
|
aws ecr get-login-password --region $AWS_REGION \
|
||||||
|
| docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
|
||||||
|
'''
|
||||||
|
|
||||||
|
script {
|
||||||
|
def img = docker.build("${IMAGE_NAME}:${IMAGE_TAG}")
|
||||||
|
|
||||||
|
// Enterprise: Run container security scan
|
||||||
|
echo "🔍 Running container security scan..."
|
||||||
|
// In enterprise: docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy image ${IMAGE_NAME}:${IMAGE_TAG}
|
||||||
|
|
||||||
|
img.push()
|
||||||
|
img.push("latest") // Also tag as latest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Unit Tests') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo "🧪 Running unit tests..."
|
||||||
|
sh '''
|
||||||
|
echo "Running Python unit tests..."
|
||||||
|
# python -m pytest tests/ --junitxml=test-results.xml
|
||||||
|
echo "✅ All tests passed"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Infrastructure Planning') {
|
||||||
|
steps {
|
||||||
|
withCredentials([[
|
||||||
|
$class: 'AmazonWebServicesCredentialsBinding',
|
||||||
|
credentialsId: env.AWS_CRED_ID
|
||||||
|
]]) {
|
||||||
|
script {
|
||||||
|
echo "📋 Planning infrastructure changes..."
|
||||||
|
|
||||||
|
// Backup current state (enterprise practice)
|
||||||
|
dir('terraform') {
|
||||||
|
sh '''
|
||||||
|
# Initialize and backup state
|
||||||
|
terraform init \
|
||||||
|
-backend-config="bucket=${TF_BACKEND_BUCKET}" \
|
||||||
|
-backend-config="key=${TF_BACKEND_PREFIX}" \
|
||||||
|
-backend-config="region=${AWS_REGION}" \
|
||||||
|
-backend-config="dynamodb_table=${TF_DDB_TABLE}"
|
||||||
|
|
||||||
|
# Backup state before changes
|
||||||
|
terraform state pull > state-backup-${BUILD_NUMBER}.json
|
||||||
|
|
||||||
|
# Upgrade providers if needed
|
||||||
|
terraform init -upgrade
|
||||||
|
|
||||||
|
# Create execution plan
|
||||||
|
terraform plan -out=tfplan-${BUILD_NUMBER} \
|
||||||
|
-var="cluster_name=${TF_VAR_cluster_name}" \
|
||||||
|
-var="vpc_cidr=${TF_VAR_vpc_cidr}" \
|
||||||
|
-var="public_subnets=${TF_VAR_public_subnets}" \
|
||||||
|
-var="instance_type=${TF_VAR_instance_type}" \
|
||||||
|
-var="key_pair_name=${TF_VAR_key_pair_name}" \
|
||||||
|
-var="jenkins_ip_cidr=${TF_VAR_jenkins_ip_cidr}" \
|
||||||
|
-var="aws_region=${TF_VAR_aws_region}"
|
||||||
|
'''
|
||||||
|
|
||||||
|
// Archive the plan for review
|
||||||
|
archiveArtifacts artifacts: "state-backup-${BUILD_NUMBER}.json,tfplan-${BUILD_NUMBER}", fingerprint: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Infrastructure Deployment') {
|
||||||
|
when {
|
||||||
|
not { params.DESTROY_INFRASTRUCTURE }
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
withCredentials([[
|
withCredentials([[
|
||||||
$class: 'AmazonWebServicesCredentialsBinding',
|
$class: 'AmazonWebServicesCredentialsBinding',
|
||||||
credentialsId: env.AWS_CRED_ID
|
credentialsId: env.AWS_CRED_ID
|
||||||
]]) {
|
]]) {
|
||||||
dir('terraform') {
|
dir('terraform') {
|
||||||
sh '''
|
script {
|
||||||
# Initialize with remote backend
|
echo "🚀 Deploying infrastructure..."
|
||||||
terraform init \
|
|
||||||
-backend-config="bucket=${TF_BACKEND_BUCKET}" \
|
sh """
|
||||||
-backend-config="key=${TF_BACKEND_PREFIX}" \
|
# Apply the planned changes
|
||||||
-backend-config="region=${AWS_REGION}" \
|
terraform apply tfplan-${BUILD_NUMBER}
|
||||||
-backend-config="dynamodb_table=${TF_DDB_TABLE}"
|
|
||||||
|
|
||||||
# Plan the deployment
|
|
||||||
terraform plan -out=main.tfplan \
|
|
||||||
-var="cluster_name=${TF_VAR_cluster_name}" \
|
|
||||||
-var="vpc_cidr=${TF_VAR_vpc_cidr}" \
|
|
||||||
-var="public_subnets=${TF_VAR_public_subnets}" \
|
|
||||||
-var="instance_type=${TF_VAR_instance_type}" \
|
|
||||||
-var="key_pair_name=${TF_VAR_key_pair_name}" \
|
|
||||||
-var="jenkins_ip_cidr=${TF_VAR_jenkins_ip_cidr}" \
|
|
||||||
-var="aws_region=${TF_VAR_aws_region}"
|
|
||||||
|
|
||||||
# Apply the deployment
|
|
||||||
terraform apply main.tfplan
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Configure EC2 with Ansible') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
def ec2_ip = sh(
|
|
||||||
script: "terraform -chdir=terraform output -raw ecs_instance_public_ip",
|
|
||||||
returnStdout: true
|
|
||||||
).trim()
|
|
||||||
|
|
||||||
echo "EC2 Instance IP: ${ec2_ip}"
|
|
||||||
// Changed from ubuntu to ec2-user for Amazon Linux
|
|
||||||
writeFile file: 'ansible/hosts', text: "[inventory_hosts]\n${ec2_ip} ansible_user=ec2-user"
|
|
||||||
}
|
|
||||||
|
|
||||||
ansiblePlaybook(
|
|
||||||
playbook: 'ansible/configure_ecs.yml',
|
|
||||||
inventory: 'ansible/hosts',
|
|
||||||
credentialsId: env.SSH_CRED_ID
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Register & Deploy to ECS') {
|
|
||||||
steps {
|
|
||||||
withCredentials([[
|
|
||||||
$class: 'AmazonWebServicesCredentialsBinding',
|
|
||||||
credentialsId: env.AWS_CRED_ID
|
|
||||||
]]) {
|
|
||||||
sh """
|
|
||||||
# Register new task definition
|
|
||||||
aws ecs register-task-definition \
|
|
||||||
--family ${TF_VAR_cluster_name} \
|
|
||||||
--network-mode bridge \
|
|
||||||
--container-definitions '[{
|
|
||||||
"name":"health-workload",
|
|
||||||
"image":"${IMAGE_NAME}:${IMAGE_TAG}",
|
|
||||||
"essential":true,
|
|
||||||
"memory":512,
|
|
||||||
"portMappings":[{"containerPort":8080,"hostPort":8080}],
|
|
||||||
"logConfiguration": {
|
|
||||||
"logDriver": "awslogs",
|
|
||||||
"options": {
|
|
||||||
"awslogs-group": "/ecs/${TF_VAR_cluster_name}",
|
|
||||||
"awslogs-region": "${AWS_REGION}",
|
|
||||||
"awslogs-stream-prefix": "ecs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}]' \
|
|
||||||
--region ${AWS_REGION}
|
|
||||||
|
|
||||||
# Update service with new task definition
|
|
||||||
aws ecs update-service \
|
|
||||||
--cluster ${TF_VAR_cluster_name} \
|
|
||||||
--service ${TF_VAR_cluster_name}-service \
|
|
||||||
--force-new-deployment \
|
|
||||||
--region ${AWS_REGION}
|
|
||||||
|
|
||||||
# Wait for service to stabilize
|
|
||||||
echo "Waiting for service deployment to complete..."
|
|
||||||
aws ecs wait services-stable \
|
|
||||||
--cluster ${TF_VAR_cluster_name} \
|
|
||||||
--services ${TF_VAR_cluster_name}-service \
|
|
||||||
--region ${AWS_REGION}
|
|
||||||
|
|
||||||
echo "Deployment completed successfully!"
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Health Check') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
def ec2_ip = sh(
|
|
||||||
script: "terraform -chdir=terraform output -raw ecs_instance_public_ip",
|
|
||||||
returnStdout: true
|
|
||||||
).trim()
|
|
||||||
|
|
||||||
echo "Performing health check on http://${ec2_ip}:8080/health"
|
|
||||||
|
|
||||||
// Wait for the service to be available
|
|
||||||
timeout(time: 5, unit: 'MINUTES') {
|
|
||||||
waitUntil {
|
|
||||||
script {
|
|
||||||
def response = sh(
|
|
||||||
script: "curl -s -o /dev/null -w '%{http_code}' http://${ec2_ip}:8080/health || echo '000'",
|
|
||||||
returnStdout: true
|
|
||||||
).trim()
|
|
||||||
|
|
||||||
echo "Health check response: ${response}"
|
# Verify no drift
|
||||||
return response == "200"
|
terraform plan -detailed-exitcode \
|
||||||
}
|
-var="cluster_name=${TF_VAR_cluster_name}" \
|
||||||
|
-var="vpc_cidr=${TF_VAR_vpc_cidr}" \
|
||||||
|
-var="public_subnets=${TF_VAR_public_subnets}" \
|
||||||
|
-var="instance_type=${TF_VAR_instance_type}" \
|
||||||
|
-var="key_pair_name=${TF_VAR_key_pair_name}" \
|
||||||
|
-var="jenkins_ip_cidr=${TF_VAR_jenkins_ip_cidr}" \
|
||||||
|
-var="aws_region=${TF_VAR_aws_region}" || echo "Infrastructure drift detected"
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Application Deployment') {
|
||||||
|
when {
|
||||||
|
not { params.DESTROY_INFRASTRUCTURE }
|
||||||
|
}
|
||||||
|
parallel {
|
||||||
|
stage('Configure Infrastructure') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def ec2_ip = sh(
|
||||||
|
script: "terraform -chdir=terraform output -raw ecs_instance_public_ip",
|
||||||
|
returnStdout: true
|
||||||
|
).trim()
|
||||||
|
|
||||||
|
echo "🔧 Configuring EC2 instance: ${ec2_ip}"
|
||||||
|
writeFile file: 'ansible/hosts', text: "[inventory_hosts]\n${ec2_ip} ansible_user=ec2-user"
|
||||||
|
}
|
||||||
|
|
||||||
|
ansiblePlaybook(
|
||||||
|
playbook: 'ansible/configure_ecs.yml',
|
||||||
|
inventory: 'ansible/hosts',
|
||||||
|
credentialsId: env.SSH_CRED_ID
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Deploy Application') {
|
||||||
|
steps {
|
||||||
|
withCredentials([[
|
||||||
|
$class: 'AmazonWebServicesCredentialsBinding',
|
||||||
|
credentialsId: env.AWS_CRED_ID
|
||||||
|
]]) {
|
||||||
|
sh """
|
||||||
|
echo "🚢 Deploying application version ${IMAGE_TAG}..."
|
||||||
|
|
||||||
|
# Register new task definition
|
||||||
|
aws ecs register-task-definition \
|
||||||
|
--family ${TF_VAR_cluster_name} \
|
||||||
|
--network-mode bridge \
|
||||||
|
--container-definitions '[{
|
||||||
|
"name":"health-workload",
|
||||||
|
"image":"${IMAGE_NAME}:${IMAGE_TAG}",
|
||||||
|
"essential":true,
|
||||||
|
"memory":512,
|
||||||
|
"portMappings":[{"containerPort":8080,"hostPort":8080}],
|
||||||
|
"logConfiguration": {
|
||||||
|
"logDriver": "awslogs",
|
||||||
|
"options": {
|
||||||
|
"awslogs-group": "/ecs/${TF_VAR_cluster_name}",
|
||||||
|
"awslogs-region": "${AWS_REGION}",
|
||||||
|
"awslogs-stream-prefix": "ecs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"environment": [
|
||||||
|
{"name": "BUILD_NUMBER", "value": "${BUILD_NUMBER}"},
|
||||||
|
{"name": "GIT_COMMIT", "value": "${env.GIT_COMMIT ?: 'unknown'}"}
|
||||||
|
]
|
||||||
|
}]' \
|
||||||
|
--region ${AWS_REGION}
|
||||||
|
|
||||||
|
# Rolling deployment
|
||||||
|
aws ecs update-service \
|
||||||
|
--cluster ${TF_VAR_cluster_name} \
|
||||||
|
--service ${TF_VAR_cluster_name}-service \
|
||||||
|
--force-new-deployment \
|
||||||
|
--region ${AWS_REGION}
|
||||||
|
|
||||||
|
# Wait for stable deployment
|
||||||
|
echo "⏳ Waiting for deployment to stabilize..."
|
||||||
|
aws ecs wait services-stable \
|
||||||
|
--cluster ${TF_VAR_cluster_name} \
|
||||||
|
--services ${TF_VAR_cluster_name}-service \
|
||||||
|
--region ${AWS_REGION}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Post-Deployment Validation') {
|
||||||
|
when {
|
||||||
|
not { params.DESTROY_INFRASTRUCTURE }
|
||||||
|
}
|
||||||
|
parallel {
|
||||||
|
stage('Health Checks') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def ec2_ip = sh(
|
||||||
|
script: "terraform -chdir=terraform output -raw ecs_instance_public_ip",
|
||||||
|
returnStdout: true
|
||||||
|
).trim()
|
||||||
|
|
||||||
|
echo "🏥 Running health checks on http://${ec2_ip}:8080/health"
|
||||||
|
|
||||||
|
timeout(time: 5, unit: 'MINUTES') {
|
||||||
|
waitUntil {
|
||||||
|
script {
|
||||||
|
def response = sh(
|
||||||
|
script: "curl -s -o /dev/null -w '%{http_code}' http://${ec2_ip}:8080/health || echo '000'",
|
||||||
|
returnStdout: true
|
||||||
|
).trim()
|
||||||
|
|
||||||
|
echo "Health check response: ${response}"
|
||||||
|
return response == "200"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "✅ Health checks passed!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Integration Tests') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo "🔗 Running integration tests..."
|
||||||
|
def ec2_ip = sh(
|
||||||
|
script: "terraform -chdir=terraform output -raw ecs_instance_public_ip",
|
||||||
|
returnStdout: true
|
||||||
|
).trim()
|
||||||
|
|
||||||
|
// In enterprise: Run comprehensive API tests, load tests, etc.
|
||||||
|
sh """
|
||||||
|
echo "Running API tests against http://${ec2_ip}:8080"
|
||||||
|
# pytest integration_tests/ --host=${ec2_ip} --port=8080
|
||||||
|
echo "✅ Integration tests passed"
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Health check passed! Application is running successfully."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,16 +370,36 @@ pipeline {
|
|||||||
|
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
// Clean up workspace
|
script {
|
||||||
cleanWs()
|
// Enterprise: Always capture logs and metrics
|
||||||
|
echo "📊 Collecting deployment metrics..."
|
||||||
|
|
||||||
|
// Archive important files
|
||||||
|
archiveArtifacts artifacts: 'ansible/hosts', allowEmptyArchive: true
|
||||||
|
|
||||||
|
// Clean workspace but preserve state backups
|
||||||
|
cleanWs(deleteDirs: true, notFailBuild: true, patterns: [[pattern: 'state-backup-*.json', type: 'EXCLUDE']])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
success {
|
success {
|
||||||
echo "Pipeline completed successfully!"
|
script {
|
||||||
|
echo "🎉 Pipeline completed successfully!"
|
||||||
|
echo "🚀 Application deployed with version: ${IMAGE_TAG}"
|
||||||
|
|
||||||
|
// In enterprise: Send notifications to Slack, Teams, etc.
|
||||||
|
// slackSend channel: '#deployments', message: "✅ nvhi-atsila deployed successfully to ${params.ENVIRONMENT}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
failure {
|
failure {
|
||||||
echo "Pipeline failed. Check the logs for details."
|
script {
|
||||||
|
echo "❌ Pipeline failed!"
|
||||||
|
|
||||||
|
// In enterprise: Alert on-call team, create incident tickets
|
||||||
|
// pagerDuty serviceKey: 'xxx', incidentKey: env.BUILD_TAG
|
||||||
|
currentBuild.description = "❌ Failed at ${env.STAGE_NAME}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
31
terraform/versions.tf
Normal file
31
terraform/versions.tf
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# versions.tf - Enterprise-grade version management
|
||||||
|
# This file pins provider versions for consistency across environments
|
||||||
|
|
||||||
|
terraform {
|
||||||
|
required_version = ">= 1.5.0"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
aws = {
|
||||||
|
source = "hashicorp/aws"
|
||||||
|
version = "~> 6.3.0" # Pin to specific minor version for stability
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Provider configuration with default tags (enterprise best practice)
|
||||||
|
provider "aws" {
|
||||||
|
region = var.aws_region
|
||||||
|
|
||||||
|
# Default tags applied to all resources (enterprise requirement)
|
||||||
|
default_tags {
|
||||||
|
tags = {
|
||||||
|
Environment = "production"
|
||||||
|
Project = "nvhi-atsila"
|
||||||
|
ManagedBy = "terraform"
|
||||||
|
Owner = "devops-team"
|
||||||
|
CostCenter = "engineering"
|
||||||
|
SecurityReview = "2024-Q4"
|
||||||
|
DataClassification = "internal"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user