aboutsummaryrefslogtreecommitdiff
path: root/nixops
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-03-26 01:31:24 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-03-26 10:45:04 +0100
commit85817848f29f1e2c3680da216a8dfc54a2ad3932 (patch)
tree21a57b50106701fa461a3767429b5a9f532138cb /nixops
parent587b9e340bb5cb14ca55e62a0498295e702b56c5 (diff)
downloadNix-85817848f29f1e2c3680da216a8dfc54a2ad3932.tar.gz
Nix-85817848f29f1e2c3680da216a8dfc54a2ad3932.tar.zst
Nix-85817848f29f1e2c3680da216a8dfc54a2ad3932.zip
Add deploy webhook
Diffstat (limited to 'nixops')
-rw-r--r--nixops/modules/buildbot/default.nix8
-rw-r--r--nixops/modules/buildbot/projects/caldance/__init__.py38
-rw-r--r--nixops/modules/buildbot/projects/test/__init__.py38
3 files changed, 83 insertions, 1 deletions
diff --git a/nixops/modules/buildbot/default.nix b/nixops/modules/buildbot/default.nix
index 3768bde..21b784b 100644
--- a/nixops/modules/buildbot/default.nix
+++ b/nixops/modules/buildbot/default.nix
@@ -83,7 +83,13 @@ in
83 ProxyPreserveHost On 83 ProxyPreserveHost On
84 </Location> 84 </Location>
85 <Location /buildbot/${project.name}/change_hook/base> 85 <Location /buildbot/${project.name}/change_hook/base>
86 Require local 86 <RequireAny>
87 Require local
88 Require ldap-group cn=users,ou=${project.name},cn=buildbot,ou=services,dc=immae,dc=eu
89 ${if lib.attrsets.hasAttr "webhookTokens" project then ''
90 Require expr "req('Access-Key') in { ${builtins.concatStringsSep ", " (map (x: "'${x}'") project.webhookTokens)} }"
91 '' else ""}
92 </RequireAny>
87 </Location> 93 </Location>
88 '') myconfig.env.buildbot.projects; 94 '') myconfig.env.buildbot.projects;
89 95
diff --git a/nixops/modules/buildbot/projects/caldance/__init__.py b/nixops/modules/buildbot/projects/caldance/__init__.py
index e28ef72..1069c35 100644
--- a/nixops/modules/buildbot/projects/caldance/__init__.py
+++ b/nixops/modules/buildbot/projects/caldance/__init__.py
@@ -1,6 +1,8 @@
1from buildbot.plugins import * 1from buildbot.plugins import *
2from buildbot_common.build_helpers import * 2from buildbot_common.build_helpers import *
3import os 3import os
4from buildbot.util import bytes2unicode
5import json
4 6
5__all__ = [ "configure", "E" ] 7__all__ = [ "configure", "E" ]
6 8
@@ -32,16 +34,52 @@ class E():
32 TITLE_URL = "https://caldance.immae.eu" 34 TITLE_URL = "https://caldance.immae.eu"
33 TITLE = "Caldance" 35 TITLE = "Caldance"
34 36
37class CustomBase(webhooks.base):
38 def getChanges(self, request):
39 try:
40 content = request.content.read()
41 args = json.loads(bytes2unicode(content))
42 except Exception as e:
43 raise ValueError("Error loading JSON: " + str(e))
44
45 args.setdefault("comments", "")
46 args.setdefault("repository", "")
47 args.setdefault("author", args.get("who", "unknown"))
48
49 if args["category"] == "deploy_webhook":
50 args = {
51 "category": "deploy_webhook",
52 "comments": "",
53 "repository": "",
54 "author": "webhook",
55 "project": "Caldance",
56 "properties": {
57 "environment": args.get("environment", "integration"),
58 "build": "caldance_{}.tar.gz".format(args.get("build", "master"))
59 }
60 }
61
62 return ([args], None)
63
64def deploy_hook_scheduler(project, timer=1):
65 return schedulers.AnyBranchScheduler(
66 change_filter=util.ChangeFilter(category="deploy_webhook", project=project),
67 name="{}_deploy".format(project), treeStableTimer=timer, builderNames=["{}_deploy".format(project)])
68
35def configure(c): 69def configure(c):
36 c["buildbotURL"] = E.BUILDBOT_URL 70 c["buildbotURL"] = E.BUILDBOT_URL
37 c["www"]["port"] = E.SOCKET 71 c["www"]["port"] = E.SOCKET
38 72
73 c["www"]["change_hook_dialects"]["base"] = {
74 "custom_class": CustomBase
75 }
39 c['workers'].append(worker.LocalWorker("generic-worker")) 76 c['workers'].append(worker.LocalWorker("generic-worker"))
40 c['workers'].append(worker.LocalWorker("deploy-worker")) 77 c['workers'].append(worker.LocalWorker("deploy-worker"))
41 78
42 c['schedulers'].append(hook_scheduler("Caldance", timer=1)) 79 c['schedulers'].append(hook_scheduler("Caldance", timer=1))
43 c['schedulers'].append(force_scheduler("force_caldance", ["Caldance_build"])) 80 c['schedulers'].append(force_scheduler("force_caldance", ["Caldance_build"]))
44 c['schedulers'].append(deploy_scheduler("deploy_caldance", ["Caldance_deploy"])) 81 c['schedulers'].append(deploy_scheduler("deploy_caldance", ["Caldance_deploy"]))
82 c['schedulers'].append(deploy_hook_scheduler("Caldance", timer=1))
45 83
46 c['builders'].append(factory("caldance")) 84 c['builders'].append(factory("caldance"))
47 85
diff --git a/nixops/modules/buildbot/projects/test/__init__.py b/nixops/modules/buildbot/projects/test/__init__.py
index adda289..0644920 100644
--- a/nixops/modules/buildbot/projects/test/__init__.py
+++ b/nixops/modules/buildbot/projects/test/__init__.py
@@ -1,6 +1,8 @@
1from buildbot.plugins import * 1from buildbot.plugins import *
2from buildbot_common.build_helpers import * 2from buildbot_common.build_helpers import *
3import os 3import os
4from buildbot.util import bytes2unicode
5import json
4 6
5__all__ = [ "configure", "E" ] 7__all__ = [ "configure", "E" ]
6 8
@@ -28,16 +30,52 @@ class E():
28 TITLE_URL = "https://git.immae.eu/?p=perso/Immae/TestProject.git;a=summary" 30 TITLE_URL = "https://git.immae.eu/?p=perso/Immae/TestProject.git;a=summary"
29 TITLE = "Test project" 31 TITLE = "Test project"
30 32
33class 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
60def deploy_hook_scheduler(project, timer=1):
61 return schedulers.AnyBranchScheduler(
62 change_filter=util.ChangeFilter(category="deploy_webhook", project=project),
63 name="{}_deploy".format(project), treeStableTimer=timer, builderNames=["{}_deploy".format(project)])
64
31def configure(c): 65def configure(c):
32 c["buildbotURL"] = E.BUILDBOT_URL 66 c["buildbotURL"] = E.BUILDBOT_URL
33 c["www"]["port"] = E.SOCKET 67 c["www"]["port"] = E.SOCKET
34 68
69 c["www"]["change_hook_dialects"]["base"] = {
70 "custom_class": CustomBase
71 }
35 c['workers'].append(worker.LocalWorker("generic-worker-test")) 72 c['workers'].append(worker.LocalWorker("generic-worker-test"))
36 c['workers'].append(worker.LocalWorker("deploy-worker-test")) 73 c['workers'].append(worker.LocalWorker("deploy-worker-test"))
37 74
38 c['schedulers'].append(hook_scheduler("TestProject", timer=1)) 75 c['schedulers'].append(hook_scheduler("TestProject", timer=1))
39 c['schedulers'].append(force_scheduler("force_test", ["TestProject_build"])) 76 c['schedulers'].append(force_scheduler("force_test", ["TestProject_build"]))
40 c['schedulers'].append(deploy_scheduler("deploy_test", ["TestProject_deploy"])) 77 c['schedulers'].append(deploy_scheduler("deploy_test", ["TestProject_deploy"]))
78 c['schedulers'].append(deploy_hook_scheduler("TestProject", timer=1))
41 79
42 c['builders'].append(factory()) 80 c['builders'].append(factory())
43 c['builders'].append(deploy_factory()) 81 c['builders'].append(deploy_factory())