automated terminal push

This commit is contained in:
lenape
2025-08-06 15:29:50 +00:00
parent 334c7097b3
commit 8e4543267e

View File

@@ -278,45 +278,50 @@ with app.test_client() as client:
echo "ECR Repository: ${ECR_REPO_URI}"
echo "Image Tag: ${IMAGE_TAG}"
# Login to ECR
echo "🔐 Logging into ECR..."
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY
# Check if ECR repository exists FIRST (before login)
echo "📦 Checking if ECR repository exists..."
if aws ecr describe-repositories --repository-names ${ECR_REPO_NAME} --region ${AWS_REGION} 2>/dev/null; then
echo "✅ ECR repository exists - proceeding with Docker operations"
# Check if ECR repository exists, create if not
echo "📦 Checking ECR repository..."
if ! aws ecr describe-repositories --repository-names $ECR_REPO_NAME --region $AWS_REGION 2>/dev/null; then
echo "🏗️ Creating ECR repository..."
aws ecr create-repository --repository-name $ECR_REPO_NAME --region $AWS_REGION
fi
# Login to ECR only if repository exists
echo "🔐 Logging into ECR..."
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
# Build Docker image
echo "🔨 Building Docker image..."
docker build -t $ECR_REPO_NAME:${IMAGE_TAG} .
docker build -t $ECR_REPO_NAME:build-${BUILD_NUMBER} .
docker build -t ${ECR_REPO_NAME}:${IMAGE_TAG} .
docker build -t ${ECR_REPO_NAME}:build-${BUILD_NUMBER} .
# Tag for ECR
docker tag $ECR_REPO_NAME:${IMAGE_TAG} $ECR_REPO_URI:${IMAGE_TAG}
docker tag $ECR_REPO_NAME:${IMAGE_TAG} $ECR_REPO_URI:build-${BUILD_NUMBER}
docker tag ${ECR_REPO_NAME}:${IMAGE_TAG} ${ECR_REPO_URI}:${IMAGE_TAG}
docker tag ${ECR_REPO_NAME}:${IMAGE_TAG} ${ECR_REPO_URI}:build-${BUILD_NUMBER}
# Push to ECR
echo "🚀 Pushing to ECR..."
docker push $ECR_REPO_URI:${IMAGE_TAG}
docker push $ECR_REPO_URI:build-${BUILD_NUMBER}
docker push ${ECR_REPO_URI}:${IMAGE_TAG}
docker push ${ECR_REPO_URI}:build-${BUILD_NUMBER}
# Clean up local images
docker rmi $ECR_REPO_NAME:${IMAGE_TAG} || true
docker rmi $ECR_REPO_NAME:build-${BUILD_NUMBER} || true
docker rmi $ECR_REPO_URI:${IMAGE_TAG} || true
docker rmi $ECR_REPO_URI:build-${BUILD_NUMBER} || true
docker rmi ${ECR_REPO_NAME}:${IMAGE_TAG} || true
docker rmi ${ECR_REPO_NAME}:build-${BUILD_NUMBER} || true
docker rmi ${ECR_REPO_URI}:${IMAGE_TAG} || true
docker rmi ${ECR_REPO_URI}:build-${BUILD_NUMBER} || true
echo "✅ Docker build and push completed"
echo "📍 Image available at: $ECR_REPO_URI:${IMAGE_TAG}"
echo "📍 Image available at: ${ECR_REPO_URI}:${IMAGE_TAG}"
else
echo "⚠️ ECR repository '${ECR_REPO_NAME}' doesn't exist yet"
echo "📝 Terraform will create it in the Apply stage"
echo "⏭️ Skipping Docker build/push for this initial deployment"
echo ""
echo " NOTE: After this pipeline completes, the ECR repository will exist."
echo " Run the pipeline again to build and push the Docker image."
fi
'''
}
}
}
}
stage('🚀 Infrastructure Bootstrap') {
when {
not { equals expected: 'destroy', actual: params.ACTION }