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
|
||||
31
infrastructure/ci-cd/tekton/tasks/git-clone.yaml
Normal file
31
infrastructure/ci-cd/tekton/tasks/git-clone.yaml
Normal file
@@ -0,0 +1,31 @@
|
||||
# Tekton Git Clone Task for Bakery-IA CI/CD
|
||||
# This task clones the source code repository
|
||||
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: git-clone
|
||||
namespace: tekton-pipelines
|
||||
spec:
|
||||
workspaces:
|
||||
- name: output
|
||||
params:
|
||||
- name: url
|
||||
type: string
|
||||
description: Repository URL to clone
|
||||
- name: revision
|
||||
type: string
|
||||
description: Git revision to checkout
|
||||
default: "main"
|
||||
steps:
|
||||
- name: clone
|
||||
image: alpine/git
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -e
|
||||
echo "Cloning repository: $(params.url)"
|
||||
git clone $(params.url) $(workspaces.output.path)
|
||||
cd $(workspaces.output.path)
|
||||
echo "Checking out revision: $(params.revision)"
|
||||
git checkout $(params.revision)
|
||||
echo "Repository cloned successfully"
|
||||
40
infrastructure/ci-cd/tekton/tasks/kaniko-build.yaml
Normal file
40
infrastructure/ci-cd/tekton/tasks/kaniko-build.yaml
Normal file
@@ -0,0 +1,40 @@
|
||||
# Tekton Kaniko Build Task for Bakery-IA CI/CD
|
||||
# This task builds and pushes container images using Kaniko
|
||||
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: kaniko-build
|
||||
namespace: tekton-pipelines
|
||||
spec:
|
||||
workspaces:
|
||||
- name: source
|
||||
- name: docker-credentials
|
||||
params:
|
||||
- name: services
|
||||
type: string
|
||||
description: Comma-separated list of services to build
|
||||
- name: registry
|
||||
type: string
|
||||
description: Container registry URL
|
||||
default: "gitea.bakery-ia.local:5000"
|
||||
- name: git-revision
|
||||
type: string
|
||||
description: Git revision for image tag
|
||||
default: "latest"
|
||||
steps:
|
||||
- name: build-and-push
|
||||
image: gcr.io/kaniko-project/executor:v1.9.0
|
||||
args:
|
||||
- --dockerfile=$(workspaces.source.path)/services/$(params.services)/Dockerfile
|
||||
- --context=$(workspaces.source.path)
|
||||
- --destination=$(params.registry)/bakery/$(params.services):$(params.git-revision)
|
||||
- --verbosity=info
|
||||
volumeMounts:
|
||||
- name: docker-config
|
||||
mountPath: /kaniko/.docker
|
||||
securityContext:
|
||||
runAsUser: 0
|
||||
volumes:
|
||||
- name: docker-config
|
||||
emptyDir: {}
|
||||
66
infrastructure/ci-cd/tekton/tasks/update-gitops.yaml
Normal file
66
infrastructure/ci-cd/tekton/tasks/update-gitops.yaml
Normal file
@@ -0,0 +1,66 @@
|
||||
# Tekton Update GitOps Manifests Task for Bakery-IA CI/CD
|
||||
# This task updates Kubernetes manifests with new image tags
|
||||
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: update-gitops
|
||||
namespace: tekton-pipelines
|
||||
spec:
|
||||
workspaces:
|
||||
- name: source
|
||||
params:
|
||||
- name: services
|
||||
type: string
|
||||
description: Comma-separated list of services to update
|
||||
- name: registry
|
||||
type: string
|
||||
description: Container registry URL
|
||||
- name: git-revision
|
||||
type: string
|
||||
description: Git revision for image tag
|
||||
steps:
|
||||
- name: update-manifests
|
||||
image: bitnami/kubectl
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -e
|
||||
cd $(workspaces.source.path)
|
||||
|
||||
echo "Updating GitOps manifests for services: $(params.services)"
|
||||
|
||||
# Split services by comma
|
||||
IFS=',' read -ra SERVICES <<< "$(params.services)"
|
||||
|
||||
for service in "${SERVICES[@]}"; do
|
||||
echo "Processing service: $service"
|
||||
|
||||
# Find and update Kubernetes manifests
|
||||
if [ "$service" = "frontend" ]; then
|
||||
# Update frontend deployment
|
||||
if [ -f "infrastructure/kubernetes/overlays/prod/frontend-deployment.yaml" ]; then
|
||||
sed -i "s|image:.*|image: $(params.registry)/bakery/frontend:$(params.git-revision)|g" \
|
||||
"infrastructure/kubernetes/overlays/prod/frontend-deployment.yaml"
|
||||
fi
|
||||
elif [ "$service" = "gateway" ]; then
|
||||
# Update gateway deployment
|
||||
if [ -f "infrastructure/kubernetes/overlays/prod/gateway-deployment.yaml" ]; then
|
||||
sed -i "s|image:.*|image: $(params.registry)/bakery/gateway:$(params.git-revision)|g" \
|
||||
"infrastructure/kubernetes/overlays/prod/gateway-deployment.yaml"
|
||||
fi
|
||||
else
|
||||
# Update service deployment
|
||||
DEPLOYMENT_FILE="infrastructure/kubernetes/overlays/prod/${service}-deployment.yaml"
|
||||
if [ -f "$DEPLOYMENT_FILE" ]; then
|
||||
sed -i "s|image:.*|image: $(params.registry)/bakery/${service}:$(params.git-revision)|g" \
|
||||
"$DEPLOYMENT_FILE"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Commit changes
|
||||
git config --global user.name "bakery-ia-ci"
|
||||
git config --global user.email "ci@bakery-ia.local"
|
||||
git add .
|
||||
git commit -m "CI: Update image tags for $(params.services) to $(params.git-revision)"
|
||||
git push origin HEAD
|
||||
Reference in New Issue
Block a user