summaryrefslogtreecommitdiff
path: root/buildbot/master.cfg
blob: 188de9fe513d2c2fb61d8d3e03d2a46fe173c63d (plain)
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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
# -*- python -*-
# ex: set syntax=python:

##
# This file is part of TALER
# (C) 2016-2023 Taler Systems SA
#
# TALER is free software; you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public
# License as published by the Free Software Foundation; either
# version 3, or (at your option) any later version.
#
# TALER is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with TALER; see the file COPYING.  If not,
# see <http://www.gnu.org/licenses/>
#
# @author Florian Dold
# @author Marcello Stanisci
# @author ng0
# @author Christian Grothoff
# @author Devan Carpenter
import ast
import configparser
import glob
import os
import pathlib
import pwd
import re
import subprocess

from buildbot.changes.pb import PBChangeSource
from buildbot.steps.source.git import Git
from buildbot.steps.shell import ShellCommand
from buildbot.plugins import changes
from buildbot.plugins import reporters
from buildbot.plugins import schedulers
from buildbot.plugins import steps
from buildbot.plugins import util
from buildbot.process import buildstep, logobserver
from buildbot.reporters.generators.build import BuildStatusGenerator
from buildbot.worker import Worker
from twisted.internet import defer

# This is a sample buildmaster config file. It must be
# installed as 'master.cfg' in your buildmaster's base
# directory.

# This file has the following structure:
# - Globals: definition of global variables we use throughout
#   + Convenience functions: helper functions useful for many jobs
# - Jobs: actual job definitions
# - General purpose: triggers and alerts shared by various jobs
#   + general purpose notification (alerts)
#   + general purpose triggers (schedulers)
# - Actual buildbot configuration object initialization

#################################################################
######################### GLOBALS ###############################
#################################################################

# The 'workers' list defines the set of recognized workers.
# Each element is a Worker object, specifying a unique worker
# name and password.  The same worker name and password must
# be configured on the worker.
WORKERS = []

# 'services' is a list of BuildbotService items like reporter
# targets. The status of each build will be pushed to these
# targets. buildbot/reporters/*.py has a variety to choose from,
# like IRC bots.


class MessageFormatterWithStdout(reporters.MessageFormatter):
    def buildAdditionalContext(self, master, ctx):
        stdout = []
        for step in ctx["build"]["steps"]:
            for log in step["logs"]:
                all_logs = log["content"]["content"].splitlines()
                # Including only what the script printed on stdout.
                for line in all_logs:
                    if re.search("^o", line):
                        stdout.append(line[1:])
        ctx.update(dict(stdout="\n".join(stdout)))

# tipReserveEmails = reporters.MailNotifier(
#     fromaddr="buildbot@taler.net", # to be sent to a dedicate alias
#     sendToInterestedUsers=False,
#     mode=("all"),
#     builders=["check-tips-builder"], # This builder has been removed - Javisep.
#     extraRecipients=["tips@taler.net"],
#     dumpMailsToLog=True, # debug, to remove
#     messageFormatter=MessageFormatterWithStdout(
#         wantSteps=True,
#         wantLogs=True,
#         template="{{ stdout }}",
#         subject="tips availability on demo")
# )


SERVICES = []

# The 'builders' list defines the Builders, which tell Buildbot
# how to perform a build: what steps, and which workers can execute
# them.  Note that any particular build will only take place on
# one worker.
BUILDERS = []

# Configures the Schedulers, which decide how to react to incoming
# changes.
SCHEDULERS = []

# Array of builders to be scheduled every night.
NIGHTLY_TRIGGERS=[]

# Array of builders to be scheduled whenever any of the code Git repos change
CODECHANGE_TRIGGERS = []

# Array of builders to be scheduled whenever the wallet-core or
# deployment change
WALLETCHANGE_TRIGGERS = []

# Array of builder names for which build status reports should be sent
# via e-mail
EMAIL_ALERTS = []

# Array of email address for which build status reports shoudl be sent
BUILDER_EMAIL_ADDRESSES = []

############ Convenience functions #################

# Create a FACTORY with a deployment.git checkout as the first step.
def create_factory_with_deployment():
    f = util.BuildFactory()
    update_deployment(f)
    return f


# Convenience function that checks out a Git repository.
# First argument is the URL of the Git to clone, second
# the desired branch. Default is 'master'.
def git_step(repo, target_branch="master"):
    return Git(
        repourl=repo,
        mode="full",
        method="fresh",
        logEnviron=False,
        alwaysUseLatest=True,
        haltOnFailure=True,
        branch=target_branch
    )


