Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate SBOM with build #643

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- run: opam exec -- dune build COMMIT
- store_artifacts:
path: ./_build/default/COMMIT
- run: opam exec -- dune build vpnkit.spdx.json
- store_artifacts:
path: ./_build/default/vpnkit.spdx.json
- run: opam exec -- dune build licenses.json
- store_artifacts:
path: ./_build/default/licenses.json
Expand Down
6 changes: 6 additions & 0 deletions dune
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
(deps vpnkit.exe (:gen ./scripts/mac_package.exe))
(action (run %{gen} -out %{target} -in %{deps})))

(rule
(alias sbom)
(target vpnkit.spdx.json)
(deps (:gen ./scripts/sbom.sh))
(action (run %{gen} %{target})))

(rule
(alias e2e)
(deps src/hostnet_test/main.exe
Expand Down
48 changes: 48 additions & 0 deletions scripts/sbom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env sh
set -e

# echo $OPAM_SWITCH_PREFIX
echo $1

pkg=(
$(opam list -s --installed --required-by=vpnkit --recursive --columns package --nobuild --color=never)
)

dir="sbom_temp"
mkdir "$dir"

cp vpnkit.opam "$dir"

for p in ${pkg[@]}; do
echo $p >> "$1"
cp -r "$OPAM_SWITCH_PREFIX/.opam-switch/packages/$p" "$dir/$p"
done

touch vpnkit.spdx.json
docker run --rm \
-v ./$dir:/vpnkit \
-v ./vpnkit.spdx.json:/out/vpnkit.spdx.json \
-e BUILDKIT_SCAN_SOURCE=/vpnkit \
-e BUILDKIT_SCAN_DESTINATION=/out \
-e BUILDKIT_SCAN_EXTRA_SCANNERS=opam-cataloger \
docker/scout-sbom-indexer:1.15

# Fix the relationships and file to point to the binary
mv vpnkit.spdx.json vpnkit.spdx
jq -c --arg uid "${$(uuidgen)//-/}" '
"SPDXRef-File-\($uid)" as $fileId
| .predicate
| del(.files[])
| .files |= . + [
{
"SPDXID": $fileId,
"fileName": "vpnkit.exe",
"licenseConcluded": "NOASSERTION"
}
]
| .relationships[] |= (
select(.relationshipType == "OTHER").relatedSpdxElement |= $fileId
)
' vpnkit.spdx > vpnkit.spdx.json

rm -rf sbom_temp