forked from SeldonIO/seldon-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
518 lines (444 loc) · 15.1 KB
/
release.py
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
#
# release.py
#
import yaml
from io import StringIO
import pprint
from subprocess import Popen, PIPE
import os
import sys
import argparse
import json
def pp(o):
pprinter = pprint.PrettyPrinter(indent=4)
pprinter.pprint(o)
def getOpts(cmd_line_args):
parser = argparse.ArgumentParser(description="Set seldon-core version")
parser.add_argument("-d", "--debug", action="store_true", help="turn on debugging")
parser.add_argument("seldon_core_version", help="the version to set")
opts = parser.parse_args(cmd_line_args)
return opts
def dict_to_yaml(d):
return yaml.dump(d, default_flow_style=False)
def yaml_to_dict(yaml_data):
return yaml.load(StringIO(yaml_data), Loader=yaml.FullLoader)
def run_command(args, debug=False):
err, out = None, None
if debug:
print("cwd[{}]".format(os.getcwd()))
print("Executing: " repr(args))
p = Popen(args, stdout=PIPE, stderr=PIPE)
if p.wait() == 0:
out = p.stdout.read()
out = out.strip()
else:
err = {}
if p.stderr != None:
err["stderr"] = p.stderr.read()
err["stderr"] = err["stderr"].strip()
if p.stdout != None:
err["stdout"] = p.stdout.read()
err["stdout"] = err["stdout"].strip()
return err, out
def update_pom_file(fpath, seldon_core_version, debug=False):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
comp_dir_path = os.path.dirname(fpath)
cwd = os.getcwd()
os.chdir(comp_dir_path)
MAVEN_REPOSITORY_LOCATION = os.getenv("MAVEN_REPOSITORY_LOCATION")
if MAVEN_REPOSITORY_LOCATION == None:
args = [
"mvn",
"versions:set",
"-DnewVersion={seldon_core_version}".format(**locals()),
]
else:
args = [
"mvn",
"versions:set",
"-DnewVersion={seldon_core_version}".format(**locals()),
"-Dmaven.repo.local={MAVEN_REPOSITORY_LOCATION}".format(**locals()),
]
err, out = run_command(args, debug)
if err == None:
print("updated {fpath}".format(**locals()))
else:
print("error {fpath}".format(**locals()))
print(err)
os.chdir(cwd)
def update_chart_yaml_file(fpath, seldon_core_version, debug=False):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
f = open(fpath)
yaml_data = f.read()
f.close()
d = yaml_to_dict(yaml_data)
d["version"] = seldon_core_version
with open(fpath, "w") as f:
f.write(dict_to_yaml(d))
print("updated {fpath}".format(**locals()))
def update_helm_values_yaml_file_default_images(
fpath, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
"s/version: \(.*\)/version: {seldon_core_version}/".format(**locals()),
fpath,
]
err, out = run_command(args, debug)
if err == None:
print("updated helm values yaml for default images".format(**locals()))
else:
print("error updating helm values yaml for default images".format(**locals()))
print(err)
def update_operator_values_yaml_file_core_images(
fpath, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
"s/tag: \(.*\)/tag: {seldon_core_version}/".format(**locals()),
fpath,
]
err, out = run_command(args, debug)
if err == None:
print("updated operator values yaml for core images".format(**locals()))
else:
print("error updating operator values yaml for core images".format(**locals()))
print(err)
def update_operator_values_yaml_file_prepackaged_images(
current_seldon_core_version, fpath, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
's/defaultImageVersion: "{current_seldon_core_version}"/defaultImageVersion: "{seldon_core_version}"/'.format(
**locals()
),
fpath,
]
err, out = run_command(args, debug)
if err == None:
print(
"updated operator values yaml for prepackaged server images".format(
**locals()
)
)
else:
print(
"error updating operator values yaml for prepackaged server images".format(
**locals()
)
)
print(err)
def update_operator_values_yaml_file_explainer_image(
fpath, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
"s|seldonio/alibiexplainer:\(.*\)|seldonio/alibiexplainer:{seldon_core_version}|".format(
**locals()
),
fpath,
]
err, out = run_command(args, debug)
if err == None:
print(
"updated operator values yaml for prepackaged server images".format(
**locals()
)
)
else:
print(
"error updating operator values yaml for prepackaged server images".format(
**locals()
)
)
print(err)
def update_operator_kustomize_prepackaged_images(
current_seldon_core_version, fpath, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
's/"defaultImageVersion": "{current_seldon_core_version}"/"defaultImageVersion": "{seldon_core_version}"/'.format(
**locals()
),
fpath,
]
err, out = run_command(args, debug)
if err == None:
print(
"updated operator kustomize yaml for prepackaged server images".format(
**locals()
)
)
else:
print(
"error updating operator kustomize yaml for prepackaged server images".format(
**locals()
)
)
print(err)
def update_versions_txt(seldon_core_version, debug=False):
with open("version.txt", "w") as f:
f.write("{seldon_core_version}\n".format(**locals()))
print("Updated version.txt")
def get_current_version():
with open("version.txt", "r") as f:
version = f.read()
print("Current version fron version.txt", version)
return version.strip()
def update_versions_py(seldon_core_version, debug=False):
# Updating the version in setup.py
args = [
"sed",
"-i",
's/version="\(.*\)"/version="{seldon_core_version}"/g'.format(**locals()),
"python/setup.py",
]
err, out = run_command(args, debug)
# Updating the version in module __version__.py
with open("python/seldon_core/version.py", "w") as f:
f.write('__version__ = "{seldon_core_version}"\n'.format(**locals()))
print("Updated python/seldon_core/version.py")
def update_kustomize_engine_version(seldon_core_version, debug=False):
args = [
"sed",
"-i",
"s/docker.io\/seldonio\/engine:\(.*\)/docker.io\/seldonio\/engine:{seldon_core_version}/g".format(
**locals()
),
"operator/config/manager/manager.yaml",
]
err, out = run_command(args, debug)
if err == None:
print("updated kustomize".format(**locals()))
else:
print("error updating kustomize".format(**locals()))
print(err)
def update_kustomize_executor_version(seldon_core_version, debug=False):
args = [
"sed",
"-i",
"s/seldonio\/seldon-core-executor:\(.*\)/seldonio\/seldon-core-executor:{seldon_core_version}/g".format(
**locals()
),
"operator/config/manager/manager.yaml",
]
err, out = run_command(args, debug)
if err == None:
print("updated kustomize".format(**locals()))
else:
print("error updating kustomize".format(**locals()))
print(err)
def update_operator_version(seldon_core_version, debug=False):
fpath = "operator/config/manager/kustomization.yaml"
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
"s/newTag: .*/newTag: {seldon_core_version}/".format(**locals()),
fpath,
]
err, out = run_command(args, debug)
if err == None:
print("updated {fpath}".format(**locals()))
else:
print("error updating {fpath}".format(**locals()))
print(err)
def update_image_metadata_json(seldon_core_version, debug=False):
paths = [
"examples/models/mean_classifier/image_metadata.json",
"servers/tfserving_proxy/image_metadata.json",
"servers/sklearnserver/sklearnserver/image_metadata.json",
"servers/mlflowserver/mlflowserver/image_metadata.json",
"servers/xgboostserver/xgboostserver/image_metadata.json",
]
for path in paths:
path = os.path.realpath(path)
if debug:
print("processing [{}]".format(path))
with open(path) as json_file:
data = json.load(json_file)
for label in data["labels"]:
if "version" in label:
label["version"] = f"{seldon_core_version}"
with open(path, "w") as outfile:
json.dump(data, outfile)
def update_dockerfile_label_version(seldon_core_version, debug=False):
paths = [
"operator/Dockerfile.redhat",
"engine/Dockerfile.redhat",
"executor/Dockerfile.executor",
"executor/Dockerfile.executor.redhat",
"servers/tfserving/Dockerfile.redhat",
"components/alibi-detect-server/Dockerfile",
"components/storage-initializer/Dockerfile",
"components/seldon-request-logger/Dockerfile",
"components/alibi-explain-server/Dockerfile",
]
replaces = [
f's/version=".*" \\\\/version="{seldon_core_version}" \\\\/',
f"s/ubi8:.*/ubi8:{seldon_core_version}/",
]
for path in paths:
for replace in replaces:
if debug:
print("processing [{}]".format(path))
args = [
"sed",
"-i",
replace,
path,
]
err, out = run_command(args, debug)
if err == None:
print("updated {path}".format(**locals()))
else:
print("error updating {path}".format(**locals()))
print(err)
def update_python_wrapper_fixed_versions(seldon_core_version, debug=False):
args = [
"./hack/update_python_version.sh",
"{seldon_core_version}".format(**locals()),
]
err, out = run_command(args, debug)
if err == None:
print("Updated python wrapper in matching files".format(**locals()))
else:
print("error updating python wrapper in matching files".format(**locals()))
print(err)
def set_version(
current_seldon_core_version,
seldon_core_version,
pom_files,
chart_yaml_files,
operator_values_yaml_file,
operator_kustomize_yaml_file,
abtest_yaml_file,
mab_yaml_file,
debug=False,
):
update_python_wrapper_fixed_versions(seldon_core_version, debug)
# Normalize file paths
pom_files_realpaths = [os.path.realpath(x) for x in pom_files]
chart_yaml_file_realpaths = [os.path.realpath(x) for x in chart_yaml_files]
operator_values_yaml_file_realpath = (
os.path.realpath(operator_values_yaml_file)
if operator_values_yaml_file != None
else None
)
operator_kustomize_yaml_file_realpath = (
os.path.realpath(operator_kustomize_yaml_file)
if operator_kustomize_yaml_file != None
else None
)
abtest_yaml_file_realpath = (
os.path.realpath(abtest_yaml_file) if abtest_yaml_file != None else None
)
mab_values_yaml_file_realpath = (
os.path.realpath(mab_yaml_file) if mab_yaml_file != None else None
)
# Update kustomize
update_kustomize_engine_version(seldon_core_version, debug)
update_kustomize_executor_version(seldon_core_version, debug)
#
# Update operator version
update_operator_version(seldon_core_version, debug)
#
# Update top level versions.txt
update_versions_txt(seldon_core_version, debug)
#
# Update version.py in python/seldon_core
update_versions_py(seldon_core_version, debug)
#
# update the pom files
for fpath in pom_files_realpaths:
update_pom_file(fpath, seldon_core_version, debug)
# update the helm chart files
for chart_yaml_file_realpath in chart_yaml_file_realpaths:
update_chart_yaml_file(chart_yaml_file_realpath, seldon_core_version, debug)
# update the operator helm values file
if operator_values_yaml_file != None:
update_operator_values_yaml_file_core_images(
operator_values_yaml_file_realpath, seldon_core_version, debug
)
# update the operator helm values files
if mab_yaml_file != None:
update_helm_values_yaml_file_default_images(
mab_values_yaml_file_realpath, seldon_core_version, debug
)
if abtest_yaml_file != None:
update_helm_values_yaml_file_default_images(
abtest_yaml_file_realpath, seldon_core_version, debug
)
if operator_values_yaml_file != None:
update_operator_values_yaml_file_prepackaged_images(
current_seldon_core_version,
operator_values_yaml_file_realpath,
seldon_core_version,
debug,
)
update_operator_values_yaml_file_explainer_image(
operator_values_yaml_file_realpath, seldon_core_version, debug
)
if operator_kustomize_yaml_file != None:
update_operator_kustomize_prepackaged_images(
current_seldon_core_version,
operator_kustomize_yaml_file_realpath,
seldon_core_version,
debug,
)
# Update image version labels
update_image_metadata_json(seldon_core_version, debug)
update_dockerfile_label_version(seldon_core_version, debug)
def main(argv):
POM_FILES = ["engine/pom.xml"]
CHART_YAML_FILES = [
"helm-charts/seldon-core-operator/Chart.yaml",
"helm-charts/seldon-core-analytics/Chart.yaml",
]
OPERATOR_VALUES_YAML_FILE = "helm-charts/seldon-core-operator/values.yaml"
OPERATOR_KUSTOMIZE_CONFIGMAP = "operator/config/manager/configmap.yaml"
AB_VALUES_YAML_FILE = "helm-charts/seldon-abtest/values.yaml"
MAB_VALUES_YAML_FILE = "helm-charts/seldon-mab/values.yaml"
opts = getOpts(argv[1:])
current_version = get_current_version()
if opts.debug:
pp(opts)
set_version(
current_version,
opts.seldon_core_version,
POM_FILES,
CHART_YAML_FILES,
OPERATOR_VALUES_YAML_FILE,
OPERATOR_KUSTOMIZE_CONFIGMAP,
AB_VALUES_YAML_FILE,
MAB_VALUES_YAML_FILE,
opts.debug,
)
print("done")
if __name__ == "__main__":
main(sys.argv)