forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_istio_image_list.sh
executable file
·166 lines (148 loc) · 4.53 KB
/
gen_istio_image_list.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
#
# Copyright 2019 Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script generates the list of images used by Istio on the control
# plane, data plane as well as addons.We generate this list by looking
# at the values.yaml file where the Helm charts are stored, as well as
# reading the values of DOCKER_TARGETS rule in the istio-docker.mk file.
ISTIO_HELM_CHART=https://api.github.com/repos/istio/istio/contents/install/kubernetes/helm/istio/charts
ISTIO_GITHUB=https://raw.githubusercontent.com/istio/istio
function get_istio_images() {
buff=''
continue_processing=0
curl --silent "${ISTIO_GITHUB}/${1}/tools/istio-docker.mk" -o temp.file
while IFS= read -r line
do
if [[ $line == DOCKER_TARGETS* ]]
then
buff+=${line#DOCKER_TARGETS}
continue_processing=1
else
if [ $continue_processing -eq 1 ]
then
if [[ $line == *\\ ]]
then
buff=${buff%\\}$line
else
buff=${buff%\\}$line
break
fi
fi
fi
done < temp.file
for repo in $buff; do
if [[ $repo == *docker.* ]]
then
istio_component=${repo##*docker.};
istio_repo=istio/$istio_component;
echo docker.io/"$istio_repo":"${1}"
fi
done
if [ -f temp.file ];
then
rm temp.file
fi
}
function get_current_release() {
TAGS="$(curl --silent 'https://api.github.com/repos/istio/istio/tags' | grep -o '"name": "[0-9].[0-9].[0-9]"' | tr -d '"' )"
for tag in $TAGS;
do
if [[ $tag != name: ]]
then
if [[ $tag > $latest_tag ]]
then
latest_tag=$tag
fi
fi
done
echo "$latest_tag"
}
function get_istio_addons() {
branches=$(curl --silent "${ISTIO_HELM_CHART}?ref=${1}" | grep '"name": *' | tr -d '", ')
for branch in ${branches}; do
REPO=${branch##name:}
curl --silent "${ISTIO_GITHUB}/${1}/install/kubernetes/helm/istio/charts/${REPO}/values.yaml" -o temp.file
HUB=$(grep -E 'hub: |repository: ' temp.file | awk '{print $2 $4}')
IMAGE=$(grep "image: " temp.file | awk '{print $2 $4}')
TAG=$(grep "tag: " temp.file | awk '{print $2 $4}')
hubs=()
images=()
tags=()
for hub in ${HUB}; do
hubs+=( "$hub" );
done
for img in ${IMAGE}; do
images+=( "$img" );
done
for tag in ${TAG}; do
tags+=( "$tag" );
done
for i in "${!hubs[@]}"; do
if [ -z "${images[$i]}" ]
then
echo "${hubs[$i]}":"${tags[$i]}"
else
echo "${hubs[$i]}"/"${images[$i]}":"${tags[$i]}"
fi
done
done
if [ -f temp.file ];
then
rm temp.file
fi
}
function display_usage() {
echo
echo "List Istio images and addons for a given release. If release is not specified, it will list images for the latest Istio release."
echo
echo "USAGE: ./gen_istio_image_list.sh [-v|--version] [-h|--help]"
echo " -v|--version : Istio release"
echo " -h|--help : Prints usage information"
exit 1
}
# Process the input arguments.
while [[ "$#" -gt 0 ]];
do
case "$1" in
-v|--version )
if [ -z "$2" ];
then
echo "Please provide an Istio release."
display_usage
else
if [[ "$2" =~ [0-9].[0-9].[0-9] ]];
then
CURRENT_RELEASE="$2"
else
echo
echo "Enter a valid Istio release [<major>.<minor>.<LTS patch level>]"
echo
exit 1
fi
fi
shift 2;;
-h|--help )
display_usage ;;
* )
echo "Unknown argument: $1"
display_usage ;;
esac
done
if [ -z "${CURRENT_RELEASE}" ]
then
CURRENT_RELEASE=$(get_current_release)
fi
get_istio_images "${CURRENT_RELEASE}"
get_istio_addons "${CURRENT_RELEASE}"