forked from SeldonIO/seldon-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
670 lines (584 loc) · 20.7 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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
#
# 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_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
d["appVersion"] = 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_storage_initializer(
fpath, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
"s|seldonio/rclone-storage-initializer:\(.*\)|seldonio/rclone-storage-initializer:{seldon_core_version}|".format(
**locals()
),
fpath,
]
err, out = run_command(args, debug)
if err == None:
print("updated operator values yaml for storage initializer".format(**locals()))
else:
print(
"error updating operator values yaml for storage initializer".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_operator_kustomize_alibiexplainer_image(
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#seldonio/alibiexplainer:{current_seldon_core_version}#seldonio/alibiexplainer:{seldon_core_version}#'.format(
**locals()
),
fpath,
]
err, out = run_command(args, debug)
if err == None:
print(
"updated operator kustomize yaml for alibi explainer image".format(
**locals()
)
)
else:
print(
"error updating operator kustomize yaml for alibi explainer image".format(
**locals()
)
)
print(err)
def update_alibi_detect_image(
fpath, current_seldon_core_version, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
f"s|seldonio/alibi-detect-server:{current_seldon_core_version}|seldonio/alibi-detect-server:{seldon_core_version}|",
fpath,
]
err, out = run_command(args, debug)
if err is None:
print(f"updated alibi-detect-server version in {fpath}")
else:
print(f"error updating alibi-detect-server version in {fpath}")
print(err)
def update_echo_model_image(
fpath, current_seldon_core_version, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
f"s|seldonio/echo-model:{current_seldon_core_version}|seldonio/echo-model:{seldon_core_version}|",
fpath,
]
err, out = run_command(args, debug)
if err is None:
print(f"updated echo-model version in {fpath}")
else:
print(f"error updating echo-model version in {fpath}")
print(err)
def update_models_version(
fpath, model_name, current_seldon_core_version, seldon_core_version, debug=False
):
fpath = os.path.realpath(fpath)
if debug:
print("processing [{}]".format(fpath))
args = [
"sed",
"-i",
f"s|gs://seldon-models/v{current_seldon_core_version}/{model_name}|gs://seldon-models/v{seldon_core_version}/{model_name}|",
fpath,
]
err, out = run_command(args, debug)
if err == None:
print(
f"updated model uri gs://seldon-models/v:{seldon_core_version}{model_name} in {fpath}"
)
else:
print(
f"error updating model uri gs://seldon-models/v:{seldon_core_version}{model_name} in {fpath}"
)
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 from 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_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",
"executor/Dockerfile.executor",
"executor/Dockerfile.executor.redhat",
"servers/tfserving/Dockerfile.redhat",
"components/alibi-detect-server/Dockerfile",
"components/storage-initializer/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,
chart_yaml_files,
operator_values_yaml_file,
operator_kustomize_yaml_file,
alibi_detect_image_files,
echo_model_image_files,
abtest_yaml_file,
mab_yaml_file,
model_uri_updates,
debug=False,
):
update_python_wrapper_fixed_versions(seldon_core_version, debug)
# Normalize file paths
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_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 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
)
update_operator_values_yaml_file_storage_initializer(
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_operator_kustomize_alibiexplainer_image(
current_seldon_core_version,
operator_kustomize_yaml_file_realpath,
seldon_core_version,
debug,
)
# update models' uris
for model_name, paths in model_uri_updates.items():
for fpath in paths:
update_models_version(
fpath, model_name, current_seldon_core_version, seldon_core_version
)
# update alibi detect image references
for fpath in alibi_detect_image_files:
update_alibi_detect_image(fpath, current_seldon_core_version, seldon_core_version)
# update echo image references
for fpath in echo_model_image_files:
update_echo_model_image(fpath, current_seldon_core_version, seldon_core_version)
# Update image version labels
update_image_metadata_json(seldon_core_version, debug)
update_dockerfile_label_version(seldon_core_version, debug)
def main(argv):
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"
MODEL_URI_UPDATES = {
"sklearn/iris": [
"servers/sklearnserver/samples/iris.yaml",
"servers/sklearnserver/samples/iris_custom.yaml",
"servers/sklearnserver/samples/iris_predict.yaml",
"testing/benchmarking/automated-benchmark/README.ipynb",
"testing/scripts/test_benchmark.py",
"notebooks/server_examples.ipynb",
"notebooks/resources/istio_shadow.yaml",
"examples/streaming/knative-eventing/README.ipynb",
"examples/streaming/knative-eventing/README.md",
"examples/streaming/knative-eventing/assets/simple-iris-deployment.yaml",
"examples/security/ssl_requests/README.ipynb",
"examples/security/ssl_requests/README.md",
"examples/iter8/progressive_rollout/separate_sdeps/abtest.ipynb",
"examples/iter8/progressive_rollout/separate_sdeps/baseline.yaml",
"examples/iter8/progressive_rollout/single_sdep/abtest.ipynb",
"examples/iter8/progressive_rollout/single_sdep/abtest.yaml",
"examples/iter8/progressive_rollout/single_sdep/promote-v1.yaml",
"examples/init_containers/custom_init_container.ipynb",
"examples/feedback/feedback-metrics-server/README.ipynb",
"examples/feedback/feedback-metrics-server/README.md",
"examples/feedback/metrics-server/README.ipynb",
"examples/feedback/metrics-server/README.md",
"examples/batch/argo-workflows-batch/helm-charts/seldon-batch-workflow/values.yaml",
"examples/batch/hdfs-argo-workflows/deployment.yaml",
"examples/batch/hdfs-argo-workflows/hdfs-batch.ipynb",
"examples/batch/kubeflow-pipelines-batch/README.ipynb",
"examples/batch/kubeflow-pipelines-batch/README.md",
"examples/batch/kubeflow-pipelines-batch/assets/seldon-batch-pipeline.py",
"doc/source/workflow/quickstart.md",
"doc/source/servers/kfserving-storage-initializer.md",
"doc/source/servers/overview.md",
"doc/source/servers/sklearn.md",
"doc/source/graph/protocols.md",
"doc/source/rollouts/abtests.md",
"README.md",
],
"sklearn/moviesentiment": [
"testing/resources/movies-text-explainer.yaml",
"notebooks/explainer_examples.ipynb",
"notebooks/resources/moviesentiment_explainer.yaml",
],
"elasticnet_wine": [
"notebooks/server_examples.ipynb",
],
}
ALIBI_DETECT_FILES = [
"testing/resources/adserver-cifar10-od-rclone.yaml",
"testing/resources/adserver-cifar10-od.yaml",
"examples/feedback/metrics-server/README.ipynb",
"examples/feedback/feedback-metrics-server/README.md",
]
ECHO_MODEL_FILES = [
"examples/models/metrics/metrics.ipynb",
]
opts = getOpts(argv[1:])
current_version = get_current_version()
if opts.debug:
pp(opts)
set_version(
current_version,
opts.seldon_core_version,
CHART_YAML_FILES,
OPERATOR_VALUES_YAML_FILE,
OPERATOR_KUSTOMIZE_CONFIGMAP,
ALIBI_DETECT_FILES,
ECHO_MODEL_FILES,
AB_VALUES_YAML_FILE,
MAB_VALUES_YAML_FILE,
MODEL_URI_UPDATES,
opts.debug,
)
print("done")
if __name__ == "__main__":
main(sys.argv)