92 lines
2.6 KiB
YAML
92 lines
2.6 KiB
YAML
|
|
# Task to verify images exist in the registry before deploying
|
||
|
|
apiVersion: tekton.dev/v1beta1
|
||
|
|
kind: Task
|
||
|
|
metadata:
|
||
|
|
name: verify-images
|
||
|
|
namespace: tekton-pipelines
|
||
|
|
labels:
|
||
|
|
app.kubernetes.io/name: bakery-ia-cicd
|
||
|
|
app.kubernetes.io/component: validation
|
||
|
|
spec:
|
||
|
|
params:
|
||
|
|
- name: services
|
||
|
|
type: string
|
||
|
|
description: Comma-separated list of services to verify
|
||
|
|
- name: registry
|
||
|
|
type: string
|
||
|
|
description: Container registry URL
|
||
|
|
- name: git-revision
|
||
|
|
type: string
|
||
|
|
description: Git revision/tag to verify
|
||
|
|
results:
|
||
|
|
- name: verification-status
|
||
|
|
description: Status of image verification (success/failed)
|
||
|
|
- name: missing-images
|
||
|
|
description: List of images that were not found
|
||
|
|
steps:
|
||
|
|
- name: verify
|
||
|
|
image: gcr.io/go-containerregistry/crane:latest
|
||
|
|
script: |
|
||
|
|
#!/bin/sh
|
||
|
|
set -e
|
||
|
|
|
||
|
|
SERVICES="$(params.services)"
|
||
|
|
REGISTRY="$(params.registry)"
|
||
|
|
REVISION="$(params.git-revision)"
|
||
|
|
MISSING=""
|
||
|
|
|
||
|
|
echo "============================================"
|
||
|
|
echo "Verifying Images in Registry"
|
||
|
|
echo "============================================"
|
||
|
|
echo "Registry: $REGISTRY"
|
||
|
|
echo "Revision: $REVISION"
|
||
|
|
echo "Services: $SERVICES"
|
||
|
|
echo "============================================"
|
||
|
|
|
||
|
|
# Convert comma-separated list to space-separated
|
||
|
|
SERVICES_LIST=$(echo "$SERVICES" | tr ',' ' ')
|
||
|
|
|
||
|
|
for SERVICE in $SERVICES_LIST; do
|
||
|
|
SERVICE=$(echo "$SERVICE" | tr -d ' ')
|
||
|
|
|
||
|
|
if [ "$SERVICE" = "infrastructure" ]; then
|
||
|
|
continue
|
||
|
|
fi
|
||
|
|
|
||
|
|
IMAGE="$REGISTRY/bakery/$SERVICE:$REVISION"
|
||
|
|
echo ""
|
||
|
|
echo "Checking: $IMAGE"
|
||
|
|
|
||
|
|
if crane manifest "$IMAGE" > /dev/null 2>&1; then
|
||
|
|
echo " ✓ Found"
|
||
|
|
else
|
||
|
|
echo " ✗ NOT FOUND"
|
||
|
|
if [ -z "$MISSING" ]; then
|
||
|
|
MISSING="$SERVICE"
|
||
|
|
else
|
||
|
|
MISSING="$MISSING,$SERVICE"
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo "============================================"
|
||
|
|
|
||
|
|
if [ -n "$MISSING" ]; then
|
||
|
|
echo "ERROR: Missing images: $MISSING"
|
||
|
|
echo "failed" > $(results.verification-status.path)
|
||
|
|
echo "$MISSING" > $(results.missing-images.path)
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "All images verified successfully"
|
||
|
|
echo "success" > $(results.verification-status.path)
|
||
|
|
echo "none" > $(results.missing-images.path)
|
||
|
|
resources:
|
||
|
|
limits:
|
||
|
|
cpu: 200m
|
||
|
|
memory: 128Mi
|
||
|
|
requests:
|
||
|
|
cpu: 100m
|
||
|
|
memory: 64Mi
|