# Convenience function that runs 'make check' in a
# directory of the code inside of a netjail.
def jailed_check(package, srcdirs):
    return steps.ShellSequence(
        name="Tests of " + package,
        description="Testing " + package,
        descriptionDone="Pass",
        commands=map(lambda srcdir: util.ShellArg(command=["sudo", "/usr/local/bin/netjail.sh", "/home/integrationtest/deployment/buildbot/with-postgres.sh", "bash", "-c", "'cd src/"+srcdir+" make install check'"]), srcdirs),
        env={'PATH': "${HOME}/local/bin:${PATH}"},
        workdir="../../sources/" + package
    )


# Convenience function that checks out the deployment.
def update_deployment(factory):
    factory.addStep(steps.ShellSequence(
        name="update deployment",
        description="removing old deployment and fetching fresh repository",
        descriptionDone="Deployment updated",
        commands=[
            util.ShellArg(command=["rm", "-rf", "deployment"]),
            util.ShellArg(command=["git", "clone", "git://git.taler.net/deployment"]),
        ],
        haltOnFailure=True,
        workdir="../.."
    ))


# Convenience function that builds and runs a container.
def container_add_step(HALT_ON_FAILURE,
                       WARN_ON_FAILURE,
                       CONTAINER_BUILD,
                       CONTAINER_NAME,
                       factory,
                       WORK_DIR,
                       stepName,
                       CONTAINER_ARCH="amd64",
                       jobCmd="/workdir/contrib/ci/ci.sh",
                       containerFile="contrib/ci/Containerfile"):
    print(f"HALT_ON_FAILURE: {HALT_ON_FAILURE}, WARN_ON_FAILURE: {WARN_ON_FAILURE}, CONTAINER_BUILD: {CONTAINER_BUILD}, CONTAINER_NAME: {CONTAINER_NAME}")
    if not CONTAINER_BUILD:
        return steps.ShellSequence(
                name=stepName,
                commands=[
                    util.ShellArg(command=["podman", "run", "--rm",
                                           "--arch", CONTAINER_ARCH,
                                           "--add-host", "taler.host.internal:10.0.2.2",
                                           "--network", "slirp4netns:allow_host_loopback=true",
                                           "--env", util.Interpolate("CI_COMMIT_REF=%(src::revision)s"),
                                           "--env", util.Interpolate("CI_GIT_BRANCH=%(src::branch)s"),
                                           "--volume", f"{WORK_DIR}:/workdir",
                                           "--volume", "/home/container-worker/container_artifacts:/artifacts",
                                           "--workdir", "/workdir",
                                           CONTAINER_NAME, jobCmd],
                                  logname='run inside container',
                                  haltOnFailure=HALT_ON_FAILURE),
                    ],
                haltOnFailure=HALT_ON_FAILURE,
                workdir=WORK_DIR
                )
    else:
        return steps.ShellSequence(
                name=stepName,
                commands=[
                    util.ShellArg(command=["podman", "build", "-t", CONTAINER_NAME,
                                           "--arch", CONTAINER_ARCH,
                                           "-f", containerFile, "."],
                                  logname='build container', haltOnFailure=True),
                    util.ShellArg(command=["podman", "run", "--rm",
                                           "--arch", CONTAINER_ARCH,
                                           "--add-host", "taler.host.internal:10.0.2.2",
                                           "--network", "slirp4netns:allow_host_loopback=true",
                                           "--env", util.Interpolate("CI_COMMIT_REF=%(src::revision)s"),
                                           "--env", util.Interpolate("CI_GIT_BRANCH=%(src::branch)s"),
                                           "--volume", f"{WORK_DIR}:/workdir",
                                           "--volume", "/home/container-worker/container_artifacts:/artifacts",
                                           "--volume", f"/run/user/{pwd.getpwnam('container-worker').pw_uid}/podman/podman.sock:/run/podman/podman.sock",
                                           "--security-opt", "label=disable",
                                           "--workdir", "/workdir",
                                           CONTAINER_NAME, jobCmd],
                                  logname='run inside container',
                                  haltOnFailure=HALT_ON_FAILURE),
                    ],
                haltOnFailure=HALT_ON_FAILURE,
                workdir=WORK_DIR
                )

##################################################################
######################## JOBS ####################################
##################################################################

