forked from SeldonIO/seldon-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
251 lines (210 loc) · 6.8 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
#
# release.py
#
import yaml
from io import StringIO
import pprint
from subprocess import Popen, PIPE
import os
import sys
import argparse
import re
import shutil
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)
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)
##pp(out)
##pp(err)
if err == None:
print("updated {fpath}".format(**locals()))
else:
print("error {fpath}".format(**locals()))
print(err)
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_operator_values_yaml_file(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)
# pp(out)
# pp(err)
if err == None:
print("updated operator values yaml".format(**locals()))
else:
print("error updating operator values yaml".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 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)
# pp(out)
# pp(err)
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)
# pp(out)
# pp(err)
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 set_version(
seldon_core_version,
pom_files,
chart_yaml_files,
operator_values_yaml_file,
debug=False,
):
# 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
)
# 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 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(
operator_values_yaml_file_realpath, 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"
opts = getOpts(argv[1:])
if opts.debug:
pp(opts)
set_version(
opts.seldon_core_version,
POM_FILES,
CHART_YAML_FILES,
OPERATOR_VALUES_YAML_FILE,
opts.debug,
)
print("done")
if __name__ == "__main__":
main(sys.argv)