CI / CI (push) Successful in 3m13s
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]>
134 lines
4.3 KiB
YAML
134 lines
4.3 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY: forgejo.riotpiao.com
|
|
IMAGE: forgejo.riotpiao.com/rock/api-gateway
|
|
DOCKER_HOST: tcp://localhost:2375
|
|
|
|
jobs:
|
|
ci:
|
|
name: CI
|
|
runs-on: golang
|
|
steps:
|
|
- name: Install dependencies
|
|
run: |
|
|
apt-get update
|
|
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
|
|
|
|
- name: Go vet
|
|
run: go vet ./...
|
|
|
|
- name: Go test
|
|
run: go test ./...
|
|
|
|
- name: Get short SHA
|
|
id: sha
|
|
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Registry login
|
|
run: |
|
|
echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" \
|
|
--username "${REGISTRY_USER}" --password-stdin
|
|
env:
|
|
REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }}
|
|
REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }}
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
docker build --no-cache \
|
|
-t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \
|
|
-f Dockerfile .
|
|
|
|
- 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 }}
|
|
|
|
- name: Trigger Tekton PipelineRun
|
|
id: tekton
|
|
run: |
|
|
SHA="${{ steps.sha.outputs.short_sha }}"
|
|
RUN_NAME="integration-test-${SHA}"
|
|
|
|
# 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 "✗ 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
|