Skip to content

Commit 66f9ccd

Browse files
committed
ci: generate and attest build provenance and SBOM for Playwright Docker image
1 parent 0ad8d02 commit 66f9ccd

1 file changed

Lines changed: 80 additions & 1 deletion

File tree

.github/workflows/Playwright.yml

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Playwright
22

3-
on: workflow_dispatch
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- '.github/workflows/Playwright.yml'
8+
- 'src/ScreenshotCreator.Api/Dockerfile-Playwright'
9+
- 'src/ScreenshotCreator.Api/install-powershell-*.sh'
410

511
jobs:
612
playwright:
@@ -12,6 +18,9 @@ jobs:
1218
attestations: write
1319
id-token: write
1420

21+
outputs:
22+
digests: ${{ steps.extract-digests.outputs.digests }}
23+
1524
steps:
1625
- name: Check out code
1726
uses: actions/checkout@v5
@@ -47,3 +56,73 @@ jobs:
4756
platforms: linux/arm64,linux/amd64
4857
tags: ghcr.io/mu88/screenshotcreator-playwright:latest,ghcr.io/mu88/screenshotcreator-playwright:${{ steps.extract_version.outputs.major_version }}.0.${{ github.run_number }}
4958
file: src/ScreenshotCreator.Api/Dockerfile-Playwright
59+
60+
- name: Extract generated Docker image digests
61+
id: extract-digests
62+
shell: pwsh
63+
run: |
64+
$ErrorActionPreference = "Stop"
65+
$PSNativeCommandUseErrorActionPreference = $true
66+
67+
$digests = @()
68+
Write-Host "Blub: ${{ steps.docker_build.outputs.metadata }}"
69+
$manifest = docker manifest inspect ${{ steps.docker_build.outputs.imageid }}@${{ steps.docker_build.outputs.digest }} | ConvertFrom-Json
70+
71+
# Collect digests from all manifests (for multi-arch images)
72+
foreach ($item in $manifest.manifests) {
73+
$digest = $item.digest
74+
if ($digest -notin $digests) {
75+
$digests += $digest
76+
}
77+
}
78+
79+
# Add the digest for the image itself
80+
$imageDigest = "${{ steps.docker_build.outputs.digest }}"
81+
if ($imageDigest -notin $digests) {
82+
$digests += $imageDigest
83+
}
84+
85+
$json = $digests | ConvertTo-Json -Depth 10
86+
Write-Output "digests=$json" >> $env:GITHUB_OUTPUT
87+
88+
attest_provenance_sbom:
89+
name: 'Attest Docker image build provenance and SBOM'
90+
runs-on: ubuntu-latest
91+
92+
needs: playwright
93+
94+
strategy:
95+
matrix:
96+
digest: ${{ fromJson(needs.playwright.outputs.digests) }}
97+
98+
steps:
99+
- name: Check out code
100+
uses: actions/checkout@v5
101+
102+
- name: Login to Container registry
103+
uses: docker/login-action@v3
104+
with:
105+
registry: ghcr.io
106+
username: ${{ github.actor }}
107+
password: ${{ secrets.GITHUB_TOKEN }}
108+
109+
- name: Attest build provenance
110+
uses: actions/attest-build-provenance@v3
111+
with:
112+
push-to-registry: true
113+
subject-name: ghcr.io/mu88/screenshotcreator-playwright
114+
subject-digest: ${{ matrix.digest }}
115+
116+
- name: Generate SBOM
117+
uses: anchore/sbom-action@v0
118+
with:
119+
image: ghcr.io/mu88/screenshotcreator-playwright@${{ matrix.digest }}
120+
output-file: sbom.json
121+
122+
- name: Attest SBOM
123+
uses: actions/attest-sbom@v2
124+
with:
125+
push-to-registry: true
126+
sbom-path: sbom.json
127+
subject-name: ghcr.io/mu88/screenshotcreator-playwright
128+
subject-digest: ${{ matrix.digest }}

0 commit comments

Comments
 (0)