This document describes the Continuous Integration and Continuous Deployment (CI/CD) pipeline for LinX (灵枢).
The platform uses GitHub Actions for CI/CD automation. The pipeline includes:
- Automated Testing: Unit tests, integration tests, and code quality checks
- Security Scanning: Vulnerability scanning with Snyk, Trivy, and CodeQL
- Docker Image Building: Multi-platform Docker images for all services
- Automated Deployment: Staging and production deployments
- Release Automation: Automated release creation and artifact generation
Triggers:
- Push to
mainordevelopbranches (backend changes) - Pull requests to
mainordevelop(backend changes)
Jobs:
-
test: Runs tests on Python 3.11 and 3.12
- Sets up PostgreSQL and Redis services
- Installs system dependencies (Tesseract, FFmpeg)
- Runs linting (flake8)
- Runs type checking (mypy)
- Runs tests with coverage (pytest)
- Uploads coverage to Codecov
-
security-scan: Security analysis
- Runs Bandit for security issues
- Runs Safety for dependency vulnerabilities
-
code-quality: Code formatting checks
- Checks Black formatting
- Checks isort import sorting
Required Secrets: None (uses GitHub token)
Triggers:
- Push to
mainordevelopbranches (frontend changes) - Pull requests to
mainordevelop(frontend changes)
Jobs:
-
test: Runs tests on Node.js 20.x and 22.x
- Installs dependencies
- Runs linting (ESLint)
- Runs type checking (TypeScript)
- Runs tests with coverage
- Builds application
- Checks bundle size
-
lighthouse: Performance testing
- Runs Lighthouse CI for performance metrics
-
security-scan: Security analysis
- Runs npm audit
-
code-quality: Code formatting checks
- Checks Prettier formatting
Required Secrets: None
Triggers:
- Push to
mainordevelopbranches - Push tags matching
v* - Pull requests to
main
Jobs:
-
build-backend-images: Builds backend service images
- api-gateway
- task-manager
- agent-runtime
- document-processor
- Multi-platform builds (amd64, arm64)
-
build-frontend-image: Builds frontend image
- Multi-platform build (amd64, arm64)
-
scan-images: Scans images for vulnerabilities
- Runs Trivy on all images
- Uploads results to GitHub Security
Required Secrets:
GITHUB_TOKEN(automatically provided)
Image Registry: GitHub Container Registry (ghcr.io)
Triggers:
- Push to
developbranch - Manual workflow dispatch
Jobs:
-
deploy: Deploys to staging environment
- Updates Kubernetes manifests with new image tags
- Applies manifests to staging cluster
- Waits for rollout completion
- Runs smoke tests
-
run-integration-tests: Runs integration tests
- Tests against staging environment
Required Secrets:
KUBE_CONFIG_STAGING: Base64-encoded kubeconfig for staging clusterSTAGING_TEST_USER: Test user credentialsSTAGING_TEST_PASSWORD: Test user password
Environment: staging
Triggers:
- Push to
mainordevelopbranches - Pull requests to
mainordevelop - Daily schedule (2 AM UTC)
Jobs:
- snyk-backend: Snyk vulnerability scanning for Python
- snyk-frontend: Snyk vulnerability scanning for Node.js
- trivy-repo-scan: Trivy filesystem scanning
- codeql-analysis: CodeQL security analysis
- dependency-review: Dependency review for PRs
- secret-scanning: TruffleHog secret scanning
Required Secrets:
SNYK_TOKEN: Snyk API token (optional, for Snyk scans)
Triggers:
- Push tags matching
v*.*.*(e.g., v1.0.0)
Jobs:
-
create-release: Creates GitHub release
- Generates changelog
- Creates release notes
- Uploads release artifacts
-
build-release-artifacts: Creates deployment package
- Packages infrastructure files
- Creates tarball
-
deploy-production: Deploys to production
- Only for stable releases (not rc/beta/alpha)
- Updates Kubernetes manifests
- Deploys to production cluster
- Runs smoke tests
-
notify-release: Sends notifications
Required Secrets:
KUBE_CONFIG_PRODUCTION: Base64-encoded kubeconfig for production cluster
Environment: production
Configure the following secrets in GitHub repository settings:
Required:
KUBE_CONFIG_STAGING: Staging Kubernetes configurationKUBE_CONFIG_PRODUCTION: Production Kubernetes configuration
Optional:
SNYK_TOKEN: Snyk API token for vulnerability scanningSTAGING_TEST_USER: Test user for staging integration testsSTAGING_TEST_PASSWORD: Test password for staging integration testsCODECOV_TOKEN: Codecov token for coverage reporting
Create the following environments in repository settings:
staging:
- URL:
https://staging.your-domain.com - Protection rules: None (auto-deploy on develop)
production:
- URL:
https://your-domain.com - Protection rules:
- Required reviewers: 2
- Wait timer: 5 minutes
- Deployment branches: Only tags matching
v*.*.*
The pipeline uses GitHub Container Registry (ghcr.io). No additional setup required.
Images are automatically pushed to:
ghcr.io/<owner>/<repo>/api-gatewayghcr.io/<owner>/<repo>/task-managerghcr.io/<owner>/<repo>/agent-runtimeghcr.io/<owner>/<repo>/document-processorghcr.io/<owner>/<repo>/frontend
Ensure your Kubernetes clusters have:
- Namespace:
digital-workforce - Ingress controller (NGINX)
- Storage class for PVCs
- Secrets configured (see
infrastructure/kubernetes/02-secrets.yaml)
-
main: Production-ready code
- Protected branch
- Requires PR reviews
- Runs all CI checks
- Deploys to production on tag push
-
develop: Development branch
- Integration branch for features
- Auto-deploys to staging
- Runs all CI checks
-
feature/*: New features
- Branch from
develop - Merge to
developvia PR - Runs CI checks on PR
- Branch from
-
bugfix/*: Bug fixes
- Branch from
developormain - Merge to source branch via PR
- Branch from
-
hotfix/*: Critical production fixes
- Branch from
main - Merge to both
mainanddevelop
- Branch from
- Create release branch:
release/v1.0.0fromdevelop - Test and fix: Make final adjustments
- Merge to main: Create PR to
main - Tag release: Create tag
v1.0.0onmain - Auto-deploy: Release workflow deploys to production
- Merge back: Merge
maintodevelop
Automatic:
- Push to
developbranch - CI tests run
- Docker images built and pushed
- Staging deployment triggered
- Smoke tests run
- Integration tests run
Manual:
- Go to Actions → Deploy to Staging
- Click "Run workflow"
- Select branch
- Click "Run workflow"
Via Release:
- Create and push tag:
git tag v1.0.0 && git push origin v1.0.0 - Release workflow creates GitHub release
- Production deployment triggered (requires approval)
- Smoke tests run
- Notification sent
Manual Rollback:
# Rollback to previous version
kubectl rollout undo deployment/api-gateway -n digital-workforce
kubectl rollout undo deployment/task-manager -n digital-workforce
kubectl rollout undo deployment/document-processor -n digital-workforce
kubectl rollout undo deployment/frontend -n digital-workforceSnyk:
- Scans Python and Node.js dependencies
- Runs on every push and PR
- Daily scheduled scans
- Results uploaded to GitHub Security
Trivy:
- Scans Docker images and filesystem
- Runs on image builds
- Results uploaded to GitHub Security
CodeQL:
- Static code analysis
- Scans Python and JavaScript code
- Runs on every push and PR
- Results uploaded to GitHub Security
TruffleHog:
- Scans for leaked secrets
- Runs on every push
- Checks commit history
GitHub Dependency Review:
- Reviews dependency changes in PRs
- Blocks PRs with vulnerable dependencies
- Severity threshold: moderate
Backend tests failing:
# Run tests locally
cd backend
pytest -v
# Check specific test
pytest tests/test_specific.py -v
# Run with coverage
pytest --cov=. --cov-report=htmlFrontend tests failing:
# Run tests locally
cd frontend
npm test
# Run specific test
npm test -- ComponentName
# Run with coverage
npm test -- --coverageCheck Dockerfile:
# Build locally
docker build -f infrastructure/docker/Dockerfile.api-gateway -t test .
# Check build logs
docker build --progress=plain -f infrastructure/docker/Dockerfile.api-gateway -t test .Multi-platform build issues:
# Set up buildx
docker buildx create --use
# Build for specific platform
docker buildx build --platform linux/amd64 -f infrastructure/docker/Dockerfile.api-gateway -t test .Check pod status:
kubectl get pods -n digital-workforce
kubectl describe pod <pod-name> -n digital-workforce
kubectl logs <pod-name> -n digital-workforceCheck rollout status:
kubectl rollout status deployment/api-gateway -n digital-workforce
kubectl rollout history deployment/api-gateway -n digital-workforceRollback deployment:
kubectl rollout undo deployment/api-gateway -n digital-workforceReview security alerts:
- Go to repository → Security → Code scanning alerts
- Review findings
- Fix vulnerabilities
- Re-run workflow
Snyk token issues:
- Verify
SNYK_TOKENsecret is set - Check token has correct permissions
- Token can be obtained from https://snyk.io/
Kubeconfig not working:
# Verify kubeconfig is valid
kubectl --kubeconfig=<path> get nodes
# Base64 encode for GitHub secret
cat kubeconfig.yaml | base64 -w 0
# Test decoding
echo "<base64-string>" | base64 -d > test-kubeconfig.yaml
kubectl --kubeconfig=test-kubeconfig.yaml get nodes- Write clear commit messages
- Reference issue numbers
- Keep commits atomic
- Sign commits (optional)
- Keep PRs small and focused
- Write descriptive PR descriptions
- Link related issues
- Ensure all CI checks pass
- Request reviews from team members
- Write tests for new features
- Maintain test coverage >80%
- Run tests locally before pushing
- Fix failing tests immediately
- Never commit secrets
- Use environment variables
- Scan dependencies regularly
- Review security alerts promptly
- Test in staging first
- Monitor deployments
- Have rollback plan ready
- Document changes in release notes
Monitor the following metrics:
- Build success rate
- Test pass rate
- Deployment frequency
- Mean time to recovery (MTTR)
- Change failure rate
Check Actions usage:
- Go to repository → Settings → Billing
- Review Actions minutes used
- Optimize workflows if needed
For CI/CD issues:
- Check workflow logs in Actions tab
- Review this documentation
- Check GitHub Actions documentation
- Contact DevOps team