]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/websites/piedsjaloux/integration.nix
Rework integration websites
[perso/Immae/Config/Nix.git] / modules / private / websites / piedsjaloux / integration.nix
index 3502964f19aef2af5008e0d88248231d06d5ea2c..01f681ca31bffae2fc85e2c317883fded49db290 100644 (file)
@@ -1,30 +1,31 @@
 { lib, pkgs, config,  ... }:
 let
   secrets = config.myEnv.websites.piedsjaloux.integration;
-  webRoot = "/var/lib/ftp/immae/piedsjaloux/web";
   cfg = config.myServices.websites.piedsjaloux.integration;
-  pcfg = config.services.phpApplication;
   texlive = pkgs.texlive.combine { inherit (pkgs.texlive) attachfile preprint scheme-small; };
+  ftpRoot = "/var/lib/piedsjaloux_integration";
+  phpRoot = "${ftpRoot}/php";
+  webRoot = "${phpRoot}/web";
+  varDir = "${ftpRoot}/var";
+  sessionDir = "${ftpRoot}/sessions";
+  packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Piedsjaloux";
+  branch = "test";
 in {
   options.myServices.websites.piedsjaloux.integration.enable = lib.mkEnableOption "enable PiedsJaloux's website in integration";
 
   config = lib.mkIf cfg.enable {
-    services.phpApplication.apps.piedsjaloux_integration = {
-      websiteEnv = "integration";
-      httpdUser = config.services.httpd.Inte.user;
-      httpdGroup = config.services.httpd.Inte.group;
-      inherit webRoot;
-      varDir = "/var/lib/ftp/immae/piedsjaloux_var";
-      varDirPaths = {
-        "tmp" = "0700";
-      };
-      app = "/var/lib/ftp/immae/piedsjaloux";
-      serviceDeps = [ "mysql.service" ];
-      preStartActions = [
-        "./bin/console --env=dev cache:clear --no-warmup"
-      ];
-      phpOpenbasedir = [ "/tmp" ];
-      phpPool = {
+    services.phpfpm.pools.piedsjaloux_integration = {
+      user = config.services.httpd.Inte.user;
+      group = config.services.httpd.Inte.group;
+      settings = {
+        "listen.owner" = config.services.httpd.Inte.user;
+        "listen.group" = config.services.httpd.Inte.group;
+        "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [
+          ftpRoot
+          config.secrets.fullPaths."websites/piedsjaloux/integration"
+          "/tmp"
+        ];
+        "php_admin_value[session.save_path]" = sessionDir;
         "php_admin_value[upload_max_filesize]" = "20M";
         "php_admin_value[post_max_size]" = "20M";
         #"php_admin_flag[log_errors]" = "on";
@@ -33,18 +34,60 @@ in {
         "pm.process_idle_timeout" = "60";
       };
       phpEnv = {
-        PATH = lib.makeBinPath [
-          pkgs.apg pkgs.unzip
-          # below ones don't need to be in the PATH but they’re used in
-          # secrets
-          pkgs.imagemagick texlive
-        ];
         SYMFONY_DEBUG_MODE = "\"yes\"";
       };
-      phpWatchFiles = [
-        config.secrets.fullPaths."websites/piedsjaloux/integration"
-      ];
-      phpPackage = pkgs.php72;
+      phpPackage = pkgs.php74;
+    };
+    systemd.services."phpfpm-piedsjaloux_integration" = {
+      after = lib.mkAfter ["mysql.service"];
+      wants = ["mysql.service"];
+      path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php74 ];
+      preStart = let
+        script = pkgs.writeScriptBin "piedsjaloux-integration-pre" ''
+          #! ${pkgs.stdenv.shell}
+
+          [ -f ${packagePath}/${branch}.tar.gz ] || exit 1
+
+          cd ${ftpRoot}
+          if ! [ -f .tarball_sum ] || ! sha256sum -c .tarball_sum; then
+            tar -xf ${packagePath}/${branch}.tar.gz --one-top-level=php_new
+            if [ -d php ]; then
+              mv php php_old
+            fi
+            mv php_new php
+          fi
+          cd php
+          rm -rf var/{logs,cache,data,miniatures,tmp}
+          ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/
+          ln -sf ${config.secrets.fullPaths."websites/piedsjaloux/integration"} app/config/parameters.yml
+          SYMFONY_ENV=dev ./bin/console --env=dev cache:clear --no-warmup
+          sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum
+        '';
+      in
+        "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/piedsjaloux-integration-pre";
+      postStart = let
+        script = pkgs.writeScriptBin "piedsjaloux-integration-post" ''
+          #! ${pkgs.stdenv.shell}
+
+          cd ${ftpRoot}
+          if [ -d php_old ]; then
+            rm -rf php_old
+          fi
+        '';
+      in
+        "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/piedsjaloux-integration-post";
+      serviceConfig.TimeoutStartSec="infinity";
+    };
+    services.filesWatcher.phpfpm-piedsjaloux_integration = {
+      restart = true;
+      paths = [ "${packagePath}/${branch}.tar.gz" ];
+    };
+
+    system.activationScripts.piedsjaloux_integration = {
+      deps = ["users"];
+      text = ''
+        install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot} ${sessionDir}
+      '';
     };
 
     secrets.keys."websites/piedsjaloux/integration" = {
@@ -79,7 +122,7 @@ in {
       extraConfig = [
         ''
         <FilesMatch "\.php$">
-          SetHandler "proxy:unix:${pcfg.phpListenPaths.piedsjaloux_integration}|fcgi://localhost"
+          SetHandler "proxy:unix:${config.services.phpfpm.pools.piedsjaloux_integration.socket}|fcgi://localhost"
         </FilesMatch>
 
         <Location />