]>
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" | |
8fa7ff2c IB |
15 | SSH_KEY_PATH = "/var/lib/buildbot/buildbot_key" |
16 | SSH_HOST_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIFbhFTl2A2RJn5L51yxJM4XfCS2ZaiSX/jo9jFSdghF" | |
17 | XMPP_RECIPIENTS = os.environ["BUILDBOT_XMPP_RECIPIENTS"].split(" ") | |
18 | ||
573e1710 IB |
19 | IMMAE_EU_GIT_URL = "gitolite@git.immae.eu:perso/Immae/Sites/Blog" |
20 | NORMALESUP_GIT_URL = "gitolite@git.immae.eu:perso/Immae/Projets/Sites/Normalesup" | |
21 | ||
8fa7ff2c IB |
22 | # master.cfg |
23 | SECRETS_FILE = os.getcwd() + "/secrets" | |
24 | LDAP_URL = "ldaps://ldap.immae.eu:636" | |
25 | LDAP_ADMIN_USER = "cn=buildbot,ou=services,dc=immae,dc=eu" | |
26 | LDAP_BASE = "dc=immae,dc=eu" | |
27 | LDAP_PATTERN = "(uid=%(username)s)" | |
28 | LDAP_GROUP_PATTERN = "(&(memberOf=cn=groups,ou=immaeEu,cn=buildbot,ou=services,dc=immae,dc=eu)(member=%(dn)s))" | |
29 | TITLE_URL = "https://www.immae.eu" | |
30 | TITLE = "Immae website" | |
31 | ||
32 | class CustomBase(webhooks.base): | |
33 | def getChanges(self, request): | |
34 | try: | |
35 | content = request.content.read() | |
36 | args = json.loads(bytes2unicode(content)) | |
37 | except Exception as e: | |
38 | raise ValueError("Error loading JSON: " + str(e)) | |
39 | ||
40 | args.setdefault("comments", "") | |
41 | args.setdefault("repository", "") | |
42 | args.setdefault("author", args.get("who", "unknown")) | |
43 | ||
44 | return ([args], None) | |
45 | ||
46 | def configure(c): | |
47 | c["buildbotURL"] = E.BUILDBOT_URL | |
48 | c["www"]["port"] = E.SOCKET | |
49 | ||
50 | c["www"]["change_hook_dialects"]["base"] = { | |
51 | "custom_class": CustomBase | |
52 | } | |
53 | c['workers'].append(worker.LocalWorker("generic-worker-immae-eu")) | |
54 | ||
55 | c['schedulers'].append(hook_scheduler("ImmaeEu", timer=1)) | |
573e1710 IB |
56 | c['schedulers'].append(hook_scheduler("Normalesup", timer=1)) |
57 | c['schedulers'].append(force_scheduler("force_immae_eu", ["ImmaeEu_build", "Normalesup_build"])) | |
8fa7ff2c | 58 | |
573e1710 IB |
59 | c['builders'].append(immae_eu_factory()) |
60 | c['builders'].append(normalesup_factory()) | |
8fa7ff2c IB |
61 | |
62 | c['services'].append(SlackStatusPush( | |
63 | name="slack_status_immae_eu_project", | |
573e1710 | 64 | builders=["ImmaeEu_build", "Normalesup_build"], |
8fa7ff2c IB |
65 | serverUrl=open(E.SECRETS_FILE + "/slack_webhook", "r").read().rstrip())) |
66 | c['services'].append(XMPPStatusPush( | |
67 | name="xmpp_status_immae_eu_project", | |
573e1710 | 68 | builders=["ImmaeEu_build", "Normalesup_build"], |
8fa7ff2c IB |
69 | recipients=E.XMPP_RECIPIENTS, |
70 | password=open(E.SECRETS_FILE + "/notify_xmpp_password", "r").read().rstrip())) | |
71 | ||
573e1710 | 72 | def immae_eu_factory(): |
8fa7ff2c | 73 | factory = util.BuildFactory() |
573e1710 | 74 | factory.addStep(steps.Git(logEnviron=False, repourl=E.IMMAE_EU_GIT_URL, |
f78fbfbf | 75 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), |
8fa7ff2c IB |
76 | sshHostKey=E.SSH_HOST_KEY, mode="full", method="copy")) |
77 | factory.addStep(steps.ShellCommand(name="build website", | |
78 | logEnviron=False, haltOnFailure=True, workdir="source", | |
79 | command=["make", "html"])) | |
80 | factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.RELEASE_PATH))) | |
81 | factory.addStep(steps.DirectoryUpload(workersrc="../source/output", | |
82 | masterdest=E.RELEASE_PATH, | |
83 | url="https://www.immae.eu")) | |
84 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.RELEASE_PATH))) | |
85 | ||
86 | return util.BuilderConfig(name="ImmaeEu_build", workernames=["generic-worker-immae-eu"], factory=factory) | |
573e1710 IB |
87 | |
88 | def normalesup_factory(): | |
89 | factory = util.BuildFactory() | |
90 | factory.addStep(steps.Git(logEnviron=False, repourl=E.NORMALESUP_GIT_URL, | |
91 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), | |
92 | sshHostKey=E.SSH_HOST_KEY, mode="full", method="copy")) | |
93 | factory.addStep(steps.ShellCommand(name="build website", | |
94 | logEnviron=False, haltOnFailure=True, workdir="source", | |
95 | command=["make", "build"])) | |
96 | factory.addStep(steps.ShellCommand(name="give read access to all files", | |
97 | logEnviron=False, haltOnFailure=True, workdir="source", | |
98 | command="chmod -R a+rX build")) | |
99 | factory.addStep(steps.ShellCommand(name="synchronize with phare", | |
100 | logEnviron=False, haltOnFailure=True, workdir="source", | |
101 | command=[ | |
102 | "rsync", "-av", "--delete", | |
103 | "-e", "ssh -i {} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no".format(E.SSH_KEY_PATH), | |
104 | "build/", | |
105 | "bouya@phare.normalesup.org:" | |
106 | ])) | |
107 | ||
108 | return util.BuilderConfig(name="Normalesup_build", workernames=["generic-worker-immae-eu"], factory=factory) |