Skip to content

Commit 8e99de3

Browse files
committed
oci-copy: rework SBOM generation
Use scripts from https://github.com/konflux-ci/build-tasks-dockerfiles instead of the previous bash script. Signed-off-by: Adam Cmiel <[email protected]>
1 parent e38416e commit 8e99de3

File tree

2 files changed

+26
-52
lines changed

2 files changed

+26
-52
lines changed

task/oci-copy-oci-ta/0.1/oci-copy-oci-ta.yaml

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -294,38 +294,25 @@ spec:
294294
add:
295295
- SETFCAP
296296
- name: sbom-generate
297-
image: quay.io/konflux-ci/yq:latest@sha256:93bb15cff64b708263055a5814b24a0b450d8724b86a7e5206396f25d81fcc21
297+
image: quay.io/acmiel-test/sbom-utility-scripts:spdx-support
298298
workingDir: /var/workdir
299299
script: |
300300
#!/bin/bash
301-
cat >sbom-cyclonedx.json <<EOL
302-
{
303-
"\$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
304-
"bomFormat": "CycloneDX",
305-
"specVersion": "1.5",
306-
"version": 1,
307-
"components": []
308-
"metadata": {
309-
"component": {
310-
"type": "file",
311-
"name": "${IMAGE%:*}@$(cat "$(results.IMAGE_DIGEST.path)")"
312-
}
313-
}
314-
}
315-
EOL
301+
set -euo pipefail
316302
317-
for varfile in "/var/workdir"/vars/*; do
318-
echo "Reading $varfile"
319-
# shellcheck source=/dev/null
320-
source $varfile
303+
IMAGE_URL=$(cat "$(results.IMAGE_URL.path)")
304+
IMAGE_DIGEST=$(cat "$(results.IMAGE_DIGEST.path)")
305+
oci_copy_file_path="$(pwd)/source/$OCI_COPY_FILE"
321306
322-
ENCODED_URL=$(echo "${OCI_SOURCE}" | python3 -c 'import sys; import urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip(), safe=":/"))')
323-
ENCODED_FILENAME=$(echo "${OCI_FILENAME}" | python3 -c 'import sys; import urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip(), safe=":/"))')
324-
purl="pkg:generic/${ENCODED_FILENAME}?download_url=${ENCODED_URL}&checksum=sha256:${OCI_ARTIFACT_DIGEST}"
307+
python3 /scripts/sbom_for_oci_copy_task.py "$oci_copy_file_path" -o sbom-cyclonedx.json
325308
326-
echo "Recording purl $purl"
327-
yq -oj -i '.components += [ {"purl": "'$purl'", "type": "file", "name": "'$OCI_FILENAME'", "hashes": [{"alg": "SHA-256", "content": "'$OCI_ARTIFACT_DIGEST'"}], "externalReferences": [{"type": "distribution", "url": "'$OCI_SOURCE'"}]} ]' sbom-cyclonedx.json
328-
done
309+
python3 /scripts/add_image_reference.py \
310+
--image-url "$IMAGE_URL" \
311+
--image-digest "$IMAGE_DIGEST" \
312+
--input-file sbom-cyclonedx.json \
313+
--output-file /tmp/sbom-cyclonedx.tmp.json
314+
315+
mv /tmp/sbom-cyclonedx.tmp.json sbom-cyclonedx.json
329316
- name: upload-sbom
330317
image: quay.io/konflux-ci/appstudio-utils:48c311af02858e2422d6229600e9959e496ddef1@sha256:91ddd999271f65d8ec8487b10f3dd378f81aa894e11b9af4d10639fd52bba7e8
331318
workingDir: /var/workdir

task/oci-copy/0.1/oci-copy.yaml

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -274,37 +274,24 @@ spec:
274274
name: varlibcontainers
275275
workingDir: $(workspaces.source.path)
276276
- name: sbom-generate
277-
image: quay.io/konflux-ci/yq:latest@sha256:93bb15cff64b708263055a5814b24a0b450d8724b86a7e5206396f25d81fcc21
277+
image: quay.io/acmiel-test/sbom-utility-scripts:spdx-support
278278
script: |
279279
#!/bin/bash
280-
cat >sbom-cyclonedx.json <<EOL
281-
{
282-
"\$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
283-
"bomFormat": "CycloneDX",
284-
"specVersion": "1.5",
285-
"version": 1,
286-
"components": []
287-
"metadata": {
288-
"component": {
289-
"type": "file",
290-
"name": "${IMAGE%:*}@$(cat "$(results.IMAGE_DIGEST.path)")"
291-
}
292-
}
293-
}
294-
EOL
280+
set -euo pipefail
295281
296-
for varfile in "$(workspaces.source.path)"/vars/*; do
297-
echo "Reading $varfile"
298-
# shellcheck source=/dev/null
299-
source $varfile
282+
IMAGE_URL=$(cat "$(results.IMAGE_URL.path)")
283+
IMAGE_DIGEST=$(cat "$(results.IMAGE_DIGEST.path)")
284+
oci_copy_file_path="$(pwd)/source/$OCI_COPY_FILE"
300285
301-
ENCODED_URL=$(echo "${OCI_SOURCE}" | python3 -c 'import sys; import urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip(), safe=":/"))')
302-
ENCODED_FILENAME=$(echo "${OCI_FILENAME}" | python3 -c 'import sys; import urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip(), safe=":/"))')
303-
purl="pkg:generic/${ENCODED_FILENAME}?download_url=${ENCODED_URL}&checksum=sha256:${OCI_ARTIFACT_DIGEST}"
286+
python3 /scripts/sbom_for_oci_copy_task.py "$oci_copy_file_path" -o sbom-cyclonedx.json
304287
305-
echo "Recording purl $purl"
306-
yq -oj -i '.components += [ {"purl": "'$purl'", "type": "file", "name": "'$OCI_FILENAME'", "hashes": [{"alg": "SHA-256", "content": "'$OCI_ARTIFACT_DIGEST'"}], "externalReferences": [{"type": "distribution", "url": "'$OCI_SOURCE'"}]} ]' sbom-cyclonedx.json
307-
done
288+
python3 /scripts/add_image_reference.py \
289+
--image-url "$IMAGE_URL" \
290+
--image-digest "$IMAGE_DIGEST" \
291+
--input-file sbom-cyclonedx.json \
292+
--output-file /tmp/sbom-cyclonedx.tmp.json
293+
294+
mv /tmp/sbom-cyclonedx.tmp.json sbom-cyclonedx.json
308295
workingDir: $(workspaces.source.path)
309296
- name: upload-sbom
310297
image: quay.io/konflux-ci/appstudio-utils:48c311af02858e2422d6229600e9959e496ddef1@sha256:91ddd999271f65d8ec8487b10f3dd378f81aa894e11b9af4d10639fd52bba7e8

0 commit comments

Comments
 (0)