from buildbot.plugins import * from buildbot_common.build_helpers import * import os from buildbot.util import bytes2unicode import json __all__ = [ "configure", "E" ] class E(): PROJECT = "denise" BUILDBOT_URL = "https://git.immae.eu/buildbot/{}/".format(PROJECT) SOCKET = "unix:/run/buildbot/{}.sock".format(PROJECT) PB_SOCKET = "unix:address=/run/buildbot/{}_pb.sock".format(PROJECT) SSH_KEY_PATH = "/var/lib/buildbot/buildbot_key" SSH_HOST_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIFbhFTl2A2RJn5L51yxJM4XfCS2ZaiSX/jo9jFSdghF" BINGO_RELEASE_PATH = "/var/lib/buildbot/outputs/denise/bingo" BINGO_BETA_PATH = "/var/lib/buildbot/outputs/denise/bingo_beta" BINGO_GIT_URL = "gitolite@git.immae.eu:perso/Denise/bingo" OMS_RELEASE_PATH = "/var/lib/buildbot/outputs/denise/oms" OMS_BETA_PATH = "/var/lib/buildbot/outputs/denise/oms_beta" OMS_GIT_URL = "gitolite@git.immae.eu:perso/Denise/oms" AVENTURIERS_RELEASE_PATH = "/var/lib/buildbot/outputs/denise/aventuriers" AVENTURIERS_GIT_URL = "https://git.immae.eu/perso/Denise/aventuriers.git" # master.cfg SECRETS_FILE = os.getcwd() + "/secrets" LDAP_URL = "ldaps://ldap.immae.eu:636" LDAP_ADMIN_USER = "cn=buildbot,ou=services,dc=immae,dc=eu" LDAP_BASE = "dc=immae,dc=eu" LDAP_PATTERN = "(uid=%(username)s)" LDAP_GROUP_PATTERN = "(&(memberOf=cn=groups,ou=denise,cn=buildbot,ou=services,dc=immae,dc=eu)(member=%(dn)s))" TITLE_URL = "https://oms.syanni.eu" TITLE = "Syanni website" def configure(c): c["buildbotURL"] = E.BUILDBOT_URL c["www"]["port"] = E.SOCKET worker_name = "generic-worker-denise" c['workers'].append(worker.LocalWorker(worker_name)) configure_bingo(c, worker_name) configure_oms(c, worker_name) configure_aventuriers(c, worker_name) c['schedulers'].append(force_scheduler("force_denise", all_builder_names(c))) def configure_bingo(c, worker_name): builder_name = "DeniseBingo_build" c['schedulers'].append(git_hook_scheduler("DeniseBingo", [builder_name])) c['builders'].append(util.BuilderConfig(name=builder_name, workernames=[worker_name], factory=bingo_build_factory())) def configure_oms(c, worker_name): builder_name = "DeniseOMS_build" c['schedulers'].append(git_hook_scheduler("DeniseOMS", [builder_name])) c['builders'].append(util.BuilderConfig(name=builder_name, workernames=[worker_name], factory=oms_build_factory())) def configure_aventuriers(c, worker_name): builder_name = "DeniseAventuriers_build" c['schedulers'].append(git_hook_scheduler("DeniseAventuriers", [builder_name])) c['builders'].append(util.BuilderConfig(name=builder_name, workernames=[worker_name], factory=aventuriers_build_factory())) def bingo_build_factory(): @util.renderer def bingo_run_path(props): if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master": return "/run/denise_bingo/gunicorn.pid" else: return "/run/denise_bingo_beta/gunicorn.pid" @util.renderer def bingo_systemd_service(props): if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master": return "denise-bingo" else: return "denise-bingo-beta" @util.renderer def bingo_url(props): if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master": return "https://bingo.syanni.eu" else: return "https://beta.bingo.syanni.eu" @util.renderer def bingo_path(props): if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master": return E.BINGO_RELEASE_PATH else: return E.BINGO_BETA_PATH factory = util.BuildFactory() factory.addStep(steps.Git(logEnviron=False, repourl=E.BINGO_GIT_URL, submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), sshHostKey=E.SSH_HOST_KEY, mode="full", method="fresh")) factory.addStep(steps.MasterShellCommand(command=util.Interpolate("rm -rf %(kw:bingo_path)s", bingo_path=bingo_path))) factory.addStep(steps.DirectoryUpload(workersrc=".", masterdest=bingo_path, url=bingo_url)) factory.addStep(steps.MasterShellCommand(command=util.Interpolate("chmod -R a+rX %(kw:bingo_path)s", bingo_path=bingo_path))) factory.addStep(steps.MasterShellCommand(command=util.Interpolate("/run/wrappers/bin/sudo systemctl restart %(kw:bingo_service)s.service", bingo_service=bingo_systemd_service))) return factory def oms_build_factory(): @util.renderer def oms_run_path(props): if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master": return "/run/denise_oms/gunicorn.pid" else: return "/run/denise_oms_beta/gunicorn.pid" @util.renderer def oms_systemd_service(props): if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master": return "denise-oms" else: return "denise-oms-beta" @util.renderer def oms_url(props): if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master": return "https://oms.syanni.eu" else: return "https://beta.oms.syanni.eu" @util.renderer def oms_path(props): if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master": return E.OMS_RELEASE_PATH else: return E.OMS_BETA_PATH factory = util.BuildFactory() factory.addStep(steps.Git(logEnviron=False, repourl=E.OMS_GIT_URL, submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), sshHostKey=E.SSH_HOST_KEY, mode="full", method="fresh")) factory.addStep(steps.MasterShellCommand(command=util.Interpolate("rm -rf %(kw:oms_path)s", oms_path=oms_path))) factory.addStep(steps.DirectoryUpload(workersrc=".", masterdest=oms_path, url=oms_url)) factory.addStep(steps.MasterShellCommand(command=util.Interpolate("chmod -R a+rX %(kw:oms_path)s", oms_path=oms_path))) factory.addStep(steps.MasterShellCommand(command=util.Interpolate("/run/wrappers/bin/sudo systemctl restart %(kw:oms_service)s.service", oms_service=oms_systemd_service))) return factory def aventuriers_build_factory(): path_env = { "PATH": "/run/current-system/sw/bin", "TZ": "Europe/Paris", } factory = util.BuildFactory() factory.addStep(steps.Git(logEnviron=False, repourl=E.AVENTURIERS_GIT_URL, submodules=True, mode="full", method="fresh")) factory.addStep(NixShellCommand(name="build files", logEnviron=False, haltOnFailure=True, env=path_env, command=["make tout encyclo"])) factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.AVENTURIERS_RELEASE_PATH))) factory.addStep(steps.DirectoryUpload(workersrc="html", masterdest=E.AVENTURIERS_RELEASE_PATH, url="https://aventuriers.syanni.eu")) factory.addStep(steps.FileUpload(name="upload epub file", workersrc="aventuriers.epub", masterdest=E.AVENTURIERS_RELEASE_PATH + "/aventuriers.epub", url="https://aventuriers.syanni.eu/aventuriers.epub", mode=0o644)) factory.addStep(steps.FileUpload(name="upload mobi file", workersrc="aventuriers.mobi", masterdest=E.AVENTURIERS_RELEASE_PATH + "/aventuriers.mobi", url="https://aventuriers.syanni.eu/aventuriers.mobi", mode=0o644)) factory.addStep(steps.FileUpload(name="upload pdf file", workersrc="aventuriers.pdf", masterdest=E.AVENTURIERS_RELEASE_PATH + "/aventuriers.pdf", url="https://aventuriers.syanni.eu/aventuriers.pdf", mode=0o644)) factory.addStep(steps.FileUpload(name="upload encyclo pdf file", workersrc="encyclo.pdf", masterdest=E.AVENTURIERS_RELEASE_PATH + "/encyclo.pdf", url="https://aventuriers.syanni.eu/encyclo.pdf", mode=0o644)) factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.AVENTURIERS_RELEASE_PATH))) return factory