]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Site de Bingo de Denise
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 5 Aug 2021 23:38:35 +0000 (01:38 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 29 Sep 2021 22:37:01 +0000 (00:37 +0200)
modules/private/buildbot/projects/denise/__init__.py
modules/private/default.nix
modules/private/websites/default.nix
modules/private/websites/denise/bingo.nix [new file with mode: 0644]

index 2a19ef57c9627a9b53370b24b424a25d7cea32a9..abeba3c7df68177f3ddaf087f2da2ebe3e075c40 100644 (file)
@@ -14,6 +14,10 @@ class E():
     SSH_KEY_PATH      = "/var/lib/buildbot/buildbot_key"
     SSH_HOST_KEY      = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIFbhFTl2A2RJn5L51yxJM4XfCS2ZaiSX/jo9jFSdghF"
 
+    BINGO_RELEASE_PATH  = "/var/lib/buildbot/outputs/denise/bingo"
+    BINGO_BETA_PATH     = "/var/lib/buildbot/outputs/denise/bingo_beta"
+    BINGO_GIT_URL       = "gitolite@git.immae.eu:perso/Denise/bingo"
+
     OMS_RELEASE_PATH  = "/var/lib/buildbot/outputs/denise/oms"
     OMS_BETA_PATH     = "/var/lib/buildbot/outputs/denise/oms_beta"
     OMS_GIT_URL       = "gitolite@git.immae.eu:perso/Denise/oms"
@@ -54,15 +58,59 @@ def configure(c):
             }
     c['workers'].append(worker.LocalWorker("generic-worker-denise"))
 
+    c['schedulers'].append(hook_scheduler("DeniseBingo", timer=1))
     c['schedulers'].append(hook_scheduler("DeniseOMS", timer=1))
     c['schedulers'].append(hook_scheduler("DeniseAventuriers", timer=1))
     c['schedulers'].append(force_scheduler("force_denise", [
-        "DeniseOMS_build", "DeniseAventuriers_build"
+        "DeniseBingo_build", "DeniseOMS_build", "DeniseAventuriers_build"
         ]))
 
     c['builders'].append(denise_oms_factory())
+    c['builders'].append(denise_bingo_factory())
     c['builders'].append(denise_aventuriers_factory())
 
+def denise_bingo_factory():
+    @util.renderer
+    def bingo_run_path(props):
+        if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master":
+            return "/run/denise_bingo/gunicorn.pid"
+        else:
+            return "/run/denise_bingo_beta/gunicorn.pid"
+
+    @util.renderer
+    def bingo_systemd_service(props):
+        if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master":
+            return "denise-bingo"
+        else:
+            return "denise-bingo-beta"
+
+    @util.renderer
+    def bingo_url(props):
+        if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master":
+            return "https://bingo.syanni.eu"
+        else:
+            return "https://beta.bingo.syanni.eu"
+
+    @util.renderer
+    def bingo_path(props):
+        if props.hasProperty("branch") and len(props["branch"]) > 0 and props["branch"] == "master":
+            return E.BINGO_RELEASE_PATH
+        else:
+            return E.BINGO_BETA_PATH
+
+    factory = util.BuildFactory()
+    factory.addStep(steps.Git(logEnviron=False, repourl=E.BINGO_GIT_URL,
+        submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(),
+        sshHostKey=E.SSH_HOST_KEY, mode="full", method="copy"))
+    factory.addStep(steps.MasterShellCommand(command=util.Interpolate("rm -rf %(kw:bingo_path)s", bingo_path=bingo_path)))
+    factory.addStep(steps.DirectoryUpload(workersrc="../source",
+        masterdest=bingo_path,
+        url=bingo_url))
+    factory.addStep(steps.MasterShellCommand(command=util.Interpolate("chmod -R a+rX %(kw:bingo_path)s", bingo_path=bingo_path)))
+    factory.addStep(steps.MasterShellCommand(command=util.Interpolate("/run/wrappers/bin/sudo systemctl restart %(kw:bingo_service)s.service", bingo_service=bingo_systemd_service)))
+
+    return util.BuilderConfig(name="DeniseBingo_build", workernames=["generic-worker-denise"], factory=factory)
+
 def denise_oms_factory():
     @util.renderer
     def oms_run_path(props):
index 0ff5214a7d5061b28e3233daa02bd2261871460f..6b64e6076cd5522276321192089fc644442647e6 100644 (file)
@@ -35,6 +35,7 @@ set = {
   deniseDenisejeromeProd = ./websites/denise/denisejerome.nix;
   deniseEvariste = ./websites/denise/evariste.nix;
   deniseOMS = ./websites/denise/oms.nix;
+  deniseBingo = ./websites/denise/bingo.nix;
   deniseAventuriers = ./websites/denise/aventuriers.nix;
   deniseProduction = ./websites/denise/production.nix;
 
index fa9ee8db7d2c293b8cb231f7bb04f06d41d7b094..ba2dde0707dc1b5d2de627a045753369854f8ab2 100644 (file)
@@ -243,6 +243,7 @@ in
         evariste.enable = true;
         denisejerome.enable = true;
         oms.enable = true;
+        bingo.enable = true;
         aventuriers.enable = true;
         production.enable = true;
       };
diff --git a/modules/private/websites/denise/bingo.nix b/modules/private/websites/denise/bingo.nix
new file mode 100644 (file)
index 0000000..9130462
--- /dev/null
@@ -0,0 +1,100 @@
+{ lib, config, pkgs, ... }:
+let
+  cfg = config.myServices.websites.denise.bingo;
+  varDir = "/var/lib/buildbot/outputs/denise/bingo";
+  varDirBeta = "/var/lib/buildbot/outputs/denise/bingo_beta";
+  socket = "/run/denise_bingo/socket.sock";
+  socket_beta = "/run/denise_bingo_beta/socket.sock";
+in {
+  options.myServices.websites.denise.bingo.enable = lib.mkEnableOption "enable Denise's bingo website";
+
+  config = lib.mkIf cfg.enable {
+    services.websites.env.production.vhostConfs.denise_bingo = {
+      certName     = "denise";
+      addToCerts   = true;
+      hosts        = [ "bingo.syanni.eu" ];
+      root         = null;
+      extraConfig  = [
+        ''
+        ProxyPreserveHost on
+        ProxyVia On
+        ProxyRequests Off
+        ProxyPassMatch ^/.well-known/acme-challenge !
+        ProxyPass / unix://${socket}|http://bingo.syanni.eu/
+        ProxyPassReverse / unix://${socket}|http://bingo.syanni.eu/
+          ''
+      ];
+    };
+
+    systemd.services.denise-bingo = {
+      description = "Denise bingo website";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+
+      serviceConfig = {
+        Type = "simple";
+        WorkingDirectory = varDir;
+        ExecStart = let
+          python = pkgs.python3.withPackages (p: [ p.gunicorn p.flask p.matplotlib p.unidecode ]);
+        in
+          "${python}/bin/gunicorn -w4 -p /run/denise_bingo/gunicorn.pid --bind unix:${socket} app:app";
+        User = "wwwrun";
+        Restart = "always";
+        RestartSec = "5s";
+        PIDFile = "/run/denise_bingo/gunicorn.pid";
+        RuntimeDirectory = "denise_bingo";
+        StandardOutput = "journal";
+        StandardError = "inherit";
+      };
+    };
+
+    security.sudo.extraRules = [
+      {
+        commands = [
+          { options = [ "NOPASSWD" ]; command = "${pkgs.systemd}/bin/systemctl restart denise-bingo-beta.service"; }
+          { options = [ "NOPASSWD" ]; command = "${pkgs.systemd}/bin/systemctl restart denise-bingo.service"; }
+        ];
+        users = ["buildbot"];
+        runAs = "root";
+      }
+    ];
+    services.websites.env.integration.vhostConfs.denise_bingo_beta = {
+      certName     = "denise";
+      addToCerts   = true;
+      hosts        = [ "beta.bingo.syanni.eu" ];
+      root         = null;
+      extraConfig  = [
+        ''
+        ProxyPreserveHost on
+        ProxyVia On
+        ProxyRequests Off
+        ProxyPassMatch ^/.well-known/acme-challenge !
+        ProxyPass / unix://${socket_beta}|http://beta.bingo.syanni.eu/
+        ProxyPassReverse / unix://${socket_beta}|http://beta.bingo.syanni.eu/
+          ''
+      ];
+    };
+
+    systemd.services.denise-bingo-beta = {
+      description = "Denise bingo beta website";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+
+      serviceConfig = {
+        Type = "simple";
+        WorkingDirectory = varDirBeta;
+        ExecStart = let
+          python = pkgs.python3.withPackages (p: [ p.gunicorn p.flask ]);
+        in
+          "${python}/bin/gunicorn -w4 -p /run/denise_bingo_beta/gunicorn.pid --bind unix:${socket_beta} app:app";
+        User = "wwwrun";
+        Restart = "always";
+        RestartSec = "5s";
+        PIDFile = "/run/denise_bingo_beta/gunicorn.pid";
+        RuntimeDirectory = "denise_bingo_beta";
+        StandardOutput = "journal";
+        StandardError = "inherit";
+      };
+    };
+  };
+}