blob: 087675c4045b2f8eb8d932ddc49568ad218e5e86 [file] [log] [blame]
Alex Stancua0e2df22023-03-21 16:05:02 +02001#!/bin/bash
2
3################################################################################
4# Copyright 2023 highstreet technologies GmbH
5#
6# Licensed under the Apache License, Version 2.0 (the 'License');
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an 'AS IS' BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17################################################################################
18
19# Excluded images is an array containing the name of the docker images we want to exclude from the analysis.
20# Please modify it according to your needs.
21
22# Installing syft
23# curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
24
25# Installing grype
26# curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
27
28SYFT=$(which syft)
29if [ -z "$SYFT" ]; then
30 echo "unable to find syft. please install."
31 exit 1
32fi
33
34GRYPE=$(which grype)
35if [ -z "$GRYPE" ]; then
36 echo "unable to find grype. please install."
37 exit 1
38fi
39
40excluded_images=(nexus3.onap.org:10001/onap/dmaap/dmaap-mr:1.1.18 nexus3.onap.org:10001/onap/dmaap/kafka111:1.0.4 nexus3.onap.org:10001/onap/dmaap/zookeeper:6.0.3 nexus3.onap.org:10001/onap/org.onap.dcaegen2.collectors.ves.vescollector:1.10.1)
41
42image_names=($(docker ps --format '{{.Image}}' | tr ' ' '\n' | sort -u | tr '\n' ' '))
43
44for ele in "${excluded_images[@]}"; do
45image_names=(${image_names[@]/*${ele}*/})
46done
47
48echo "Analysing following images: ${image_names[*]}"
49
50for image in "${image_names[@]}"; do
51image_name_no_repo="${image##*/}"
52echo "Creating SBOM for ${image} in ${image_name_no_repo}.sbom.spdx.json..."
53${SYFT} -q ${image} -o spdx-json --file ${image_name_no_repo}.sbom.spdx.json
54echo "Creating Vulnerabilities for ${image} in ${image_name_no_repo}.vulnerabilities.vex.json..."
55${GRYPE} -q ${image} -o embedded-cyclonedx-vex-json --file ${image_name_no_repo}.vulnerabilities.vex.json
56done
57
58echo "Done!"