# For every job, we have (in this order!):
# - worker(s): hosts/users that run the job
# - factory: list of steps that define what to do
# - builder: gives the job a name and binds it to the factory and worker
# - (OPTIONAL) alerts: notifications to trigger when the job fails
#   Pre-defined: EMAIL_ALERTS
# - scheduler: rules that define when to run the job
#   Pre-defined: NIGHTLY_TRIGGERS, CODECHANGE_TRIGGERS, WALLETCHANGE_TRIGGERS

################ 1: BUILDMASTER JOB ###################################


##
# This worker restarts the buildmaster itself on
# changes to this file.
# Location: /home/buildbot-master @ taler.net
WORKERS.append(Worker("buildmaster-worker", "buildmaster-pass"))

BUILDMASTER_FACTORY = create_factory_with_deployment()
BUILDMASTER_FACTORY.addStep(
    ShellCommand(
        name="restart buildmaster",
        description="trigger buildmaster restart with new configuration",
        descriptionDone="Buildmaster updated",
        command=["systemctl", "--user", "kill", "--signal", "SIGHUP", "buildbot-master"],
        workdir="../.."
    )
)

BUILDERS.append(util.BuilderConfig(
    name="buildmaster-builder",
    workernames=["buildmaster-worker"],
    factory=BUILDMASTER_FACTORY
))

EMAIL_ALERTS.append("buildmaster-builder")

# Buildmaster is notified whenever deployment.git changes
SCHEDULERS.append(schedulers.SingleBranchScheduler(
    name="buildmaster-scheduler",
    change_filter=util.ChangeFilter(
        branch="master",
        project_re="(deployment)"
    ),
    treeStableTimer=None,
    builderNames=["buildmaster-builder"]
))




################ 3: WEBSITE JOB ###################################

##
# This worker builds Websites: www and stage.
#
WORKERS.append(Worker("sites-worker", "sites-pass"))

SITES_FACTORY = create_factory_with_deployment()
SITES_FACTORY.addStep(
    ShellCommand(
        name="build Web sites",
        description="Building all the Taler homepages",
        descriptionDone="Sites built.",
        command=["./build-sites.sh"],
        workdir="../../deployment/buildbot",
        haltOnFailure=True
    )
)

BUILDERS.append(util.BuilderConfig(
    name="sites-builder", workernames=["sites-worker"], factory=SITES_FACTORY
))

#EMAIL_ALERTS.append("sites-builder")


# The web page changed if 'www' changed OR if 'web' in the 'twister' repo changed:
def twister_web_page(change):
    _change = change.asDict()
    repo = _change.get("project")
    if repo in ["www", "buywith", "deployment"]:
        return True

    files = _change.get("files")
    for file in files:
        if re.search(r"web", file.get("name", "")) \
                and "twister" == repo:
            return True
    return False


# Sites are re-build whenever deployment, www buywith, or twister changes.
SCHEDULERS.append(schedulers.SingleBranchScheduler(
    name="sites-scheduler",
    builderNames=["sites-builder"],
    change_filter=util.ChangeFilter(
        branch_re="(master|stable)",
        filter_fn=twister_web_page
    ),
    treeStableTimer=None
))


################ 9: 'check links' JOB ###################################

##
# linkchecker worker checks for dead links in the Website
# Location: /home/linkchecker @ taler.net
WORKERS.append(Worker("linkchecker-worker", "linkchecker-pass"))

# linkchecker FACTORY
LINKCHECKER_FACTORY = create_factory_with_deployment()
LINKCHECKER_FACTORY.addStep(
    ShellCommand(
        name="linkchecker",
        description="Check taler.net website for broken links && Notify",
        descriptionDone="Results of wget in buildbot logs.",
        command=["/home/linkchecker/deployment/buildbot/linkchecker.sh"],
        workdir="/home/linkchecker",
        haltOnFailure=True,
        timeout=7200 # 2 hours
    )
)

# linkchecker BUILDER
# worker at linkchecker@taler.net
BUILDERS.append(util.BuilderConfig(
    name="linkchecker-builder",
    workernames="linkchecker-worker",
    factory=LINKCHECKER_FACTORY
))

docs_generator = BuildStatusGenerator(
    mode=('change', 'problem', 'failing', 'exception',),
    builders=[
       'linkchecker-builder',
    ],
    message_formatter=reporters.MessageFormatter(
       template_type='plain',
       wantSteps=True,
       wantLogs=True
     ),
    add_logs=True
    )


SERVICES.append(reporters.MailNotifier(
    fromaddr="bb@taler.net",
    generators=[docs_generator],
    sendToInterestedUsers=False,
    useTls=False,
    relayhost="localhost",
    smtpPort=25,
    dumpMailsToLog=True,
    extraRecipients=['linkcheck@taler.net']
))

# SERVICES.append(tipReserveEmails) 

NIGHTLY_TRIGGERS.append("linkchecker-builder")


#############################################
# 19: CONTAINER FACTORY #####################
#############################################
##
# These factories uses the standard container worker.
WORKERS.append(Worker("container-worker", "container-pass"))


# Container Job Generator Functions
# Parse config file and save values in a dict
def ingest_job_config(configPath, jobName):
    configDict = {jobName: {}}
    print(configDict)
    ini.read_string(configPath)
    for key in ini["build"]:
        value = ini['build'][key]
        configDict[jobName][key] = value
    print(configDict)
    configDict.update(configDict)
    print(configDict)
    return configDict


# Search for configs, and ingest
def handle_job_config(jobDirPath, jobName, repoName, configPath, configExist):
    print(configPath)
    if configExist == 0:
        print(f"Ingesting Job Config: {configPath}")
        configDict = ingest_job_config(configPath, jobName)
        print(configDict)
        return configDict
    else:
        print("No job config; Using default params")
        # Set default job config parameters
        configDict = {jobName: {"HALT_ON_FAILURE": True,
                                "WARN_ON_FAILURE": False,
                                "CONTAINER_BUILD": True,
                                "CONTAINER_NAME": repoName,
                                "CONTAINER_ARCH": "amd64"}}
        return configDict


class GenerateStagesCommand(buildstep.ShellMixin, steps.BuildStep):

    def __init__(self, REPO_NAME, **kwargs):
        self.REPO_NAME = REPO_NAME
        kwargs = self.setupShellMixin(kwargs)
        super().__init__(**kwargs)
        self.observer = logobserver.BufferLogObserver()
        self.addLogObserver('stdio', self.observer)

    def extract_stages(self, stdout):
        stages = []
        for line in stdout.split('\n'):
            stage = str(line.strip())
            if stage:
                stages.append(stage)
        return stages

    @defer.inlineCallbacks
    def run(self):
        CONTAINER_WORKDIR = f"/home/container-worker/workspace/{self.REPO_NAME}"
        CI_JOBS_PATH = f"{CONTAINER_WORKDIR}/contrib/ci/jobs"
        # run 'ls <project_root>/contrib/ci/jobs/' to get the list of stages
        cmd = yield self.makeRemoteShellCommand()
        yield self.runCommand(cmd)
        jobDirs = []

        # if the command passes extract the list of stages
        result = cmd.results()
        if result == util.SUCCESS:
            jobDirs = self.extract_stages(self.observer.getStdout())
            print(f"this is jobDirs list: {jobDirs}")
            self.configDict = {}
            print(f"Remote cmd stdout: {self.observer.getStdout()}")
            print(f"cmd.results: {cmd.results()}")
            for stage in jobDirs:
                jobDirPath = f"{CI_JOBS_PATH}/{stage}"
                observer = logobserver.BufferLogObserver()
                self.addLogObserver('stdio', observer)
                cmd1 = yield self.makeRemoteShellCommand(
                        command=["cat", f"{jobDirPath}/config.ini"])
                yield self.runCommand(cmd1)
                print(f"cmd1.results: {cmd1.results()}")
                print(f"Second command stdout: {observer.getStdout()}")
                print(f"Current stage: {stage}")
                print(jobDirPath)
                self.configDict.update(
                        handle_job_config(
                            jobDirPath, stage, self.REPO_NAME,
                            observer.getStdout(), cmd1.results()))
                print(self.configDict)
            # create a container step for each stage and
            # add them to the build
            convstr2bool = ast.literal_eval
            self.build.addStepsAfterCurrentStep([
                container_add_step(
                    convstr2bool(
                        str(self.configDict[stage]["HALT_ON_FAILURE"])),
                    convstr2bool(
                        str(self.configDict[stage]["WARN_ON_FAILURE"])),
                    convstr2bool(
                        str(self.configDict[stage]["CONTAINER_BUILD"])),
                    self.configDict[stage]["CONTAINER_NAME"],
                    container_factory,
                    CONTAINER_WORKDIR,
                    stage,
                    self.configDict[stage]["CONTAINER_ARCH"],
                    f"contrib/ci/jobs/{stage}/job.sh")
                for stage in jobDirs
            ])

        return result


