|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2024 The Tekton Authors |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# E2e test for Tekton Bundle publishing. |
| 18 | +# Pushes the task as a bundle to ttl.sh, then runs a TaskRun that |
| 19 | +# references it via the bundle resolver. |
| 20 | +# |
| 21 | +# Environment variables: |
| 22 | +# PIPELINE_VERSION - Tekton Pipelines version to install (default: v1.12.0) |
| 23 | +# TIMEOUT - Timeout for TaskRun (default: 120s) |
| 24 | +# GIT_INIT_IMAGE - Override the gitInitImage in the task (optional) |
| 25 | +# BUNDLE_REGISTRY - Registry to push bundles to (default: ttl.sh) |
| 26 | + |
| 27 | +set -euo pipefail |
| 28 | + |
| 29 | +PIPELINE_VERSION="${PIPELINE_VERSION:-v1.12.0}" |
| 30 | +TIMEOUT="${TIMEOUT:-120s}" |
| 31 | +BUNDLE_REGISTRY="${BUNDLE_REGISTRY:-ttl.sh}" |
| 32 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 33 | +ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" |
| 34 | + |
| 35 | +# Generate a unique bundle reference |
| 36 | +BUNDLE_REF="${BUNDLE_REGISTRY}/git-clone-e2e-$(head -c 8 /proc/sys/kernel/random/uuid):1h" |
| 37 | + |
| 38 | +echo "--- Installing Tekton Pipelines ${PIPELINE_VERSION}" |
| 39 | +kubectl apply --filename "https://github.com/tektoncd/pipeline/releases/download/${PIPELINE_VERSION}/release.yaml" |
| 40 | +echo "--- Waiting for Tekton Pipelines to be ready" |
| 41 | +kubectl wait --for=condition=available --timeout=120s deployment/tekton-pipelines-controller -n tekton-pipelines |
| 42 | +kubectl wait --for=condition=available --timeout=120s deployment/tekton-pipelines-webhook -n tekton-pipelines |
| 43 | + |
| 44 | +# Prepare the task YAML (with optional image override) |
| 45 | +TASK_YAML=$(mktemp) |
| 46 | +if [[ -n "${GIT_INIT_IMAGE:-}" ]]; then |
| 47 | + echo " Using locally built image: ${GIT_INIT_IMAGE}" |
| 48 | + sed "s|ghcr.io/tektoncd-catalog/git-clone:[^ \"]*|${GIT_INIT_IMAGE}|g" \ |
| 49 | + "${ROOT_DIR}/task/git-clone/git-clone.yaml" > "${TASK_YAML}" |
| 50 | +else |
| 51 | + cp "${ROOT_DIR}/task/git-clone/git-clone.yaml" "${TASK_YAML}" |
| 52 | +fi |
| 53 | + |
| 54 | +echo "--- Pushing Tekton Bundle to ${BUNDLE_REF}" |
| 55 | +tkn bundle push "${BUNDLE_REF}" -f "${TASK_YAML}" |
| 56 | + |
| 57 | +echo "--- Creating TaskRun using bundle resolver" |
| 58 | +cat <<EOF | kubectl apply -f - |
| 59 | +apiVersion: tekton.dev/v1 |
| 60 | +kind: TaskRun |
| 61 | +metadata: |
| 62 | + name: git-clone-bundle-test |
| 63 | +spec: |
| 64 | + taskRef: |
| 65 | + resolver: bundles |
| 66 | + params: |
| 67 | + - name: bundle |
| 68 | + value: ${BUNDLE_REF} |
| 69 | + - name: name |
| 70 | + value: git-clone |
| 71 | + - name: kind |
| 72 | + value: task |
| 73 | + workspaces: |
| 74 | + - name: output |
| 75 | + emptyDir: {} |
| 76 | + podTemplate: |
| 77 | + securityContext: |
| 78 | + fsGroup: 65532 |
| 79 | + params: |
| 80 | + - name: url |
| 81 | + value: https://github.com/kelseyhightower/nocode |
| 82 | +EOF |
| 83 | + |
| 84 | +echo "--- Waiting for TaskRun to complete (timeout: ${TIMEOUT})" |
| 85 | +if kubectl wait --for=condition=Succeeded --timeout="${TIMEOUT}" taskrun/git-clone-bundle-test 2>/dev/null; then |
| 86 | + echo "" |
| 87 | + echo "=== Bundle test PASSED ===" |
| 88 | +else |
| 89 | + echo "" |
| 90 | + echo "=== Bundle test FAILED ===" |
| 91 | + kubectl get taskrun/git-clone-bundle-test -o jsonpath='{.status.conditions[*].message}' 2>/dev/null || true |
| 92 | + echo "" |
| 93 | + pod=$(kubectl get taskrun/git-clone-bundle-test -o jsonpath='{.status.podName}' 2>/dev/null) |
| 94 | + if [[ -n "${pod}" ]]; then |
| 95 | + kubectl logs "${pod}" --all-containers 2>/dev/null || true |
| 96 | + fi |
| 97 | + exit 1 |
| 98 | +fi |
| 99 | + |
| 100 | +rm -f "${TASK_YAML}" |
0 commit comments