Created
July 17, 2024 13:50
-
-
Save lcarva/7e0c68aa5e75244775b11b77e4a8a9df to your computer and use it in GitHub Desktop.
Update Tekton bundle references in Tekton resource files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
FILES=$@ | |
# Find existing image references | |
OLD_REFS="$(\ | |
yq '.' $FILES --output-format json | \ | |
jq '.. | .taskRef? | select(. != null) | .params[] | select(.name == "bundle") | .value' -r | | |
sort -u \ | |
)" | |
# Find updates for image references | |
for old_ref in ${OLD_REFS}; do | |
repo_tag="${old_ref%@*}" | |
new_digest="$(skopeo inspect --no-tags docker://${repo_tag} | yq '.Digest')" | |
new_ref="${repo_tag}@${new_digest}" | |
[[ $new_ref == $old_ref ]] && continue | |
echo "New digest found! $new_ref" | |
for file in $FILES; do | |
sed -i "s!${old_ref}!${new_ref}!g" $file | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment