forked from buildbot/buildbot-docker-example-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaster.cfg
189 lines (146 loc) · 7.47 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
# -*- python -*-
# ex: set filetype=python:
import os
import json
import ntpath
from buildbot.util import bytes2unicode
from buildbot.plugins import *
# from .hooks import bitbuckethook
# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory.
# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}
####### SECRETS
c['secretsProviders'] = [secrets.SecretInAFile(dirname="/buildbot/secrets")]
####### WORKERS
# 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.
c['workers'] = [worker.Worker("worker-1", 'pass')]
c['workers'].append(worker.Worker("worker-2", 'pass'))
if 'BUILDBOT_MQ_URL' in os.environ:
c['mq'] = {
'type' : 'wamp',
'router_url': os.environ['BUILDBOT_MQ_URL'],
'realm': os.environ.get('BUILDBOT_MQ_REALM', 'buildbot').decode('utf-8'),
'debug' : 'BUILDBOT_MQ_DEBUG' in os.environ,
'debug_websockets' : 'BUILDBOT_MQ_DEBUG' in os.environ,
'debug_lowlevel' : 'BUILDBOT_MQ_DEBUG' in os.environ,
}
# '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': os.environ.get("BUILDBOT_WORKER_PORT", 9989)}}
####### CHANGESOURCES
# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes. Here we point to the buildbot clone of pyflakes.
c['change_source'] = []
# c['change_source'].append(changes.GitPoller(
# 'git://github.com/buildbot/pyflakes.git',
# workdir='gitpoller-workdir', branch='master',
# pollinterval=300))
####### SCHEDULERS
# Configure the Schedulers, which decide how to react to incoming changes. In this
# case, just kick off a 'package-donkey-train' build
c['schedulers'] = []
c['schedulers'].append(schedulers.SingleBranchScheduler(
name="all",
change_filter=util.ChangeFilter(branch='master', repository='swamp-train-donkey'),
treeStableTimer=None,
builderNames=["package-donkey-train"]))
c['schedulers'].append(schedulers.ForceScheduler(
name="force-package-donkey-train",
builderNames=["package-donkey-train"]))
c['schedulers'].append(schedulers.ForceScheduler(
name="force-build-model",
builderNames=["build-model"]))
####### BUILDERS
# 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.
c['builders'] = []
factory = util.BuildFactory()
# check out the source
factory.addStep(steps.Git(repourl='ssh://[email protected]/iot/swamp-train-donkey.git', mode='incremental', branch='master',
sshPrivateKey=util.Secret('id_rsa'), sshKnownHosts=util.Secret('known_hosts')))
#factory.addStep(steps.ShellCommand(command=[("ssh-agent", "bash", "-c", 'ssh-add '%(secret:id_rsa)s'; git clone ssh://[email protected]/iot/swamp-train-donkey.git'")]))
# run the tests (note that this will require that 'trial' is installed)
factory.addStep(steps.ShellCommand(command=["pip3", "install", "--user", "twine"]))
factory.addStep(steps.ShellCommand(command=["python3", "setup.py", "sdist"]))
factory.addStep(steps.ShellCommand(command=["/home/buildbot/.local/bin/twine", "upload", "--repository-url", "http://35.185.255.93/artifactory/api/pypi/swamp-python-local",
"-u", util.Secret('user'), "-p", util.Secret('password'), "--disable-progress-bar", "dist/*"]))
# factory.addStep(steps.ShellCommand(command=["cp", "./dist/swamp-train-donkey-0.6.tar.gz", "~/tmp"]))
c['builders'].append(
util.BuilderConfig(name="package-donkey-train",
workernames=["worker-1"],
factory=factory))
factory2 = util.BuildFactory()
factory2.addStep(steps.ShellCommand(command=["ls"]))
c['builders'].append(
util.BuilderConfig(name="build-model",
workernames=["worker-2"],
factory=factory2))
####### STATUS TARGETS
# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# like IRC bots.
c['status'] = []
####### PROJECT IDENTITY
# the 'title' string will appear at the top of this buildbot installation's
# home pages (linked to the 'titleURL').
c['title'] = "Pyflakes"
c['titleURL'] = "https://launchpad.net/pyflakes"
# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server is visible. This typically uses the port number set in
# the 'www' entry below, but with an externally-visible host name which the
# buildbot cannot figure out without some help.
c['buildbotURL'] = os.environ.get("BUILDBOT_WEB_URL", "http://localhost:8010/")
# minimalistic config to activate new web UI
c['www'] = dict(port=os.environ.get("BUILDBOT_WEB_PORT", 8010),
plugins=dict(waterfall_view={}, console_view={}))
####### CHANGE HOOKS
class BitBucketHook(webhooks.base):
def getChanges(self, request):
print(util.Secret("user"))
payload = self._get_payload(request)
revision=payload['refChanges'][0]['toHash']
for changeset in payload['changesets']['values']:
if changeset['toCommit']['id'] == revision:
revlink=changeset['links']['self'][0]['href'].rstrip('#README.md')
author=changeset['toCommit']['author']['name']
message=changeset['toCommit']['message']
break
chdict = dict(
revision=revision,
repository=payload['repository']['name'],
project=payload['repository']['project']['name'],
branch=ntpath.basename(payload['refChanges'][0]['refId']),
revlink=revlink,
author=author,
comments='Bitbucket Server Pull Request #{} . Commit comment: {}'.format(revision, message)
)
print('change payload data that was sent to db: {} '.format(chdict))
return ([chdict], None)
def _get_payload(self, request):
content = request.content.read()
content = bytes2unicode(content)
content_type = request.getHeader(b'Content-Type')
content_type = bytes2unicode(content_type)
if content_type.startswith('application/json'):
payload = json.loads(content)
else:
raise ValueError('Unknown content type: {}'
.format(content_type))
print("Payload: {}".format(payload))
return payload
# c['www']['change_hook_dialects'] = change_hook_dialects={'bitbucketserver': {}}
c['www']['change_hook_dialects'] = change_hook_dialects={ 'base' : { 'custom_class': BitBucketHook }}
####### DB URL
c['db'] = {
# This specifies what database buildbot uses to store its state. You can leave
# this at its default for all but the largest installations.
'db_url' : os.environ.get("BUILDBOT_DB_URL", "sqlite://").format(**os.environ),
}