|
| 1 | +name: Python Backend CI/CD - Enhanced |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
| 8 | + paths: |
| 9 | + - 'backend/**' |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + - develop |
| 14 | + paths: |
| 15 | + - 'backend/**' |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-test-scan: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: '3.9' |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: | |
| 31 | + python -m pip install --upgrade pip |
| 32 | + pip install -r backend/requirements.txt |
| 33 | + pip install black flake8 pytest bandit |
| 34 | +
|
| 35 | + - name: Run Black Formatter |
| 36 | + run: black --check backend/ |
| 37 | + |
| 38 | + - name: Run Flake8 Linter |
| 39 | + run: flake8 backend/ |
| 40 | + |
| 41 | + - name: Run Pytest Unit Tests |
| 42 | + run: pytest backend/tests/unit/ || true # Allow failure for now, adjust path as needed |
| 43 | + |
| 44 | + - name: Run Pytest Integration Tests |
| 45 | + run: pytest backend/tests/integration/ || true # Allow failure for now, adjust path as needed |
| 46 | + |
| 47 | + - name: Run Bandit SAST |
| 48 | + run: bandit -r backend/ -ll -f json -o bandit-report.json || true |
| 49 | + |
| 50 | + - name: Upload Bandit Report |
| 51 | + uses: actions/upload-artifact@v4 |
| 52 | + with: |
| 53 | + name: bandit-report |
| 54 | + path: bandit-report.json |
| 55 | + |
| 56 | + - name: Install Trivy |
| 57 | + run: | |
| 58 | + sudo apt-get update |
| 59 | + sudo apt-get install -y wget apt-transport-https gnupg |
| 60 | + wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add - |
| 61 | + echo "deb https://aquasecurity.github.io/trivy-repo/deb stable main" | sudo tee /etc/apt/sources.list.d/trivy.list |
| 62 | + sudo apt-get update |
| 63 | + sudo apt-get install -y trivy |
| 64 | +
|
| 65 | + - name: Build Docker image for backend |
| 66 | + run: docker build -t flowlet-backend:$(git rev-parse --short HEAD) ./backend |
| 67 | + |
| 68 | + - name: Scan backend Docker image (Trivy) |
| 69 | + run: trivy image --exit-code 1 --severity HIGH,CRITICAL flowlet-backend:$(git rev-parse --short HEAD) |
| 70 | + |
| 71 | + - name: Run Secrets Scanning (TruffleHog - Placeholder) |
| 72 | + run: echo "TruffleHog scan placeholder: trufflehog filesystem . --json > trufflehog_report.json || true" |
| 73 | + |
| 74 | + - name: Run OWASP Dependency-Check (Placeholder) |
| 75 | + run: echo "OWASP Dependency-Check placeholder: Download and run dependency-check.sh" |
| 76 | + |
| 77 | + # Placeholder for deployment job, will be in a separate workflow or triggered by this one |
| 78 | + # deploy: |
| 79 | + # runs-on: ubuntu-latest |
| 80 | + # needs: build-test-scan |
| 81 | + # if: github.ref == 'refs/heads/main' |
| 82 | + # steps: |
| 83 | + # - name: Deploy to production |
| 84 | + # run: echo "Deploying backend..." |
| 85 | + |
| 86 | + |
0 commit comments