-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaster.cfg
322 lines (281 loc) · 8.31 KB
/
master.cfg
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
# -*- python -*-
# ex: set filetype=python:
from buildbot.plugins import *
import os
import shlex
from datetime import timedelta
c = BuildmasterConfig = {}
import user_config
current_dir = os.path.dirname(os.path.abspath(__file__))
## SECRETS MANAGEMENT
secrets_dir = os.path.join(current_dir, "master-secrets")
c["secretsProviders"] = [secrets.SecretInAFile(dirname=secrets_dir)]
## LOG JANITORING
c["configurators"] = [
util.JanitorConfigurator(
logHorizon=timedelta(weeks=16),
hour=12,
dayOfWeek=6,
)
]
## CHANGE SOURCES
# keep it empty here; we'll hook it from github via www
c["change_source"] = []
c["collapseRequests"] = True
## MASTER TO WORKER INTERFACE
# the master will listen here
c["protocols"] = {}
c["protocols"][user_config.master_protocol] = {"port": user_config.master_port}
## DATABASE
c["db"] = {
"db_url": user_config.master_db,
}
## WEB INTERFACE AND IDENTITY
# allow specific users from github org
authz = util.Authz(
allowRules=[util.AnyControlEndpointMatcher(role="buildbot")],
roleMatchers=[util.RolesFromGroups(groupPrefix="chimera-linux/")],
)
if user_config.github_client_id:
bauth = util.GitHubAuth(
user_config.github_client_id,
util.Secret("github-client-secret"),
apiVersion=4,
getTeamsMembership=True,
)
else:
bauth = None
c["title"] = user_config.title
c["titleURL"] = user_config.title_url
c["buildbotURL"] = user_config.bot_url
c["www"] = dict(
port=user_config.www_port,
authz=authz,
auth=bauth,
change_hook_dialects=dict(github={"secret": util.Secret("github-webhook-token")}),
plugins=dict(
waterfall_view={},
console_view={},
grid_view={},
),
)
## SERVICES
# TODO: irc bot
c["services"] = []
## MACHINE DEFINITION
#
# Here we conflate worker, scheduler, and builder into one, as there is one
# worker per architecture, one scheduler per worker, one builder per
# scheduler, in order to make sure all kick in upon changes being received
c["workers"] = []
c["schedulers"] = []
c["builders"] = []
@util.renderer
def sort_pkgs(props, cmd_base):
ret = cmd_base + ["bulk-print"]
# get packages list
pkgs = str(props.getProperty("pkgs_unbuilt")).strip().split("\n")
# map it
ret += map(lambda v: v.split("=")[0], pkgs)
# that's about it
return ret
@util.renderer
def make_build(props, cmd_base):
ret = []
# list of all pkgs, sorted in bulk order
pkgs = str(props.getProperty("pkgs_sorted")).split()
# get the versioned list and make it into a mapping
vermap = {}
for pkg in str(props.getProperty("pkgs_unbuilt")).strip().split("\n"):
pl = pkg.split("=")
if len(pl) == 2:
vermap[pl[0]] = pl[1]
# make up shellargs
for p in pkgs:
ret.append(
util.ShellArg(
command=cmd_base + ["--force-color", "--stage", "pkg", p],
logname=f"pkg:{p}={vermap[p] if p in vermap else 'unknown'}",
haltOnFailure=True,
)
)
# emit an unstage command if the list is non-empty
if ret:
ret.append(
util.ShellArg(
command=cmd_base + ["unstage"],
logname="unstage",
warnOnFailure=True,
)
)
return ret
def gen_machine(c, machdict):
archn = machdict["arch"]
workn = f"worker-{archn}"
schedn = f"scheduler-{archn}"
buildn = f"builder-{archn}"
# add worker for the arch
w = worker.Worker(
workn, util.Secret(f"pass-worker-{archn}"), properties={}, defaultProperties={}
)
c["workers"].append(w)
# add scheduler for the arch
s = schedulers.SingleBranchScheduler(
name=schedn,
change_filter=util.ChangeFilter(branch=user_config.cports_branch),
# give the changes a chance to accumulate
treeStableTimer=2,
builderNames=[buildn],
)
c["schedulers"].append(s)
# add force scheduler for the arch
sf = schedulers.ForceScheduler(
name=f"force-{schedn}",
buttonName="boop",
label="Poke the builder",
reason=util.StringParameter(
name="reason", label="Reason:", required=True, default="boop"
),
builderNames=[buildn],
)
c["schedulers"].append(sf)
# create build factory
f = util.BuildFactory()
cmd_base = ["./cbuild"]
# only pass if specified
if "config" in machdict:
cmd_base += ["-c", machdict["config"]]
if "opts" in machdict:
cmd_base += machdict["opts"]
rsync = [
"rsync",
"-amrt",
"--progress",
"--exclude",
"*.lock",
"-e",
user_config.repo_ssh,
]
rsync_dest = [
machdict["repo-src"],
f"{user_config.repo_dest}:{machdict['repo-dest']}",
]
f.addStep(
steps.Git(
repourl=user_config.cports_repo,
mode="incremental",
alwaysUseLatest=True,
name="cports_update",
description="Updating cports",
descriptionDone="Updated cports",
logEnviron=False,
haltOnFailure=True,
)
)
f.addStep(
steps.ShellCommand(
command=cmd_base + ["bootstrap-update"],
name="bldroot_update",
description="Bldroot update",
descriptionDone="Bldroot updated",
logEnviron=False,
haltOnFailure=True,
env={"PYTHONUNBUFFERED": "1"},
)
)
# unsorted, but versioned
f.addStep(
steps.SetPropertyFromCommand(
command=cmd_base + ["list-unbuilt"],
property="pkgs_unbuilt",
name="find_unbuilt",
description="Find unbuilt",
descriptionDone="Found unbuilt",
logEnviron=False,
haltOnFailure=True,
env={"PYTHONUNBUFFERED": "1"},
)
)
# get a bulk-sorted, plain list
f.addStep(
steps.SetPropertyFromCommand(
command=sort_pkgs.withArgs(cmd_base),
property="pkgs_sorted",
name="sort_unbuilt",
description="Sort unbuilt",
descriptionDone="Sorted unbuilt",
logEnviron=False,
haltOnFailure=True,
env={"PYTHONUNBUFFERED": "1"},
)
)
f.addStep(
steps.ShellSequence(
commands=make_build.withArgs(cmd_base),
name="build_packages",
description="Build packages",
descriptionDone="Built packages",
logEnviron=False,
haltOnFailure=True,
timeout=14400,
env={"PYTHONUNBUFFERED": "1"},
)
)
f.addStep(
steps.ShellCommand(
command=cmd_base + ["prune-pkgs"],
name="prune_packages",
description="Prune packages",
descriptionDone="Pruned packages",
logEnviron=False,
haltOnFailure=True,
env={"PYTHONUNBUFFERED": "1"},
)
)
f.addStep(
steps.ShellCommand(
command=rsync
+ [
"--exclude",
"*.gz",
]
+ rsync_dest,
name="upload_packages",
description="Upload packages",
descriptionDone="Uploaded packages",
logEnviron=False,
haltOnFailure=True,
)
)
f.addStep(
steps.ShellCommand(
command=rsync
+ [
"--delete",
]
+ rsync_dest,
name="sync_repos",
description="Synchronize repos",
descriptionDone="Synchronized repos",
logEnviron=False,
haltOnFailure=True,
)
)
if user_config.repo_post:
f.addStep(
steps.ShellCommand(
command=shlex.split(user_config.repo_ssh)
+ [user_config.repo_dest]
+ user_config.repo_post,
name=user_config.repo_hook,
description=user_config.repo_hookdesc,
descriptionDone=user_config.repo_hookdone,
logEnviron=False,
warnOnFailure=True,
)
)
# add builder for the arch
b = util.BuilderConfig(name=buildn, workernames=[workn], factory=f)
c["builders"].append(b)
for machdict in user_config.machines:
gen_machine(c, machdict)