CI/CD Pipeline Documentation
Overview
The FRED ML project uses GitHub Actions for comprehensive CI/CD automation. The pipeline includes multiple workflows for different purposes:
- Main CI/CD Pipeline (
ci-cd.yml
): Full deployment pipeline for main branch - Pull Request Checks (
pull-request.yml
): Quality checks for PRs and development - Scheduled Maintenance (
scheduled.yml
): Automated maintenance tasks - Release Deployment (
release.yml
): Versioned releases and production deployments
Workflow Overview
π Main CI/CD Pipeline (ci-cd.yml
)
Triggers:
- Push to
main
ordevelop
branches - Pull requests to
main
branch - Daily scheduled runs at 2 AM UTC
Jobs:
- π§ͺ Test & Quality: Linting, type checking, unit tests
- π Integration Tests: AWS integration testing
- π End-to-End Tests: Complete system testing
- π Security Scan: Security vulnerability scanning
- β‘ Deploy Lambda: AWS Lambda function deployment
- ποΈ Deploy Infrastructure: AWS infrastructure deployment
- π¨ Deploy Streamlit: Streamlit Cloud deployment preparation
- π’ Notifications: Deployment status notifications
π Pull Request Checks (pull-request.yml
)
Triggers:
- Pull requests to
main
ordevelop
branches - Push to
develop
branch
Jobs:
- π Code Quality: Formatting, linting, type checking
- π§ͺ Unit Tests: Unit test execution with coverage
- π Security Scan: Security vulnerability scanning
- π¦ Dependency Check: Outdated dependencies and security
- π Documentation Check: README and deployment docs validation
- ποΈ Build Test: Lambda package and Streamlit app testing
- π¬ Comment Results: Automated PR comments with results
β° Scheduled Maintenance (scheduled.yml
)
Triggers:
- Daily at 6 AM UTC: Health checks
- Weekly on Sundays at 8 AM UTC: Dependency updates
- Monthly on 1st at 10 AM UTC: Performance testing
Jobs:
- π₯ Daily Health Check: AWS service status monitoring
- π¦ Weekly Dependency Check: Dependency updates and security
- β‘ Monthly Performance Test: Performance benchmarking
- π§Ή Cleanup Old Artifacts: S3 cleanup and maintenance
π― Release Deployment (release.yml
)
Triggers:
- GitHub releases (published)
Jobs:
- π¦ Create Release Assets: Lambda packages, docs, test results
- π Deploy to Production: Production deployment
- π§ͺ Production Tests: Post-deployment testing
- π’ Notify Stakeholders: Release notifications
Required Secrets
Configure these secrets in your GitHub repository settings:
AWS Credentials
AWS_ACCESS_KEY_ID=your_aws_access_key
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
FRED API
FRED_API_KEY=your_fred_api_key
Environment Variables
The workflows use these environment variables:
AWS_REGION: us-west-2
S3_BUCKET: fredmlv1
LAMBDA_FUNCTION: fred-ml-processor
PYTHON_VERSION: '3.9'
Workflow Features
π Automated Testing
- Unit Tests: pytest with coverage reporting
- Integration Tests: AWS service integration
- End-to-End Tests: Complete system validation
- Security Scans: Bandit security scanning
- Performance Tests: Load and performance testing
ποΈ Infrastructure as Code
- S3 Bucket: Automated bucket creation and configuration
- Lambda Function: Automated deployment and configuration
- EventBridge Rules: Quarterly scheduling automation
- SSM Parameters: Secure parameter storage
π Monitoring & Reporting
- Code Coverage: Automated coverage reporting to Codecov
- Test Results: Detailed test result artifacts
- Security Reports: Vulnerability scanning reports
- Performance Metrics: Performance benchmarking
π Security
- Secret Management: Secure handling of API keys
- Vulnerability Scanning: Automated security checks
- Access Control: Environment-based deployment controls
- Audit Trail: Complete deployment logging
Deployment Process
Development Workflow
- Create feature branch from
develop
- Make changes and push to branch
- Create pull request to
develop
- Automated checks run on PR
- Merge to
develop
after approval - Automated testing on
develop
branch
Production Deployment
- Create pull request from
develop
tomain
- Automated checks and testing
- Merge to
main
triggers production deployment - Lambda function updated
- Infrastructure deployed
- Production tests run
- Notification sent
Release Process
- Create GitHub release with version tag
- Automated release asset creation
- Production deployment
- Post-deployment testing
- Stakeholder notification
Monitoring & Alerts
Health Checks
- Daily AWS service status monitoring
- Lambda function availability
- S3 bucket accessibility
- EventBridge rule status
Performance Monitoring
- Monthly performance benchmarking
- Response time tracking
- Resource utilization monitoring
- Error rate tracking
Security Monitoring
- Weekly dependency vulnerability scans
- Security best practice compliance
- Access control monitoring
- Audit log review
Troubleshooting
Common Issues
Lambda Deployment Failures
# Check Lambda function status
aws lambda get-function --function-name fred-ml-processor --region us-west-2
# Check CloudWatch logs
aws logs describe-log-groups --log-group-name-prefix /aws/lambda/fred-ml-processor
S3 Access Issues
# Check S3 bucket permissions
aws s3 ls s3://fredmlv1 --region us-west-2
# Test bucket access
aws s3 cp test.txt s3://fredmlv1/test.txt
EventBridge Rule Issues
# Check EventBridge rules
aws events list-rules --name-prefix "fred-ml" --region us-west-2
# Test rule execution
aws events test-event-pattern --event-pattern file://event-pattern.json
Debug Workflows
Enable Debug Logging
Add to workflow:
env:
ACTIONS_STEP_DEBUG: true
ACTIONS_RUNNER_DEBUG: true
Check Workflow Logs
- Go to GitHub repository
- Click "Actions" tab
- Select workflow run
- View detailed logs for each job
Best Practices
Code Quality
- Use pre-commit hooks for local checks
- Maintain high test coverage (>80%)
- Follow PEP 8 style guidelines
- Use type hints throughout codebase
Security
- Never commit secrets to repository
- Use least privilege AWS IAM policies
- Regularly update dependencies
- Monitor security advisories
Performance
- Optimize Lambda function cold starts
- Use S3 lifecycle policies for cleanup
- Monitor AWS service quotas
- Implement proper error handling
Documentation
- Keep README updated
- Document deployment procedures
- Maintain architecture diagrams
- Update troubleshooting guides
Advanced Configuration
Custom Workflow Triggers
on:
push:
branches: [ main, develop ]
paths: [ 'lambda/**', 'frontend/**' ]
pull_request:
branches: [ main ]
paths-ignore: [ 'docs/**' ]
Environment-Specific Deployments
jobs:
deploy:
environment:
name: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
url: ${{ steps.deploy.outputs.url }}
Conditional Job Execution
jobs:
deploy:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
Support
For issues with the CI/CD pipeline:
- Check workflow logs in GitHub Actions
- Review this documentation
- Check AWS CloudWatch logs
- Contact the development team
Contributing
To contribute to the CI/CD pipeline:
- Create feature branch
- Make changes to workflow files
- Test locally with
act
(GitHub Actions local runner) - Create pull request
- Ensure all checks pass
- Get approval from maintainers