forked from tektoncd/operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-releases.sh
executable file
·288 lines (234 loc) · 8.85 KB
/
fetch-releases.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env bash
set -u -e
declare -r SCRIPT_DIR=$(cd $(dirname "$0")/.. && pwd)
TARGET=""
FORCE_FETCH_RELEASE=""
# release_yaml <component> <release-yaml-name> <target-file-name> <version>
release_yaml() {
echo fetching '|' component: ${1} '|' file: ${3} '|' version: ${4}
local comp=$1
local releaseFileName=$2
local destFileName=$3
local version=$4
# directory name => tekton-<component>
# tekton-pipeline tekton-trigger
local dir=$1
if [[ $comp == "triggers" ]]; then
dir="trigger"
fi
if [[ $comp == "dashboard" ]]; then
if [[ ${releaseFileName} == "release-full" ]]; then
dir="dashboard/tekton-dashboard-fullaccess"
fi
if [[ ${releaseFileName} == "release" ]]; then
dir="dashboard/tekton-dashboard-readonly"
fi
fi
#nightly -> 0.0.0-nightly`
#latest -> find version till then -> 0.0.0-latest
#version -> directory with version
url=""
case $version in
nightly)
dirVersion="0.0.0-nightly"
url="https://storage.googleapis.com/tekton-releases-nightly/${comp}/latest/${releaseFileName}.yaml"
;;
latest)
dirVersion="0.0.0-latest"
url="https://storage.googleapis.com/tekton-releases/${comp}/latest/${releaseFileName}.yaml"
;;
*)
dirVersion=${version//v}
url="https://storage.googleapis.com/tekton-releases/${comp}/previous/${version}/${releaseFileName}.yaml"
;;
esac
ko_data=${SCRIPT_DIR}/cmd/${TARGET}/operator/kodata
comp_dir=${ko_data}/tekton-${dir}
dirPath=${comp_dir}/${dirVersion}
# destination file
dest=${dirPath}/${destFileName}.yaml
if [ -f "$dest" ] && [ $FORCE_FETCH_RELEASE = "false" ]; then
label="app.kubernetes.io/version: \"$version\""
label2="app.kubernetes.io/version: $version"
label3="version: \"$version\""
if grep -Eq "$label" $dest || grep -Eq "$label2" $dest || grep -Eq "$label3" $dest;
then
echo "release file already exist with required version, skipping!"
echo ""
return
fi
fi
# before adding releases, remove existing version directories
# ignore while adding for interceptors
if [[ ${releaseFileName} != "interceptors" ]] ; then
rm -rf ${comp_dir}/*
fi
# create a directory
mkdir -p ${dirPath} || true
http_response=$(curl -s -o ${dest} -w "%{http_code}" ${url})
echo url: ${url}
if [[ $http_response != "200" ]]; then
echo "Error: failed to get $comp yaml, status code: $http_response"
exit 1
fi
# Add OpenShift specific files for pipelines
if [[ ${TARGET} == "openshift" ]] && [[ ${comp} == "pipeline" ]]; then
cp -r ${ko_data}/openshift/00-prereconcile ${comp_dir}/
cp ${ko_data}/openshift/pipelines-rbac/* ${dirPath}/
fi
if [[ ${comp} == "dashboard" ]]; then
sed -i '/aggregationRule/,+3d' ${dest}
fi
echo "Info: Added $comp/$releaseFileName:$version release yaml !!"
if [[ ${comp} == "results" ]]; then
grep 'version' ${dest} | head -n 1 | tr -d ' ' || true
else
grep 'app.kubernetes.io/version' ${dest} | head -n 1 | sed 's/[[:space:]]*app.kubernetes.io\///' || true
fi
echo ""
}
# release_yaml_pac <component> <release-yaml-name> <version>
release_yaml_pac() {
echo fetching '|' component: ${1} '|' file: ${2} '|' version: ${3}
local comp=$1
local fileName=$2
local version=$3
ko_data=${SCRIPT_DIR}/cmd/${TARGET}/operator/kodata
dirPath=${ko_data}/tekton-addon/pipelines-as-code/${version}
if [[ ${version} == "stable" || ${version} == "nightly" ]]; then
url="https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code/${version}/release.yaml"
else
url="https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code/release-${version}/release.yaml"
fi
dest=${dirPath}/${fileName}.yaml
if [ -f "$dest" ] && [ $FORCE_FETCH_RELEASE = "false" ]; then
label="app.kubernetes.io/version: \"$version\""
if grep -Eq "$label" $dest;
then
echo "release file already exist with required version, skipping!"
echo ""
return
fi
else
rm -rf ${dirPath} || true
mkdir -p ${dirPath} || true
http_response=$(curl -s -o ${dest} -w "%{http_code}" ${url})
echo url: ${url}
if [[ $http_response != "200" ]]; then
echo "Error: failed to get $comp yaml, status code: $http_response"
exit 1
fi
echo "Info: Added $comp/$fileName:$version release yaml !!"
echo ""
fi
runtime=( go java nodejs python generic )
for run in "${runtime[@]}"
do
echo "fetching PipelineRun template for runtime: $run"
source="https://raw.githubusercontent.com/openshift-pipelines/pipelines-as-code/${version}/pkg/cmd/tknpac/generate/templates/${run}.yaml"
dest_dir="${ko_data}/tekton-addon/pipelines-as-code-templates"
mkdir -p ${dest_dir} || true
destination="${dest_dir}/${run}.yaml"
http_response=$(curl -s -o ${destination} -w "%{http_code}" ${source})
echo url: ${source}
if [[ $http_response != "200" ]]; then
echo "Error: failed to get pipelinerun template for $run, status code: $http_response"
exit 1
fi
done
echo ""
}
release_yaml_hub() {
echo fetching '|' component: ${1} '|' version: ${2}
local version=$2
ko_data=${SCRIPT_DIR}/cmd/${TARGET}/operator/kodata
if [ ${version} == "latest" ]
then
version=$(curl -sL https://api.github.com/repos/tektoncd/hub/releases | jq -r ".[].tag_name" | sort -Vr | head -n1)
dirPath=${ko_data}/tekton-hub/0.0.0-latest
else
dirPath=${ko_data}/tekton-hub/${version}
fi
mkdir -p ${dirPath} || true
url=""
components="db db-migration api ui hub-info"
for component in ${components}; do
echo fetching Hub '|' component: ${component} '|' version: ${2}
dest=${dirPath}/${component}
fileName=${component}.yaml
destinationFile=${dest}/${fileName}
if [ -f "$destinationFile" ] && [ $FORCE_FETCH_RELEASE = "false" ]; then
if grep -Eq "$version" $destinationFile;
then
echo "release file already exist with required version, skipping!"
echo ""
continue
fi
fi
rm -rf ${dest} || true
mkdir -p ${dest} || true
[[ ${component} == "api" ]] || [[ ${component} == "ui" ]] && fileName=${component}-${TARGET}.yaml
url="https://github.com/tektoncd/hub/releases/download/${version}/${fileName}"
echo $url
http_response=$(curl -s -L -o ${destinationFile} -w "%{http_code}" ${url})
echo url: ${url}
if [[ $http_response != "200" ]]; then
echo "Error: failed to get ${component} yaml, status code: $http_response"
exit 1
fi
echo "Info: Added Hub/$fileName:$version release yaml !!"
echo ""
done
}
fetch_openshift_addon_tasks() {
fetch_addon_task_script="${SCRIPT_DIR}/hack/openshift"
local dest_dir="cmd/openshift/operator/kodata/tekton-addon/addons/02-clustertasks/source_external"
${fetch_addon_task_script}/fetch-tektoncd-catalog-tasks.sh ${dest_dir}
}
copy_pruner_yaml() {
srcPath=${SCRIPT_DIR}/config/pruner
ko_data=${SCRIPT_DIR}/cmd/${TARGET}/operator/kodata
dstPath=${ko_data}/tekton-pruner
rm $dstPath -rf
cp $srcPath $dstPath -r
}
main() {
TARGET=$1
CONFIG=${2:=components.yaml}
FORCE_FETCH_RELEASE=$3
p_version=$(go run ./cmd/tool component-version ${CONFIG} pipeline)
t_version=$(go run ./cmd/tool component-version ${CONFIG} triggers)
c_version=$(go run ./cmd/tool component-version ${CONFIG} chains)
r_version=$(go run ./cmd/tool component-version ${CONFIG} results)
# get release YAML for Pipelines
release_yaml pipeline release 00-pipelines ${p_version}
# get release YAML for Triggers
release_yaml triggers release 00-triggers ${t_version}
release_yaml triggers interceptors 01-interceptors ${t_version}
# get release YAML for Chains
release_yaml chains release 00-chains ${c_version}
# get release YAML for Results
if [[ ${TARGET} == "openshift" ]]
then
release_yaml results release_base 00-results ${r_version}
else
release_yaml results release 00-results ${r_version}
fi
if [[ ${TARGET} != "openshift" ]]; then
d_version=$(go run ./cmd/tool component-version ${CONFIG} dashboard)
# get release YAML for Dashboard
release_yaml dashboard release-full 00-dashboard ${d_version}
release_yaml dashboard release 00-dashboard ${d_version}
else
pac_version=$(go run ./cmd/tool component-version ${CONFIG} pipelines-as-code)
release_yaml_pac pipelinesascode release ${pac_version}
fetch_openshift_addon_tasks
fi
hub_version=$(go run ./cmd/tool component-version ${CONFIG} hub)
release_yaml_hub hub ${hub_version}
# copy pruner rbac/sa yaml
copy_pruner_yaml
echo updated payload tree
find cmd/${TARGET}/operator/kodata
}
main $@