|
| 1 | +# GitHub CI/CD Configuration |
| 2 | + |
| 3 | +This directory contains the GitHub Actions workflows and configuration for the TalkPipe project's automated CI/CD pipeline. |
| 4 | + |
| 5 | +## Files Overview |
| 6 | + |
| 7 | +### Workflows (`workflows/`) |
| 8 | + |
| 9 | +#### `ci-cd.yml` - Main CI/CD Pipeline |
| 10 | +Comprehensive pipeline that runs on: |
| 11 | +- Pushes to `main` and `develop` branches |
| 12 | +- Pull requests to `main` and `develop` |
| 13 | +- GitHub releases |
| 14 | + |
| 15 | +**Pipeline Jobs:** |
| 16 | +1. **Test** - Multi-version Python testing (3.11, 3.12) with coverage |
| 17 | +2. **Security Scan** - SAST and dependency vulnerability scanning |
| 18 | +3. **Build Container** - Docker image build/push with container security scan |
| 19 | +4. **CodeQL Analysis** - GitHub's semantic code analysis |
| 20 | +5. **Publish Package** - Automated PyPI publishing on releases |
| 21 | + |
| 22 | +### Configuration Files |
| 23 | + |
| 24 | +- **`dependabot.yml`** - Automated dependency updates (weekly schedule) |
| 25 | +- **`SECURITY.md`** - Security policy and vulnerability reporting guidelines |
| 26 | + |
| 27 | +### Root Level Security Files |
| 28 | + |
| 29 | +- **`.bandit`** - Configuration for Bandit static security analysis |
| 30 | +- **`.dockerignore`** - Optimized Docker build context exclusions |
| 31 | + |
| 32 | +## Security Scanning |
| 33 | + |
| 34 | +The pipeline includes multiple layers of security scanning: |
| 35 | + |
| 36 | +- **Bandit** - Python static analysis security testing (SAST) |
| 37 | +- **Safety** - Python dependency vulnerability scanning |
| 38 | +- **Trivy** - Container image vulnerability scanning |
| 39 | +- **CodeQL** - Semantic code analysis for security issues |
| 40 | +- **Dependabot** - Automated dependency update PRs |
| 41 | + |
| 42 | +## Container Registry |
| 43 | + |
| 44 | +Docker images are built and pushed to GitHub Container Registry: |
| 45 | +``` |
| 46 | +ghcr.io/sandialabs/talkpipe:latest |
| 47 | +ghcr.io/sandialabs/talkpipe:<branch-name> |
| 48 | +ghcr.io/sandialabs/talkpipe:<version> |
| 49 | +``` |
| 50 | + |
| 51 | +## Required Repository Secrets |
| 52 | + |
| 53 | +To enable full functionality, set these secrets in your GitHub repository settings (`Settings > Secrets and variables > Actions`): |
| 54 | + |
| 55 | +### Required for PyPI Publishing |
| 56 | +- **`PYPI_API_TOKEN`** - PyPI API token for automated package publishing |
| 57 | + - Create at: https://pypi.org/manage/account/token/ |
| 58 | + - Scope: Entire account or specific to talkpipe project |
| 59 | + - Used in: Package publishing job (triggered on releases) |
| 60 | + |
| 61 | +### Automatic Secrets (No Action Required) |
| 62 | +- **`GITHUB_TOKEN`** - Automatically provided by GitHub Actions |
| 63 | + - Used for: Container registry authentication, uploading artifacts, CodeQL results |
| 64 | + |
| 65 | +## Setup Instructions |
| 66 | + |
| 67 | +1. **Enable GitHub Container Registry** (if not already enabled): |
| 68 | + - Go to repository `Settings > General` |
| 69 | + - Scroll to "Features" section |
| 70 | + - Ensure "Packages" is enabled |
| 71 | + |
| 72 | +2. **Set PyPI Token**: |
| 73 | + ```bash |
| 74 | + # In repository Settings > Secrets and variables > Actions |
| 75 | + # Add new repository secret: |
| 76 | + Name: PYPI_API_TOKEN |
| 77 | + Secret: pypi-your-token-here |
| 78 | + ``` |
| 79 | + |
| 80 | +3. **Configure Dependabot** (optional customization): |
| 81 | + - Edit `.github/dependabot.yml` to adjust reviewers/assignees |
| 82 | + - Default: weekly updates on Mondays at 9 AM UTC |
| 83 | + |
| 84 | +## Testing Locally |
| 85 | + |
| 86 | +Before pushing, you can test components locally: |
| 87 | + |
| 88 | +```bash |
| 89 | +# Run tests with coverage (matches CI) |
| 90 | +pytest --cov=src --cov-report=xml --cov-report=html |
| 91 | + |
| 92 | +# Run security scans |
| 93 | +bandit -r src/ |
| 94 | +safety check |
| 95 | + |
| 96 | +# Build container (matches CI) |
| 97 | +docker build -t talkpipe:local . |
| 98 | + |
| 99 | +# Run container security scan |
| 100 | +docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \ |
| 101 | + aquasec/trivy image talkpipe:local |
| 102 | +``` |
| 103 | + |
| 104 | +## Workflow Triggers |
| 105 | + |
| 106 | +| Event | Trigger | Jobs Run | |
| 107 | +|-------|---------|----------| |
| 108 | +| Push to main/develop | Automatic | All jobs | |
| 109 | +| Pull Request | Automatic | All except publish | |
| 110 | +| Release published | Automatic | All jobs + PyPI publish | |
| 111 | +| Manual trigger | `workflow_dispatch` | All jobs | |
| 112 | + |
| 113 | +## Monitoring |
| 114 | + |
| 115 | +- **Test Results**: Visible in Actions tab and PR checks |
| 116 | +- **Coverage Reports**: Uploaded to Codecov (if configured) |
| 117 | +- **Security Issues**: Reported in Security tab (CodeQL, Trivy) |
| 118 | +- **Container Images**: Available in Packages tab |
| 119 | + |
| 120 | +## Troubleshooting |
| 121 | + |
| 122 | +**Common Issues:** |
| 123 | + |
| 124 | +1. **PyPI Publishing Fails**: |
| 125 | + - Verify `PYPI_API_TOKEN` is set correctly |
| 126 | + - Ensure token has sufficient permissions |
| 127 | + - Check package version doesn't already exist |
| 128 | + |
| 129 | +2. **Container Build Fails**: |
| 130 | + - Check Dockerfile syntax |
| 131 | + - Verify base image availability |
| 132 | + - Review build logs in Actions tab |
| 133 | + |
| 134 | +3. **Tests Fail**: |
| 135 | + - Run tests locally first |
| 136 | + - Check dependency compatibility |
| 137 | + - Review test logs in Actions tab |
| 138 | + |
| 139 | +4. **Security Scans Fail**: |
| 140 | + - Review Bandit/Safety reports |
| 141 | + - Update vulnerable dependencies |
| 142 | + - Add exclusions to `.bandit` if needed |
| 143 | + |
| 144 | +For additional help, check the Actions tab logs or create an issue in the repository. |
0 commit comments