# List of repos to add to container factory.
container_repos = ["git.taler.net/wallet-core",
                   "git.taler.net/libeufin",
                   "git.taler.net/merchant",
                   "git.taler.net/exchange",
                   "git.taler.net/docs",
                   "git.taler.net/taler-ops-www",
                   "git.taler.net/taler-systems-www",
                   "git.taler.net/anastasis-www",
                   "git.taler.net/tutorials",
                   "git.taler.net/sync",
                   "git.taler.net/challenger",
                   "git.taler.net/sandcastle-ng",
                   "git.gnunet.org/gnunet"]

for repo in container_repos:

    # Prepare to read job configs
    ini = configparser.ConfigParser()
    ini.optionxform = str

    # Factory-wide variables
    REPO_NAME = repo.rsplit('/', 1)[1]
    REPO_URL = "https://" + repo + ".git"
    CONTAINER_WORKDIR = f"/home/container-worker/workspace/{REPO_NAME}"
    CI_JOBS_PATH = f"{CONTAINER_WORKDIR}/contrib/ci/jobs"

    # Create a factory
    container_factory = util.BuildFactory()
    container_factory.workdir = CONTAINER_WORKDIR

    # Setup workspace
    container_factory.addStep(ShellCommand(
        name="workspace",
        descriptionDone="Workspace directory check",
        command=f"test -d {CONTAINER_WORKDIR} && podman run --rm --volume {CONTAINER_WORKDIR}:/workdir docker.io/library/debian:bookworm-slim chmod -R 777 /workdir || mkdir -p {CONTAINER_WORKDIR}",
        haltOnFailure=True,
    ))

    # Ensure repo is cloned or clean.
    # Git() will clone repo if it doesn't exist.
    # Method clobber removes directory and makes a fresh clone.
    # Shallow set to "True" defaults to a depth of 1.
    # Will checkout value of "branch" property from job properties.
    # https://docs.buildbot.net/latest/manual/configuration/steps/source_git.html
    container_factory.addStep(Git(
        name="git",
        repourl=REPO_URL,
        branch=util.Interpolate('%(src::branch)s'),
        mode='full',
        method='clobber',
        shallow=True,
        submodules=True,
        haltOnFailure=True,
    ))

    container_factory.addStep(GenerateStagesCommand(
        REPO_NAME,
        name="Generate build stages",
        command=["ls", CI_JOBS_PATH],
        haltOnFailure=True))

    BUILDERS.append(util.BuilderConfig(
        name=f"{REPO_NAME}-builder",
        workernames=["container-worker"],
        factory=container_factory
    ))

    # Only enable this scheduler for debugging!
    # Will run builders with 1 minute of waiting inbetween builds
    # SCHEDULERS.append(schedulers.Periodic(
    #     name=f"{REPO_NAME}-minutely",
    #     builderNames=[f"{REPO_NAME}-builder"],
    #     periodicBuildTimer=60
    #     ))

    SCHEDULERS.append(schedulers.SingleBranchScheduler(
        name=f"{REPO_NAME}-container-scheduler",
        change_filter=util.ChangeFilter(
            branch="master",
            project_re=f"({REPO_NAME})"
        ),
        treeStableTimer=30,
        builderNames=[f"{REPO_NAME}-builder"]
    ))

    SERVICES.append(reporters.MailNotifier(
        fromaddr="buildbot@taler.net",
        # notify from pass to fail, and viceversa.
        generators=[BuildStatusGenerator(
            mode=('change','problem','failing','exception',),
            builders=[f"{REPO_NAME}-builder",],
            message_formatter=reporters.MessageFormatter(
                template_type='plain',
                wantSteps=True,
                wantLogs=True
            ),
            add_logs=True,
        )],
        sendToInterestedUsers=False,
        useTls=False,
        relayhost="localhost",
        smtpPort=25,
        dumpMailsToLog=True,
        extraRecipients=[f"ci-{REPO_NAME}@taler.net"]
    ))


############## sandcastle-ng Scheduler #################################


# Periodic scheduler for sandcastle-ng.
# Runs every 2 hours (60 seconds * 60 * 2)
SCHEDULERS.append(schedulers.Periodic(
    name="sandcastle-ng-periodic-scheduler",
    builderNames=["sandcastle-ng-builder"],
    change_filter=util.ChangeFilter(branch="master"),
    periodicBuildTimer=60*60*2
))


