# Tekton Update GitOps Task for Bakery-IA CI/CD # This task updates GitOps manifests with new image tags apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: update-gitops namespace: {{ .Values.namespace }} labels: app.kubernetes.io/name: {{ .Values.labels.app.name }} app.kubernetes.io/component: gitops spec: workspaces: - name: source description: Workspace containing the source code - name: git-credentials description: Git credentials for pushing changes 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 to tag images with - name: git-branch type: string description: Git branch to push changes to - name: dry-run type: string description: Dry run mode - don't push changes default: "false" steps: - name: update-manifests image: alpine/git:2.43.0 workingDir: $(workspaces.source.path) env: - name: GIT_USERNAME valueFrom: secretKeyRef: name: gitea-git-credentials key: username - name: GIT_PASSWORD valueFrom: secretKeyRef: name: gitea-git-credentials key: password script: | #!/bin/bash set -e echo "============================================" echo "Updating GitOps Manifests" echo "Services: $(params.services)" echo "Registry: $(params.registry)" echo "Revision: $(params.git-revision)" echo "Branch: $(params.git-branch)" echo "Dry run: $(params.dry-run)" echo "============================================" # Configure git git config --global user.email "ci@bakery-ia.local" git config --global user.name "bakery-ia-ci" # Clone the GitOps repository REPO_URL="https://${GIT_USERNAME}:${GIT_PASSWORD}@gitea.bakery-ia.local/bakery/bakery-ia-gitops.git" git clone "$REPO_URL" /tmp/gitops cd /tmp/gitops # Switch to target branch git checkout "$(params.git-branch)" || git checkout -b "$(params.git-branch)" # Update image tags in Kubernetes manifests for service in $(echo "$(params.services)" | tr ',' '\n'); do echo "Updating manifest for service: $service" # Find and update the image tag in the deployment YAML if [ -f "deployments/${service}-deployment.yaml" ]; then sed -i "s|image: bakery/${service}:.*|image: $(params.registry)/bakery/${service}:$(params.git-revision)|g" "deployments/${service}-deployment.yaml" fi done # Commit and push changes (unless dry-run) if [ "$(params.dry-run)" != "true" ]; then git add . git commit -m "Update images for services: $(params.services) [skip ci]" git push origin "$(params.git-branch)" echo "GitOps manifests updated successfully" else echo "Dry run mode - changes not pushed" git status git diff fi resources: limits: cpu: 500m memory: 512Mi requests: cpu: 100m memory: 128Mi