Skip to content

Commit 0a833a5

Browse files
committed
Add bash script that extracts images from manifests repi
1 parent 9fa5b94 commit 0a833a5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

hack/extract_manifests_images.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
# The extracts all images from specific manifests sub-directories.
4+
# Future release process enhancement may include an automatic image inventory scan.
5+
# The reported image list can be used later for image vulnerability scanning and managing license risks management
6+
7+
#VERSION=1.7.0
8+
output_file="kf${VERSION}_images.txt"
9+
10+
rm -f .tmp
11+
# Iterate over all files with names: 'kustomization.yaml', 'kustomization.yml', 'Kustomization' found recursively in the provided list of directories
12+
for F in $(find ../apps ../common ../example ../contrib/metacontroller ../contrib/seldon \( -name kustomization.yaml -o -name kustomization.yml -o -name Kustomization \)); do
13+
14+
dir=$(dirname -- "$F")
15+
# Generate k8s resources specified in 'dir' using the 'kustomize build' command.
16+
# Log the 'dir' name where the 'kustomize build' command fails.
17+
kbuild=$(kustomize build "$dir")
18+
return_code=$?
19+
if [ $return_code -ne 0 ]; then
20+
printf 'ERROR:\t Failed \"kustomize build\" command for directory: %s. See error above\n' "$dir"
21+
continue
22+
fi
23+
# Grep the output of 'kustomize build' command for 'image:' and '- image' lines and return just the image itself
24+
# Redirect the output to '.tmp' file
25+
grep '\-\?\s\image:'<<<"$kbuild" | sed -re 's/\s-?\simage: *//;s/^[ \t]*//g' | sed '/^$/d;/{/d' >> .tmp
26+
done
27+
28+
sort .tmp | uniq > "$output_file"
29+
rm -f .tmp
30+
31+
echo "File ${output_file} successfully created"

0 commit comments

Comments
 (0)