]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/buildbot/common/build_helpers.py
Rework buildbot: Move towards independent builds
[perso/Immae/Config/Nix.git] / modules / private / buildbot / common / build_helpers.py
index 55b8b989d26aa664a7aac9298f839af19e2e997e..ebd49ae9d4a53310b9aaf7ecb605bb07769a00ac 100644 (file)
@@ -5,7 +5,7 @@ from shutil import which
 __all__ = [
         "force_scheduler", "deploy_scheduler", "git_hook_scheduler",
         "clean_branch", "package_and_upload", "SlackStatusPush",
-        "XMPPStatusPush", "LdapEdit", "NixShellCommand",
+        "XMPPStatusPush", "NixShellCommand",
         "all_builder_names", "compute_build_infos", "deploy_ssh_command",
         "configure_slack_push", "configure_xmpp_push", "deploy_hook_scheduler",
         ]
@@ -35,7 +35,7 @@ def package_and_upload(package, package_dest, package_url):
 
 # Steps
 class NixShellCommand(steps.ShellCommand):
-    def __init__(self, command=None, pure=True, nixfile=None, **kwargs):
+    def __init__(self, command=None, nixPackages=[], pure=True, nixFile=None, nixIncludes={}, nixArgs={}, **kwargs):
         oldpath = kwargs.get("env", {}).get("PATH", None)
         if which("nix-shell", path=oldpath) is None:
             kwargs["env"] = kwargs.get("env", {})
@@ -44,12 +44,22 @@ class NixShellCommand(steps.ShellCommand):
             elif isinstance(oldpath, list):
                 kwargs["env"]["PATH"] = ["/run/current-system/sw/bin"] + oldpath
         nixcommand = ["nix-shell"]
+        for k, v in nixArgs.items():
+            nixcommand.append("--arg")
+            nixcommand.append(k)
+            nixcommand.append(v)
         if pure:
             nixcommand.append("--pure")
+        for k, v in nixIncludes.items():
+            nixcommand.append("-I")
+            nixcommand.append("{}={}".format(k, v))
         nixcommand.append("--run")
         nixcommand.append(command)
-        if nixfile is not None:
-            nixcommand.append(nixfile)
+        if len(nixPackages) > 0:
+            nixcommand.append("-p")
+            nixcommand += nixPackages
+        elif nixFile is not None:
+            nixcommand.append(nixFile)
         super().__init__(command=nixcommand, **kwargs)
 
 # Schedulers
@@ -307,47 +317,6 @@ from buildbot.process.buildstep import FAILURE
 from buildbot.process.buildstep import SUCCESS
 from buildbot.process.buildstep import BuildStep
 
-class LdapEdit(BuildStep):
-    name = "LdapEdit"
-    renderables = ["environment", "build_version", "build_hash", "ldap_password"]
-
-    def __init__(self, **kwargs):
-        self.environment = kwargs.pop("environment")
-        self.build_version = kwargs.pop("build_version")
-        self.build_hash = kwargs.pop("build_hash")
-        self.ldap_password = kwargs.pop("ldap_password")
-        self.ldap_host = kwargs.pop("ldap_host")
-        self.ldap_dn = kwargs.pop("ldap_dn")
-        self.ldap_roles_base = kwargs.pop("ldap_roles_base")
-        self.ldap_cn_template = kwargs.pop("ldap_cn_template")
-        self.config_key = kwargs.pop("config_key")
-        super().__init__(**kwargs)
-
-    def run(self):
-        import json
-        from ldap3 import Reader, Writer, Server, Connection, ObjectDef
-        server = Server(self.ldap_host)
-        conn = Connection(server,
-                user=self.ldap_dn,
-                password=self.ldap_password)
-        conn.bind()
-        obj = ObjectDef("immaePuppetClass", conn)
-        r = Reader(conn, obj,
-                "cn={},{}".format(self.ldap_cn_template.format(self.environment), self.ldap_roles_base))
-        r.search()
-        if len(r) > 0:
-            w = Writer.from_cursor(r)
-            for value in w[0].immaePuppetJson.values:
-                config = json.loads(value)
-                if "{}_version".format(self.config_key) in config:
-                    config["{}_version".format(self.config_key)] = self.build_version
-                    config["{}_sha256".format(self.config_key)] = self.build_hash
-                    w[0].immaePuppetJson -= value
-                    w[0].immaePuppetJson += json.dumps(config, indent="  ")
-                    w.commit()
-                    return defer.succeed(SUCCESS)
-        return defer.succeed(FAILURE)
-
 def compute_build_infos(prefix, release_path):
     @util.renderer
     def compute(props):