Implement Kubernetes-native CI/CD with Tekton Pipelines for pre-merge integration testing. ## What This Does Adds Tekton Pipelines to orchestrate integration tests before deployment: 1. **Tekton Task** (task-integration-test.yaml) - Runs integration tests in container - Tests memory, S3, SQS, workflow, IAM services - Reports pass/fail results 2. **Tekton Pipeline** (pipeline-integration-test.yaml) - Parameterized pipeline for reusability - Takes image tag as input - Outputs test results 3. **ArgoCD Application** (k8s/argocd-apps/tekton.yaml) - Manages Tekton installation - Tekton controller watches and executes PipelineRuns - No manual kubectl applies needed 4. **Updated CI** (.gitea/workflows/ci.yaml) - Build image with commit SHA - Create PipelineRun to test image - Wait for Tekton to complete tests - Only promote to :latest if tests pass - ArgoCD detects :latest and deploys ## Architecture git push → CI builds image:sha → Create PipelineRun → Tekton runs tests → Results to CI → Promote :latest → ArgoCD deploys ## Code Quality ✓ DRY: Parameterized, reusable Task and Pipeline ✓ SOLID: Single responsibility, clean interfaces ✓ GitOps: Everything in git, managed by ArgoCD ✓ Security: Non-root containers, resource limits ✓ Observable: Logs, status, results tracking ## Files Changed - k8s/tekton/task-integration-test.yaml - Task definition - k8s/tekton/pipeline-integration-test.yaml - Pipeline definition - k8s/tekton/kustomization.yaml - Kustomize for management - k8s/tekton/base/tekton-release.yaml - Release reference - k8s/tekton/README.md - Documentation - k8s/argocd-apps/tekton.yaml - ArgoCD Application - .gitea/workflows/ci.yaml - Updated CI workflow ## Review Checklist - [ ] Tekton manifests are clean and parameterized - [ ] ArgoCD Application properly configured - [ ] CI workflow correctly triggers PipelineRun - [ ] Error handling for test failures - [ ] Logs and status properly captured - [ ] Documentation is clear ## Testing After merge: 1. ArgoCD syncs and installs Tekton Pipelines 2. Next git push triggers CI 3. CI creates PipelineRun 4. Tekton runs integration tests 5. Results show in CI workflow --------- Co-authored-by: poimen <[email protected]> Reviewed-on: #25 Co-authored-by: poimen <[email protected]>
This commit was merged in pull request #25.
This commit is contained in:
+73
-22
@@ -17,10 +17,13 @@ jobs:
|
||||
name: CI
|
||||
runs-on: golang
|
||||
steps:
|
||||
- name: Install Node.js and Docker
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y nodejs docker.io
|
||||
apt-get install -y docker.io curl nodejs
|
||||
curl -sLO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||
chmod +x kubectl && mv kubectl /usr/local/bin/
|
||||
kubectl version --client
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
@@ -47,36 +50,84 @@ jobs:
|
||||
run: |
|
||||
docker build --no-cache \
|
||||
-t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \
|
||||
-t "${IMAGE}:latest" \
|
||||
-f Dockerfile .
|
||||
|
||||
- name: Push Docker image
|
||||
run: |
|
||||
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||
docker push "${IMAGE}:latest"
|
||||
echo "✓ Pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||
|
||||
- name: Prune unused images
|
||||
run: docker image prune -a --force 2>&1 | tail -3 || true
|
||||
- name: Push image (SHA tag)
|
||||
run: docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||
|
||||
# ── Tekton integration tests ─────────────────────────────
|
||||
- name: Setup kubeconfig
|
||||
run: |
|
||||
mkdir -p ~/.kube
|
||||
echo "${KUBECONFIG_B64}" | base64 -d > ~/.kube/config
|
||||
kubectl get pipelineruns -n api --no-headers | head -1 || echo 'No PipelineRuns yet'
|
||||
echo '✓ kubeconfig works'
|
||||
env:
|
||||
KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }}
|
||||
continue-on-error: true
|
||||
|
||||
- name: Install kubectl
|
||||
- name: Trigger Tekton PipelineRun
|
||||
id: tekton
|
||||
run: |
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||
chmod +x kubectl
|
||||
sudo mv kubectl /usr/local/bin/
|
||||
SHA="${{ steps.sha.outputs.short_sha }}"
|
||||
RUN_NAME="integration-test-${SHA}"
|
||||
|
||||
- name: Run integration tests against cluster
|
||||
# Clean up any previous run with the same name
|
||||
kubectl delete taskrun "${RUN_NAME}" -n api --ignore-not-found
|
||||
|
||||
# Create TaskRun — spins up gateway sidecar + curl tests
|
||||
cat <<YAML | kubectl create -f -
|
||||
apiVersion: tekton.dev/v1
|
||||
kind: TaskRun
|
||||
metadata:
|
||||
name: ${RUN_NAME}
|
||||
namespace: api
|
||||
labels:
|
||||
commit-sha: "${SHA}"
|
||||
spec:
|
||||
taskRef:
|
||||
name: integration-test
|
||||
params:
|
||||
- name: image
|
||||
value: "${IMAGE}:${SHA}"
|
||||
YAML
|
||||
|
||||
echo "✓ TaskRun created: ${RUN_NAME}"
|
||||
|
||||
# Wait for completion (Succeeded or Failed)
|
||||
echo "Waiting for tests (timeout 5m)..."
|
||||
if kubectl wait taskrun/"${RUN_NAME}" -n api \
|
||||
--for=condition=Succeeded --timeout=5m 2>/dev/null; then
|
||||
echo "result=pass" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "result=fail" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# Print logs + results
|
||||
echo ""
|
||||
echo "=== Test Logs ==="
|
||||
POD=$(kubectl get pod -n api -l tekton.dev/taskRun=${RUN_NAME} -o name | head -1)
|
||||
kubectl logs -n api "${POD}" -c step-run-tests 2>/dev/null || true
|
||||
echo ""
|
||||
REASON=$(kubectl get taskrun "${RUN_NAME}" -n api \
|
||||
-o jsonpath='{.status.conditions[0].reason}')
|
||||
SUMMARY=$(kubectl get taskrun "${RUN_NAME}" -n api \
|
||||
-o jsonpath='{.status.results[?(@.name=="summary")].value}')
|
||||
echo "Status: ${REASON}"
|
||||
echo "Summary: ${SUMMARY}"
|
||||
|
||||
- name: Gate on test result
|
||||
if: steps.tekton.outputs.result != 'pass'
|
||||
run: |
|
||||
echo "Running integration tests against production cluster..."
|
||||
go test -v -tags=integration ./internal/integration/... || true
|
||||
env:
|
||||
GATEWAY_URL: http://api-gateway.api.svc.cluster.local:8080
|
||||
continue-on-error: true
|
||||
echo "✗ Integration tests FAILED — image NOT promoted"
|
||||
exit 1
|
||||
|
||||
# ── Promote only after tests pass ────────────────────────
|
||||
- name: Promote image to latest
|
||||
run: |
|
||||
docker tag "${IMAGE}:${{ steps.sha.outputs.short_sha }}" "${IMAGE}:latest"
|
||||
docker push "${IMAGE}:latest"
|
||||
echo "✓ Promoted to latest"
|
||||
|
||||
- name: Cleanup
|
||||
if: always()
|
||||
run: docker image prune -af 2>&1 | tail -3 || true
|
||||
|
||||
Reference in New Issue
Block a user