diff options
Diffstat (limited to 'flakes/private/buildbot/test_project/__init__.py')
-rw-r--r-- | flakes/private/buildbot/test_project/__init__.py | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/flakes/private/buildbot/test_project/__init__.py b/flakes/private/buildbot/test_project/__init__.py new file mode 100644 index 0000000..d5893fd --- /dev/null +++ b/flakes/private/buildbot/test_project/__init__.py | |||
@@ -0,0 +1,121 @@ | |||
1 | from buildbot.plugins import * | ||
2 | from buildbot_common.build_helpers import * | ||
3 | import buildbot_common.libvirt as ilibvirt | ||
4 | import os | ||
5 | from buildbot.util import bytes2unicode | ||
6 | import json | ||
7 | |||
8 | __all__ = [ "configure", "E" ] | ||
9 | |||
10 | class E(): | ||
11 | PROJECT = "test" | ||
12 | BUILDBOT_URL = "https://git.immae.eu/buildbot/{}/".format(PROJECT) | ||
13 | SOCKET = "unix:/run/buildbot/{}.sock".format(PROJECT) | ||
14 | PB_SOCKET = os.environ["BUILDBOT_WORKER_PORT"] | ||
15 | WORKER_HOST = "{}:{}".format(os.environ["BUILDBOT_HOST"], PB_SOCKET) | ||
16 | RELEASE_PATH = "/var/lib/ftp/release.immae.eu/{}".format(PROJECT) | ||
17 | RELEASE_URL = "https://release.immae.eu/{}".format(PROJECT) | ||
18 | GIT_URL = "https://git.immae.eu/perso/Immae/TestProject.git" | ||
19 | SSH_KEY_PATH = "/var/lib/buildbot/buildbot_key" | ||
20 | LIBVIRT_URL = os.environ["BUILDBOT_VIRT_URL"] + "?keyfile=" + SSH_KEY_PATH | ||
21 | XMPP_RECIPIENTS = os.environ["BUILDBOT_XMPP_RECIPIENTS"].split(" ") | ||
22 | |||
23 | # master.cfg | ||
24 | SECRETS_FILE = os.getcwd() + "/secrets" | ||
25 | LDAP_URL = "ldaps://ldap.immae.eu:636" | ||
26 | LDAP_ADMIN_USER = "cn=buildbot,ou=services,dc=immae,dc=eu" | ||
27 | LDAP_BASE = "dc=immae,dc=eu" | ||
28 | LDAP_PATTERN = "(uid=%(username)s)" | ||
29 | LDAP_GROUP_PATTERN = "(&(memberOf=cn=groups,ou=test,cn=buildbot,ou=services,dc=immae,dc=eu)(member=%(dn)s))" | ||
30 | TITLE_URL = "https://git.immae.eu/?p=perso/Immae/TestProject.git;a=summary" | ||
31 | TITLE = "Test project" | ||
32 | |||
33 | class CustomBase(webhooks.base): | ||
34 | def getChanges(self, request): | ||
35 | try: | ||
36 | content = request.content.read() | ||
37 | args = json.loads(bytes2unicode(content)) | ||
38 | except Exception as e: | ||
39 | raise ValueError("Error loading JSON: " + str(e)) | ||
40 | |||
41 | args.setdefault("comments", "") | ||
42 | args.setdefault("repository", "") | ||
43 | args.setdefault("author", args.get("who", "unknown")) | ||
44 | |||
45 | if args["category"] == "deploy_webhook": | ||
46 | args = { | ||
47 | "category": "deploy_webhook", | ||
48 | "comments": "", | ||
49 | "repository": "", | ||
50 | "author": "unknown", | ||
51 | "project": "TestProject", | ||
52 | "properties": { | ||
53 | "environment": args.get("environment", "integration"), | ||
54 | "build": "test_{}.tar.gz".format(args.get("branch", "master")) | ||
55 | } | ||
56 | } | ||
57 | |||
58 | return ([args], None) | ||
59 | |||
60 | def configure(c): | ||
61 | c["buildbotURL"] = E.BUILDBOT_URL | ||
62 | c["www"]["port"] = E.SOCKET | ||
63 | |||
64 | c["www"]["change_hook_dialects"]["base"] = { "custom_class": CustomBase } | ||
65 | |||
66 | configure_build(c) | ||
67 | configure_deploy(c) | ||
68 | |||
69 | configure_apprise_push(c, E.SECRETS_FILE, all_builder_names(c)) | ||
70 | configure_xmpp_push(c, E.SECRETS_FILE, all_builder_names(c), E.XMPP_RECIPIENTS) | ||
71 | |||
72 | def configure_build(c): | ||
73 | builder_name = "TestProject_build" | ||
74 | worker_name = "test-build" | ||
75 | c['schedulers'].append(force_scheduler("force_test", [builder_name])) | ||
76 | c['schedulers'].append(git_hook_scheduler("TestProject", [builder_name])) | ||
77 | c['workers'].append(libvirt_worker(worker_name)) | ||
78 | c['builders'].append(util.BuilderConfig(name=builder_name, workernames=[worker_name], factory=build_factory())) | ||
79 | |||
80 | def configure_deploy(c): | ||
81 | builder_name = "TestProject_deploy" | ||
82 | worker_name = "test-deploy" | ||
83 | c['workers'].append(libvirt_worker(worker_name)) | ||
84 | c['schedulers'].append(deploy_hook_scheduler("TestProject", [builder_name])) | ||
85 | c['schedulers'].append(deploy_scheduler("deploy_test", [builder_name])) | ||
86 | c['builders'].append(util.BuilderConfig(name=builder_name, workernames=[worker_name], factory=deploy_factory())) | ||
87 | |||
88 | def libvirt_worker(name): | ||
89 | return ilibvirt.LibVirtWorker(name, | ||
90 | open(E.SECRETS_FILE + "/worker_password", "r").read().rstrip(), | ||
91 | ilibvirt.Connection(E.LIBVIRT_URL), | ||
92 | E.WORKER_HOST) | ||
93 | |||
94 | def build_factory(): | ||
95 | package = util.Interpolate("test_%(kw:clean_branch)s.tar.gz", clean_branch=clean_branch) | ||
96 | package_dest = util.Interpolate("{}/test_%(kw:clean_branch)s.tar.gz".format(E.RELEASE_PATH), clean_branch=clean_branch) | ||
97 | package_url = util.Interpolate("{}/test_%(kw:clean_branch)s.tar.gz".format(E.RELEASE_URL), clean_branch=clean_branch) | ||
98 | |||
99 | factory = util.BuildFactory() | ||
100 | factory.addStep(steps.Git(logEnviron=False, | ||
101 | repourl=E.GIT_URL, mode="full", method="fresh")) | ||
102 | factory.addStep(steps.ShellCommand(name="env", | ||
103 | logEnviron=False, command=["env"])) | ||
104 | factory.addStep(steps.ShellCommand(name="pwd", | ||
105 | logEnviron=False, command=["pwd"])) | ||
106 | factory.addStep(steps.ShellCommand(name="true", | ||
107 | logEnviron=False, command=["true"])) | ||
108 | factory.addStep(steps.ShellCommand(name="echo", | ||
109 | logEnviron=False, command=["echo", package])) | ||
110 | factory.addSteps(package_and_upload(package, package_dest, package_url)) | ||
111 | |||
112 | return factory | ||
113 | |||
114 | def deploy_factory(): | ||
115 | package_dest = util.Interpolate("{}/%(prop:build)s".format(E.RELEASE_PATH)) | ||
116 | |||
117 | factory = util.BuildFactory() | ||
118 | factory.addStep(steps.MasterShellCommand(command=["test", "-f", package_dest])) | ||
119 | factory.addStep(steps.SetProperties(properties=compute_build_infos("test", E.RELEASE_PATH))) | ||
120 | factory.addStep(steps.MasterShellCommand(command=deploy_ssh_command(E.SSH_KEY_PATH, {}))) | ||
121 | return factory | ||