CI / CI (pull_request) Failing after 3m38s
Implement Kubernetes-native CI/CD with Tekton Pipelines: ARCHITECTURE: - Tekton Task: Runs integration tests in container - Tekton Pipeline: Orchestrates test execution - ArgoCD Application: Manages Tekton installation - CI: Triggers PipelineRun, reads results, promotes image FLOW: 1. CI builds image:sha 2. CI creates PipelineRun with new image 3. Tekton controller watches PipelineRun 4. Task executes integration tests 5. Results written to PipelineRun status 6. CI reads status, promotes to :latest if pass 7. ArgoCD detects :latest change and deploys BENEFITS: ✓ Kubernetes-native (CRDs, no external dependencies) ✓ DRY (parameterized Task/Pipeline) ✓ SOLID (single responsibility, clean interfaces) ✓ GitOps (Tekton managed by ArgoCD) ✓ Observable (logs, status, results) ✓ Secure (non-root, resource limits) FILES: - k8s/tekton/task-integration-test.yaml: Task definition - k8s/tekton/pipeline-integration-test.yaml: Pipeline definition - k8s/tekton/kustomization.yaml: Kustomize management - k8s/tekton/README.md: Documentation - k8s/argocd-apps/tekton.yaml: ArgoCD Application - .gitea/workflows/ci.yaml: Updated CI to use Tekton NEXT: 1. Merge PR 2. ArgoCD syncs and installs Tekton 3. First git push triggers PipelineRun 4. Integration tests run in cluster 5. Results feedback to CI
86 lines
2.1 KiB
YAML
86 lines
2.1 KiB
YAML
apiVersion: tekton.dev/v1
|
|
kind: Task
|
|
metadata:
|
|
name: integration-test
|
|
namespace: api
|
|
labels:
|
|
app: api-gateway
|
|
component: testing
|
|
spec:
|
|
description: Run integration tests for API gateway
|
|
params:
|
|
- name: image
|
|
type: string
|
|
description: Container image to test (including tag)
|
|
- name: timeout
|
|
type: string
|
|
default: "5m"
|
|
description: Test timeout
|
|
results:
|
|
- name: result
|
|
description: Test result (pass/fail)
|
|
type: string
|
|
- name: message
|
|
description: Test summary message
|
|
type: string
|
|
steps:
|
|
- name: run-tests
|
|
image: $(params.image)
|
|
securityContext:
|
|
runAsNonRoot: true
|
|
runAsUser: 65532
|
|
allowPrivilegeEscalation: false
|
|
env:
|
|
- name: GATEWAY_URL
|
|
value: "http://api-gateway:8080"
|
|
- name: CI
|
|
value: "true"
|
|
script: |
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
echo "🧪 Starting integration tests..."
|
|
echo "Image: $(params.image)"
|
|
echo "Gateway: $GATEWAY_URL"
|
|
echo ""
|
|
|
|
# Wait for gateway to be ready
|
|
echo "Waiting for gateway service..."
|
|
for i in $(seq 1 30); do
|
|
if curl -s $GATEWAY_URL/healthz > /dev/null 2>&1; then
|
|
echo "✓ Gateway is ready"
|
|
break
|
|
fi
|
|
echo "Attempt $i/30: Waiting for gateway..."
|
|
sleep 2
|
|
done
|
|
|
|
# Run integration tests
|
|
echo "Running integration tests..."
|
|
if go test -v -tags=integration -timeout=$(params.timeout) ./internal/integration/...; then
|
|
echo "pass" | tee $(results.result.path)
|
|
echo "✓ All integration tests passed" | tee $(results.message.path)
|
|
exit 0
|
|
else
|
|
echo "fail" | tee $(results.result.path)
|
|
echo "✗ Some integration tests failed" | tee $(results.message.path)
|
|
exit 1
|
|
fi
|
|
volumeMounts:
|
|
- name: tmp
|
|
mountPath: /tmp
|
|
- name: home
|
|
mountPath: /home/nonroot
|
|
resources:
|
|
requests:
|
|
cpu: 250m
|
|
memory: 512Mi
|
|
limits:
|
|
cpu: 500m
|
|
memory: 1Gi
|
|
volumes:
|
|
- name: tmp
|
|
emptyDir: {}
|
|
- name: home
|
|
emptyDir: {}
|