forked from kubev2v/forklift
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-tekton.sh
More file actions
executable file
·44 lines (39 loc) · 1.35 KB
/
update-tekton.sh
File metadata and controls
executable file
·44 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Use this script to update the Tekton Task Bundle references used in a Pipeline or a PipelineRun.
# update-tekton-task-bundles.sh .tekton/*.yaml
set +e -uo pipefail
FILES=$@
# Find existing image references
OLD_REFS="$(
yq '... | select(has("resolver")) | .params // [] | .[] | select(.name == "bundle") | .value' $FILES |
grep -v -- '---' |
sort -u
)"
# Find updates for image references
for old_ref in ${OLD_REFS}; do
repo_tag="${old_ref%@*}"
task_ver=${repo_tag#*:}
task_x=${task_ver%.*}
task_y=$((${task_ver#*.} + 1))
task_name=${repo_tag%:*}
new_digest=$(skopeo inspect --no-tags docker://${task_name}:${task_x}.${task_y} 2>/dev/null)
if [[ $? -eq 0 ]]; then
new_digest=$(echo $new_digest | yq '.Digest')
new_ref="${task_name}:${task_x}.${task_y}@${new_digest}"
echo "New digest and version found! $new_ref"
if [[ $SKIP_UPDATE == "true" ]]; then continue; fi
for file in $FILES; do
sed -i -e "s!${old_ref}!${new_ref}!g" $file
done
continue
else
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"
if [[ $SKIP_UPDATE == "true" ]]; then continue; fi
for file in $FILES; do
sed -i -e "s!${old_ref}!${new_ref}!g" $file
done
fi
done