X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fwebsites%2Fludivine%2Fintegration.nix;h=33ab191a1bc30d04a88fc0b8ecef8aaebf700ccd;hb=bbea22c02b6c059a6be1064391f06737ee244ba6;hp=49aa11350625f6023dde7bde40d8fa3aa4f8a530;hpb=7c5e6fe8b639e3175798c097170a0b94ca7326b7;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/websites/ludivine/integration.nix b/modules/private/websites/ludivine/integration.nix index 49aa113..33ab191 100644 --- a/modules/private/websites/ludivine/integration.nix +++ b/modules/private/websites/ludivine/integration.nix @@ -2,28 +2,29 @@ let secrets = config.myEnv.websites.ludivine.integration; cfg = config.myServices.websites.ludivine.integration; - pcfg = config.services.phpApplication; - webRoot = "/var/lib/ftp/immae/ludivine/web"; + ftpRoot = "/var/lib/ludivine_integration"; + phpRoot = "${ftpRoot}/php"; + webRoot = "${phpRoot}/web"; + varDir = "${ftpRoot}/var"; + packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Ludivine"; + branch = "test"; in { options.myServices.websites.ludivine.integration.enable = lib.mkEnableOption "enable Ludivine's website in integration"; config = lib.mkIf cfg.enable { - services.phpApplication.apps.ludivine_integration = { - websiteEnv = "integration"; - httpdUser = config.services.httpd.Inte.user; - httpdGroup = config.services.httpd.Inte.group; - inherit webRoot; - varDir = "/var/lib/ftp/immae/ludivine_var"; - app = "/var/lib/ftp/immae/ludivine"; - varDirPaths = { - "tmp" = "0700"; - }; - serviceDeps = [ "mysql.service" ]; - preStartActions = [ - "./bin/console --env=dev cache:clear --no-warmup" - ]; - phpOpenbasedir = [ "/tmp" ]; - phpPool = { + services.phpfpm.pools.ludivine_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/ludivine/integration" + "/tmp" + ]; + "php_admin_value[session.save_handler]" = "redis"; + "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=Ludivine:Production:'"; "php_admin_value[upload_max_filesize]" = "20M"; "php_admin_value[post_max_size]" = "20M"; #"php_admin_flag[log_errors]" = "on"; @@ -32,17 +33,60 @@ in { "pm.process_idle_timeout" = "60"; }; phpEnv = { - PATH = lib.makeBinPath [ - # below ones don't need to be in the PATH but they’re used in - # secrets - pkgs.imagemagick pkgs.sass pkgs.ruby - ]; SYMFONY_DEBUG_MODE = "\"yes\""; }; - phpWatchFiles = [ - config.secrets.fullPaths."websites/ludivine/integration" - ]; - phpPackage = pkgs.php72; + phpPackage = pkgs.php72.withExtensions({ enabled, all }: enabled ++ [all.redis]); + }; + systemd.services."phpfpm-ludivine_integration" = { + after = lib.mkAfter ["mysql.service"]; + wants = ["mysql.service"]; + path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ]; + preStart = let + script = pkgs.writeScriptBin "ludivine-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/ludivine/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/ludivine-integration-pre"; + postStart = let + script = pkgs.writeScriptBin "ludivine-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/ludivine-integration-post"; + serviceConfig.TimeoutStartSec="infinity"; + }; + services.filesWatcher.phpfpm-ludivine_integration = { + restart = true; + paths = [ "${packagePath}/${branch}.tar.gz" ]; + }; + + system.activationScripts.ludivine_integration = { + deps = []; + text = '' + install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot} + ''; }; secrets.keys."websites/ludivine/integration" = { @@ -57,7 +101,7 @@ in { database_name: ${secrets.mysql.database} database_user: ${secrets.mysql.user} database_password: ${secrets.mysql.password} - database_server_version: ${pkgs.mariadb.mysqlVersion} + database_server_version: ${config.myServices.databases.mariadb.package.mysqlVersion} mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: null @@ -89,7 +133,7 @@ in { extraConfig = [ '' - SetHandler "proxy:unix:${pcfg.phpListenPaths.ludivine_integration}|fcgi://localhost" + SetHandler "proxy:unix:${config.services.phpfpm.pools.ludivine_integration.socket}|fcgi://localhost"