|
9 | 9 | permissions: |
10 | 10 | contents: read |
11 | 11 | packages: write |
| 12 | + security-events: write |
12 | 13 |
|
13 | 14 | jobs: |
14 | | - build-and-push: |
| 15 | + build-scan-push: |
15 | 16 | runs-on: ubuntu-latest |
16 | 17 | steps: |
17 | 18 | - uses: actions/checkout@v6 |
18 | 19 |
|
19 | 20 | - name: Set up Docker Buildx |
20 | 21 | uses: docker/setup-buildx-action@v3 |
21 | 22 |
|
22 | | - - name: Log in to GHCR |
23 | | - uses: docker/login-action@v3 |
24 | | - with: |
25 | | - registry: ghcr.io |
26 | | - username: ${{ github.actor }} |
27 | | - password: ${{ secrets.GITHUB_TOKEN }} |
28 | | - |
29 | 23 | - name: Extract metadata |
30 | 24 | id: meta |
31 | 25 | uses: docker/metadata-action@v5 |
|
36 | 30 | type=semver,pattern={{major}}.{{minor}} |
37 | 31 | type=raw,value=latest |
38 | 32 |
|
39 | | - - name: Build and push |
| 33 | + - name: Build image (local) |
| 34 | + uses: docker/build-push-action@v6 |
| 35 | + with: |
| 36 | + context: . |
| 37 | + load: true |
| 38 | + tags: ghcr.io/${{ github.repository }}:scan |
| 39 | + cache-from: type=gha |
| 40 | + cache-to: type=gha,mode=max |
| 41 | + |
| 42 | + - name: Scan with Trivy |
| 43 | + uses: aquasecurity/trivy-action@master |
| 44 | + with: |
| 45 | + image-ref: ghcr.io/${{ github.repository }}:scan |
| 46 | + format: sarif |
| 47 | + output: trivy-results.sarif |
| 48 | + severity: CRITICAL,HIGH |
| 49 | + exit-code: 1 |
| 50 | + continue-on-error: true |
| 51 | + id: trivy |
| 52 | + |
| 53 | + - name: Upload Trivy SARIF |
| 54 | + uses: github/codeql-action/upload-sarif@v4 |
| 55 | + if: always() |
| 56 | + with: |
| 57 | + sarif_file: trivy-results.sarif |
| 58 | + category: trivy |
| 59 | + |
| 60 | + - name: Fail on critical vulnerabilities |
| 61 | + if: steps.trivy.outcome == 'failure' |
| 62 | + run: | |
| 63 | + echo "::error::Trivy found CRITICAL or HIGH vulnerabilities" |
| 64 | + exit 1 |
| 65 | +
|
| 66 | + - name: Log in to GHCR |
| 67 | + uses: docker/login-action@v3 |
| 68 | + with: |
| 69 | + registry: ghcr.io |
| 70 | + username: ${{ github.actor }} |
| 71 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + |
| 73 | + - name: Push image |
40 | 74 | uses: docker/build-push-action@v6 |
41 | 75 | with: |
42 | 76 | context: . |
|
0 commit comments