diff --git a/buildbot.tac b/buildbot.tac index 98055695..4eacf779 100644 --- a/buildbot.tac +++ b/buildbot.tac @@ -1,30 +1,44 @@ +# -*- python -*- +# ex: set filetype=python: import os from twisted.application import service +from twisted.python.log import FileLogObserver, ILogObserver +from twisted.python.logfile import LogFile from buildbot.master import BuildMaster -basedir = "." -log_basedir = "/var/log/buildbot/" +# This buildbot.tac file is a basis for all "autogen" masters. +# The folder structure for autogen masters is: +# +# autogen +# └── aarch64-master-0 +#    ├── buildbot.tac +#     ├── master.cfg +#     ├── master-config.yaml +#     └── master-private.cfg +# +# Thus basedir is two levels below this file"s position. +buildbot_tac_dir = os.path.abspath(os.path.dirname(__file__)) +basedir = os.path.abspath(f"{buildbot_tac_dir}/../../") + +# Hard coded as it runs in containers. +# TODO(cvicentiu) this should come as an environment variable. +log_basedir = "/var/log/buildbot" rotateLength = 20000000 maxRotatedFiles = 30 -configfile = "master.cfg" +# Last two directories. autogen and +cfg_from_basedir = os.path.normpath( + buildbot_tac_dir).split(os.sep)[-2:] + ["master.cfg"] +configfile = os.path.join(*cfg_from_basedir) # Default umask for server umask = None -# if this is a relocatable tac file, get the directory containing the TAC -if basedir == ".": - import os - - basedir = os.path.abspath(os.path.dirname(__file__)) - # note: this line is matched against to check that this is a buildmaster # directory; do not edit it. -application = service.Application('buildmaster') # fmt: skip -from twisted.python.log import FileLogObserver, ILogObserver -from twisted.python.logfile import LogFile +application = service.Application("buildmaster") # fmt: skip logfile = LogFile.fromFullPath( os.path.join(log_basedir, "%s"), diff --git a/master.cfg b/master.cfg index b322c7d2..4e581ff9 100644 --- a/master.cfg +++ b/master.cfg @@ -36,8 +36,11 @@ from utils import ( uploadDebArtifacts, ) -with open("master-config.yaml", "r") as f: - master_config = yaml.safe_load(f) +cfg_dir = os.path.abspath(os.path.dirname(__file__)) +# Autogen master, see buildbot.tac for why this is the case. +base_dir = os.path.abspath(f'{cfg_dir}/../../') +with open(os.path.join(cfg_dir, "master-config.yaml"), "r") as file: + master_config = yaml.safe_load(file) # This is the dictionary that the buildmaster pays attention to. We also use # a shorter alias to save typing. @@ -46,7 +49,8 @@ c = BuildmasterConfig = {} # Load the slave, database passwords and 3rd-party tokens from an external # private file, so that the rest of the configuration can be public. config = {"private": {}} -exec(open("master-private.cfg").read(), config, {}) +with open(os.path.join(cfg_dir, "master-private.cfg"), "r") as file: + exec(file.read(), config, {}) ####### # BUILDBOT SERVICES diff --git a/validate_master_cfg.sh b/validate_master_cfg.sh index b3a8d540..5418b7d9 100755 --- a/validate_master_cfg.sh +++ b/validate_master_cfg.sh @@ -86,5 +86,5 @@ for dir in autogen/* \ -w "/srv/buildbot/master/" \ $IMAGE \ bash -c "buildbot checkconfig $dir/master.cfg" - echo -e "done\n" + echo "done" done