]>
Commit | Line | Data |
---|---|---|
8fa7ff2c IB |
1 | from buildbot.plugins import * |
2 | from buildbot_common.build_helpers import * | |
3 | import os | |
4 | from buildbot.util import bytes2unicode | |
5 | import json | |
6 | ||
7 | __all__ = [ "configure", "E" ] | |
8 | ||
9 | class E(): | |
10 | PROJECT = "immaeEu" | |
11 | BUILDBOT_URL = "https://git.immae.eu/buildbot/{}/".format(PROJECT) | |
12 | SOCKET = "unix:/run/buildbot/{}.sock".format(PROJECT) | |
13 | PB_SOCKET = "unix:address=/run/buildbot/{}_pb.sock".format(PROJECT) | |
14 | RELEASE_PATH = "/var/lib/buildbot/outputs/immaeEu" | |
15 | GIT_URL = "gitolite@git.immae.eu:perso/Immae/Sites/Blog" | |
16 | SSH_KEY_PATH = "/var/lib/buildbot/buildbot_key" | |
17 | SSH_HOST_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIFbhFTl2A2RJn5L51yxJM4XfCS2ZaiSX/jo9jFSdghF" | |
18 | XMPP_RECIPIENTS = os.environ["BUILDBOT_XMPP_RECIPIENTS"].split(" ") | |
19 | ||
20 | # master.cfg | |
21 | SECRETS_FILE = os.getcwd() + "/secrets" | |
22 | LDAP_URL = "ldaps://ldap.immae.eu:636" | |
23 | LDAP_ADMIN_USER = "cn=buildbot,ou=services,dc=immae,dc=eu" | |
24 | LDAP_BASE = "dc=immae,dc=eu" | |
25 | LDAP_PATTERN = "(uid=%(username)s)" | |
26 | LDAP_GROUP_PATTERN = "(&(memberOf=cn=groups,ou=immaeEu,cn=buildbot,ou=services,dc=immae,dc=eu)(member=%(dn)s))" | |
27 | TITLE_URL = "https://www.immae.eu" | |
28 | TITLE = "Immae website" | |
29 | ||
30 | class CustomBase(webhooks.base): | |
31 | def getChanges(self, request): | |
32 | try: | |
33 | content = request.content.read() | |
34 | args = json.loads(bytes2unicode(content)) | |
35 | except Exception as e: | |
36 | raise ValueError("Error loading JSON: " + str(e)) | |
37 | ||
38 | args.setdefault("comments", "") | |
39 | args.setdefault("repository", "") | |
40 | args.setdefault("author", args.get("who", "unknown")) | |
41 | ||
42 | return ([args], None) | |
43 | ||
44 | def configure(c): | |
45 | c["buildbotURL"] = E.BUILDBOT_URL | |
46 | c["www"]["port"] = E.SOCKET | |
47 | ||
48 | c["www"]["change_hook_dialects"]["base"] = { | |
49 | "custom_class": CustomBase | |
50 | } | |
51 | c['workers'].append(worker.LocalWorker("generic-worker-immae-eu")) | |
52 | ||
53 | c['schedulers'].append(hook_scheduler("ImmaeEu", timer=1)) | |
54 | c['schedulers'].append(force_scheduler("force_immae_eu", ["ImmaeEu_build"])) | |
55 | ||
56 | c['builders'].append(factory()) | |
57 | ||
58 | c['services'].append(SlackStatusPush( | |
59 | name="slack_status_immae_eu_project", | |
60 | builders=["ImmaeEu_build"], | |
61 | serverUrl=open(E.SECRETS_FILE + "/slack_webhook", "r").read().rstrip())) | |
62 | c['services'].append(XMPPStatusPush( | |
63 | name="xmpp_status_immae_eu_project", | |
64 | builders=["ImmaeEu_build"], | |
65 | recipients=E.XMPP_RECIPIENTS, | |
66 | password=open(E.SECRETS_FILE + "/notify_xmpp_password", "r").read().rstrip())) | |
67 | ||
68 | def factory(): | |
69 | factory = util.BuildFactory() | |
70 | factory.addStep(steps.Git(logEnviron=False, repourl=E.GIT_URL, | |
f78fbfbf | 71 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), |
8fa7ff2c IB |
72 | sshHostKey=E.SSH_HOST_KEY, mode="full", method="copy")) |
73 | factory.addStep(steps.ShellCommand(name="build website", | |
74 | logEnviron=False, haltOnFailure=True, workdir="source", | |
75 | command=["make", "html"])) | |
76 | factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.RELEASE_PATH))) | |
77 | factory.addStep(steps.DirectoryUpload(workersrc="../source/output", | |
78 | masterdest=E.RELEASE_PATH, | |
79 | url="https://www.immae.eu")) | |
80 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.RELEASE_PATH))) | |
81 | ||
82 | return util.BuilderConfig(name="ImmaeEu_build", workernames=["generic-worker-immae-eu"], factory=factory) |