Add ci/cd and fix multiple pods issues
This commit is contained in:
64
infrastructure/ci-cd/tekton/tasks/detect-changes.yaml
Normal file
64
infrastructure/ci-cd/tekton/tasks/detect-changes.yaml
Normal file
@@ -0,0 +1,64 @@
|
||||
# Tekton Detect Changed Services Task for Bakery-IA CI/CD
|
||||
# This task identifies which services have changed in the repository
|
||||
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: detect-changed-services
|
||||
namespace: tekton-pipelines
|
||||
spec:
|
||||
workspaces:
|
||||
- name: source
|
||||
results:
|
||||
- name: changed-services
|
||||
description: Comma-separated list of changed services
|
||||
steps:
|
||||
- name: detect
|
||||
image: alpine/git
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -e
|
||||
cd $(workspaces.source.path)
|
||||
|
||||
echo "Detecting changed files..."
|
||||
# Get list of changed files compared to previous commit
|
||||
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || git diff --name-only HEAD)
|
||||
|
||||
echo "Changed files: $CHANGED_FILES"
|
||||
|
||||
# Map files to services
|
||||
CHANGED_SERVICES=()
|
||||
for file in $CHANGED_FILES; do
|
||||
if [[ $file == services/* ]]; then
|
||||
SERVICE=$(echo $file | cut -d'/' -f2)
|
||||
# Only add unique service names
|
||||
if [[ ! " ${CHANGED_SERVICES[@]} " =~ " ${SERVICE} " ]]; then
|
||||
CHANGED_SERVICES+=("$SERVICE")
|
||||
fi
|
||||
elif [[ $file == frontend/* ]]; then
|
||||
CHANGED_SERVICES+=("frontend")
|
||||
break
|
||||
elif [[ $file == gateway/* ]]; then
|
||||
CHANGED_SERVICES+=("gateway")
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# If no specific services changed, check for infrastructure changes
|
||||
if [ ${#CHANGED_SERVICES[@]} -eq 0 ]; then
|
||||
for file in $CHANGED_FILES; do
|
||||
if [[ $file == infrastructure/* ]]; then
|
||||
CHANGED_SERVICES+=("infrastructure")
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Output result
|
||||
if [ ${#CHANGED_SERVICES[@]} -eq 0 ]; then
|
||||
echo "No service changes detected"
|
||||
echo "none" | tee $(results.changed-services.path)
|
||||
else
|
||||
echo "Detected changes in services: ${CHANGED_SERVICES[@]}"
|
||||
echo $(printf "%s," "${CHANGED_SERVICES[@]}" | sed 's/,$//') | tee $(results.changed-services.path)
|
||||
fi
|
||||
Reference in New Issue
Block a user