Files
bakery-ia/infrastructure/cicd/tekton-helm/templates/task-kaniko-build.yaml

103 lines
3.8 KiB
YAML
Raw Normal View History

2026-01-19 13:57:50 +01:00
# Tekton Kaniko Build Task for Bakery-IA CI/CD
# This task builds and pushes container images using Kaniko
2026-01-19 16:31:11 +01:00
# Supports environment-configurable base images via build-args
2026-01-19 13:57:50 +01:00
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kaniko-build
namespace: {{ .Values.namespace }}
labels:
app.kubernetes.io/name: {{ .Values.labels.app.name }}
app.kubernetes.io/component: build
spec:
workspaces:
- name: source
description: Workspace containing the source code
- name: docker-credentials
description: Docker registry credentials
params:
- name: services
type: string
description: Comma-separated list of services to build
- name: registry
type: string
2026-01-19 16:31:11 +01:00
description: Container registry URL for pushing built images
2026-01-19 13:57:50 +01:00
- name: git-revision
type: string
description: Git revision to tag images with
2026-01-19 16:31:11 +01:00
- name: base-registry
type: string
description: Base image registry URL (e.g., docker.io, ghcr.io/org)
default: "docker.io"
- name: python-image
type: string
description: Python base image name and tag
default: "python:3.11-slim"
2026-01-19 13:57:50 +01:00
results:
- name: build-status
description: Status of the build operation
steps:
- name: build-and-push
image: gcr.io/kaniko-project/executor:v1.15.0
env:
- name: DOCKER_CONFIG
value: /tekton/home/.docker
2026-01-19 14:22:07 +01:00
script: |
#!/bin/bash
set -e
2026-01-19 16:31:11 +01:00
echo "==================================================================="
echo "Kaniko Build Configuration"
echo "==================================================================="
echo "Target Registry: $(params.registry)"
echo "Base Registry: $(params.base-registry)"
echo "Python Image: $(params.python-image)"
echo "Git Revision: $(params.git-revision)"
echo "==================================================================="
2026-01-19 14:22:07 +01:00
# Split services parameter by comma
IFS=',' read -ra SERVICES <<< "$(params.services)"
2026-01-19 16:31:11 +01:00
2026-01-19 14:22:07 +01:00
# Build each service
for service in "${SERVICES[@]}"; do
service=$(echo "$service" | xargs) # Trim whitespace
if [ -n "$service" ] && [ "$service" != "none" ]; then
2026-01-19 16:31:11 +01:00
echo ""
2026-01-19 14:22:07 +01:00
echo "Building service: $service"
2026-01-19 16:31:11 +01:00
echo "-------------------------------------------------------------------"
2026-01-20 10:39:40 +01:00
# Determine Dockerfile path (services vs gateway vs frontend)
2026-01-19 16:31:11 +01:00
if [ "$service" = "gateway" ]; then
DOCKERFILE_PATH="$(workspaces.source.path)/gateway/Dockerfile"
2026-01-20 10:39:40 +01:00
elif [ "$service" = "frontend" ]; then
DOCKERFILE_PATH="$(workspaces.source.path)/frontend/Dockerfile.kubernetes"
2026-01-19 16:31:11 +01:00
else
DOCKERFILE_PATH="$(workspaces.source.path)/services/$service/Dockerfile"
fi
2026-01-19 14:22:07 +01:00
/kaniko/executor \
2026-01-19 16:31:11 +01:00
--dockerfile="$DOCKERFILE_PATH" \
2026-01-19 14:22:07 +01:00
--destination="$(params.registry)/$service:$(params.git-revision)" \
--context="$(workspaces.source.path)" \
2026-01-19 16:31:11 +01:00
--build-arg="BASE_REGISTRY=$(params.base-registry)" \
--build-arg="PYTHON_IMAGE=$(params.python-image)" \
2026-01-19 14:22:07 +01:00
--cache=true \
--cache-repo="$(params.registry)/cache"
2026-01-19 16:31:11 +01:00
echo "Successfully built: $(params.registry)/$service:$(params.git-revision)"
2026-01-19 14:22:07 +01:00
fi
done
2026-01-19 16:31:11 +01:00
echo ""
echo "==================================================================="
echo "Build completed successfully!"
echo "==================================================================="
2026-01-19 14:22:07 +01:00
echo "success" > $(results.build-status.path)
2026-01-19 13:57:50 +01:00
resources:
limits:
cpu: 2000m
memory: 4Gi
requests:
cpu: 500m
memory: 1Gi