################ 99: debug stuff JOB ###################################

# This does nothing, just a starting point for a factory.
DEBUG_FACTORY = util.BuildFactory()
DEBUG_FACTORY.addStep(
    ShellCommand(
        name="echo debug",
        description="just echoing a word",
        descriptionDone="builder responded",
        command=["echo", "I'm here!"]
    )
)


##################################################################
#################### General purpose #############################
##################################################################

# Compute array of the names of all of our builders
BUILDER_LIST = map(lambda builder: builder.name, BUILDERS)

####### GENERAL PURPOSE BUILDBOT SERVICES #######################

SERVICES.append(reporters.MailNotifier(
    fromaddr="testbuild@taler.net",
    # notify from pass to fail, and viceversa.
    generators=[BuildStatusGenerator(
        mode=('change','problem','failing','exception',),
        builders=EMAIL_ALERTS,
        message_formatter=reporters.MessageFormatter(
            template_type='plain',
            wantSteps=True,
            wantLogs=True
        ),
        add_logs=True,
    )],
    sendToInterestedUsers=False,
    useTls=False,
    relayhost="localhost",
    smtpPort=25,
    dumpMailsToLog=True,
    extraRecipients=BUILDER_EMAIL_ADDRESSES
))


############# GENERAL PURPOSE SCHEDULERS ##########################

# Workers that are done on wallet or deployment changes to master
SCHEDULERS.append(schedulers.SingleBranchScheduler(
    name="taler-healthcheck-scheduler",
    change_filter=util.ChangeFilter(
        branch="master",
        project_re="(wallet|deployment)"
    ),
    treeStableTimer=None,
    builderNames=WALLETCHANGE_TRIGGERS
))

SCHEDULERS.append(schedulers.SingleBranchScheduler(
    name="all-scheduler",
    change_filter=util.ChangeFilter(
        branch_re="(master|stable)",
        project_re="(backoffice|wallet-core|bank|exchange|"
        "merchant|deployment|twister|sync|"
        "help|taler-merchant-demos)"
    ),
    treeStableTimer=None,
    builderNames=CODECHANGE_TRIGGERS
))

# Scheduler for all nightly builds.
SCHEDULERS.append(schedulers.Nightly(
    name="nightly-scheduler",
    builderNames=list(NIGHTLY_TRIGGERS),
    branch="master",
    hour=6,
    minute=0
))

# Provide "force" button in the web UI.
SCHEDULERS.append(schedulers.ForceScheduler(
    name="force-scheduler",
    builderNames=list(BUILDER_LIST)
))


#########################################################
####### Actual configuation initialization ##############
#########################################################

# This is the dictionary that the buildmaster pays attention to.  We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}
c["workers"] = WORKERS
c["builders"] = BUILDERS
c["schedulers"] = SCHEDULERS
c["services"] = SERVICES

# Silence warning and allow very basic phoning home.
c["buildbotNetUsageData"] = "basic"

c["title"] = "GNU Taler"
c["titleURL"] = "https://taler.net"

# This specifies what database buildbot uses to store its
# state.  You can leave  this at its default for all but the
# largest installations.
c["db"] = {
    "db_url": "sqlite:///state.sqlite",
}

# the 'change_source' setting tells the buildmaster how it should
# find out about source code changes.
pbSource = PBChangeSource(user="allcs", passwd="allcs")


pollGnunetSource = changes.GitPoller(repourl='https://git.gnunet.org/gnunet.git',
                                       branches=True,
				       pollInterval=300,
				       pollAtLaunch=True,
				       project="gnunet")

c["change_source"] = [pollGnunetSource, pbSource]

# 'protocols' contains information about protocols which master
# will use for communicating with workers. You must define at
# least 'port' option that workers could connect to your master
# with this protocol. 'port' must match the value configured into
# the workers (with their --master option)
c["protocols"] = {"pb": {"port": "tcp:9989:interface=127.0.0.1"}}

# We use nginx to expose the BB under this URL.
c["buildbotURL"] = "https://buildbot.taler.net/"


# minimalistic config to activate new web UI
# -- formerly commented out as not packaged properly in Debian and others, see
# https://bugzilla.redhat.com/show_bug.cgi?id=1557687
c["www"] = {
    "port": 8010,
    "default_page": 'waterfall',
    "plugins": {
        "waterfall_view": True,
        "console_view": True,
        "grid_view": True,
    },
    "allowed_origins": ["https://*.taler.net"],
    "avatar_methods": [],
}