-
Notifications
You must be signed in to change notification settings - Fork 0
/
set-compose-tags.sh
executable file
·49 lines (40 loc) · 1.09 KB
/
set-compose-tags.sh
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
45
46
47
48
49
source_images=$1
target_tag=${2:-"latest"}
composefile=${3:-"docker-compose.yml"}
print_file=${4:-True}
echo "tag to set: $target_tag"
echo "compose file: $composefile"
split() {
local string="$1"
local delimiter="$2"
if [ -n "$string" ]; then
local part
while read -d "$delimiter" part; do
echo $part
done <<< "$string"
echo $part
fi
}
images=$(split $source_images ";")
echo "got images to replace:"
for image in $images
do
echo "$image"
done
for image in $images
do
image_no_tag=$(echo "$image" | awk '{split($0,a,"[:]"); print a[1]}')
image_tag=$(echo "$image" | awk '{split($0,a,"[:]"); print a[2]}')
image_to_set="$image_no_tag:$target_tag"
echo "replacing $image with $image_to_set"
if [[ -z "$image_tag" ]]; then
sed -i -e "s|$image_no_tag$|$image_to_set|g" "$composefile"
sed -i -e "s|$image_no_tag:.*|$image_to_set|g" "$composefile"
else
sed -i -e "s|$image_no_tag:$image_tag|$image_to_set|g" "$composefile"
fi
done
if [[ "$print_file" = "True" ]]; then
echo "----final file-----"
cat "$composefile"
fi