blob: 2e9cbbf399437c312f60b553fac75a57b5f6829a [file] [log] [blame]
import json
import os
import socket
import sys
from buildbot.plugins import reporters, util
from datetime import timedelta
import loadConfig
from events import Events, GitHubEventHandlerNoEdits
def load_password(name, default=None):
if os.getenv(name):
return os.getenv(name)
try:
passwords = json.load(open('passwords.json'))
return passwords.get(name, default)
except Exception as e:
print('Error in finding {} in passwords.json'.format(name))
return default
# This is work-around for Twisted having a small size limit for patches. See https://bugs.webkit.org/show_bug.cgi?id=198851#c5
from twisted.spread import banana
banana.SIZE_LIMIT = 100 * 1024 * 1024
# This is work-around for https://bugs.webkit.org/show_bug.cgi?id=222361
from buildbot.process.buildstep import BuildStep
BuildStep.warn_deprecated_if_oldstyle_subclass = lambda self, name: None
is_test_mode_enabled = load_password('BUILDBOT_PRODUCTION') is None
custom_suffix = '-uat' if load_password('BUILDBOT_UAT') else ''
c = BuildmasterConfig = {}
c['www'] = dict(port='tcp:8010:interface=127.0.0.1', allowed_origins=["*"])
c['www']['custom_templates_dir'] = 'templates'
c['www']['ui_default_config'] = {
'Builders.show_workers_name': True,
'Builders.buildFetchLimit': 1000,
'Workers.showWorkerBuilders': True,
}
if not is_test_mode_enabled:
c['www']['change_hook_dialects'] = dict(
github={
'class': GitHubEventHandlerNoEdits,
'secret': load_password('GITHUB_HOOK_SECRET'),
'github_property_whitelist': [
'github.number',
'github.title',
'github.head.ref',
'github.head.sha',
'github.base.ref',
'github.base.sha',
'github.head.repo.full_name',
'github.head.user.login',
], 'token': load_password('GITHUB_COM_ACCESS_TOKEN'),
},
)
credentials = load_password('EWS_CREDENTIALS')
if not credentials:
print('EWS credentials not found. Please ensure EWS_CREDENTIALS is configured either in env variables or in passwords.json')
sys.exit(1)
# See https://docs.buildbot.net/current/manual/configuration/www.html#example-configs
authz = util.Authz(
allowRules=[util.AnyControlEndpointMatcher(role="admin")],
roleMatchers=[util.RolesFromEmails(admin=list(credentials.keys()))]
)
auth = util.UserPasswordAuth(credentials)
c['www']['auth'] = auth
c['www']['authz'] = authz
c['protocols'] = {'pb': {'port': 17000}}
c['projectName'] = 'WebKit EWS{}'.format(custom_suffix.upper())
c['projectURL'] = 'https://ews-build.webkit{}.org/'.format(custom_suffix)
if is_test_mode_enabled:
c['buildbotURL'] = 'http://localhost:8010/'
c['db_url'] = 'sqlite:///state.sqlite?serialize_access=1'
else:
c['buildbotURL'] = 'https://ews-build.webkit{}.org/'.format(custom_suffix)
db_url = load_password('DB_URL', None)
db_name = load_password('DB_NAME', None)
db_username = load_password('DB_USERNAME', None)
db_password = load_password('DB_PASSWORD', None)
if None in [db_url, db_name, db_username, db_password]:
print('Environment variables for DB not found. Please ensure these variables are set.')
sys.exit(1)
# See https://docs.buildbot.net/1.7.0/manual/configuration/global.html#database-specification
c['db_url'] = 'postgresql://{}:{}@{}/{}'.format(db_username, db_password, db_url, db_name)
# configure a janitor to delete old logs
c['configurators'] = [util.JanitorConfigurator(logHorizon=timedelta(weeks=52), hour='1', dayOfWeek='*')]
c['logCompressionMethod'] = 'lz4'
c['buildbotNetUsageData'] = None
loadConfig.loadBuilderConfig(c, is_test_mode_enabled=is_test_mode_enabled)
mail_notifier = reporters.MailNotifier(
fromaddr='ews-build@webkit.org',
sendToInterestedUsers=False,
extraRecipients=['webkit-ews-bot-watchers@group.apple.com'],
mode=('exception'),
addPatch=False)
if not is_test_mode_enabled:
hostname = socket.gethostname().strip()
event_reporter = Events(master_hostname=hostname, type_prefix='ews')
c['services'] = [event_reporter, mail_notifier]