]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Add buildbot website project
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 18 Oct 2019 12:25:10 +0000 (14:25 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 18 Oct 2019 12:25:10 +0000 (14:25 +0200)
modules/private/buildbot/default.nix
modules/private/buildbot/projects/immaeEu/__init__.py [new file with mode: 0644]
modules/private/websites/immae/production.nix

index 88bab9b687f88841e8db9cd76d28ae5ddfa65718..0e63337d3b4677f098e686c784bdc4ae5e6a1edd 100644 (file)
@@ -68,7 +68,11 @@ in
 
     system.activationScripts = lib.attrsets.mapAttrs' (k: project: lib.attrsets.nameValuePair "buildbot-${project.name}" {
       deps = [ "users" "wrappers" ];
-      text = project.activationScript;
+      text = ''
+        install -m 755 -o buildbot -g buildbot -d ${varDir}/${project.name}
+
+        ${project.activationScript}
+        '';
     }) myconfig.env.buildbot.projects;
 
     secrets.keys = (
diff --git a/modules/private/buildbot/projects/immaeEu/__init__.py b/modules/private/buildbot/projects/immaeEu/__init__.py
new file mode 100644 (file)
index 0000000..23ac970
--- /dev/null
@@ -0,0 +1,82 @@
+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       = "immaeEu"
+    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)
+    RELEASE_PATH  = "/var/lib/buildbot/outputs/immaeEu"
+    GIT_URL       = "gitolite@git.immae.eu:perso/Immae/Sites/Blog"
+    SSH_KEY_PATH  = "/var/lib/buildbot/buildbot_key"
+    SSH_HOST_KEY  = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIFbhFTl2A2RJn5L51yxJM4XfCS2ZaiSX/jo9jFSdghF"
+    XMPP_RECIPIENTS = os.environ["BUILDBOT_XMPP_RECIPIENTS"].split(" ")
+
+    # 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=immaeEu,cn=buildbot,ou=services,dc=immae,dc=eu)(member=%(dn)s))"
+    TITLE_URL          = "https://www.immae.eu"
+    TITLE              = "Immae website"
+
+class CustomBase(webhooks.base):
+    def getChanges(self, request):
+        try:
+            content = request.content.read()
+            args = json.loads(bytes2unicode(content))
+        except Exception as e:
+            raise ValueError("Error loading JSON: " + str(e))
+
+        args.setdefault("comments", "")
+        args.setdefault("repository", "")
+        args.setdefault("author", args.get("who", "unknown"))
+
+        return ([args], None)
+
+def configure(c):
+    c["buildbotURL"] = E.BUILDBOT_URL
+    c["www"]["port"] = E.SOCKET
+
+    c["www"]["change_hook_dialects"]["base"] = {
+            "custom_class": CustomBase
+            }
+    c['workers'].append(worker.LocalWorker("generic-worker-immae-eu"))
+
+    c['schedulers'].append(hook_scheduler("ImmaeEu", timer=1))
+    c['schedulers'].append(force_scheduler("force_immae_eu", ["ImmaeEu_build"]))
+
+    c['builders'].append(factory())
+
+    c['services'].append(SlackStatusPush(
+        name="slack_status_immae_eu_project",
+        builders=["ImmaeEu_build"],
+        serverUrl=open(E.SECRETS_FILE + "/slack_webhook", "r").read().rstrip()))
+    c['services'].append(XMPPStatusPush(
+        name="xmpp_status_immae_eu_project",
+        builders=["ImmaeEu_build"],
+        recipients=E.XMPP_RECIPIENTS,
+        password=open(E.SECRETS_FILE + "/notify_xmpp_password", "r").read().rstrip()))
+
+def factory():
+    factory = util.BuildFactory()
+    factory.addStep(steps.Git(logEnviron=False, repourl=E.GIT_URL,
+        sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(),
+        sshHostKey=E.SSH_HOST_KEY, mode="full", method="copy"))
+    factory.addStep(steps.ShellCommand(name="build website",
+        logEnviron=False, haltOnFailure=True, workdir="source",
+        command=["make", "html"]))
+    factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.RELEASE_PATH)))
+    factory.addStep(steps.DirectoryUpload(workersrc="../source/output",
+        masterdest=E.RELEASE_PATH,
+        url="https://www.immae.eu"))
+    factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.RELEASE_PATH)))
+
+    return util.BuilderConfig(name="ImmaeEu_build", workernames=["generic-worker-immae-eu"], factory=factory)
index 6b88ff2c0a1fbe28ce249c363f03a5836b7cf60e..e02d026fc2f91acba7ceabe50283479056270eba 100644 (file)
@@ -1,7 +1,7 @@
 { lib, pkgs, config, myconfig,  ... }:
 let
   cfg = config.myServices.websites.immae.production;
-  varDir = "/var/lib/ftp/immae";
+  varDir = "/var/lib/buildbot/outputs/immaeEu";
   env = myconfig.env.websites.immae;
 in {
   options.myServices.websites.immae.production.enable = lib.mkEnableOption "enable Immae's website";
@@ -24,11 +24,6 @@ in {
           AllowOverride All
           Require all granted
         </Directory>
-
-        <Location /blog_old/>
-          Use LDAPConnect
-          Require ldap-group cn=blog,cn=immae.eu,ou=services,dc=immae,dc=eu
-        </Location>
         ''
       ];
     };