From 9f66adf4372a3b1c859dc053489f727aa360077e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 2 Jun 2019 22:53:54 +0200 Subject: [PATCH] Move integration php applications to dedicated module --- modules/private/websites/aten/integration.nix | 2 +- modules/private/websites/aten/production.nix | 2 +- .../websites/connexionswing/integration.nix | 154 +++++++++++++++--- modules/private/websites/florian/app.nix | 4 +- .../websites/ludivinecassal/integration.nix | 151 ++++++++++++++--- .../websites/piedsjaloux/integration.nix | 136 +++++++++++++--- 6 files changed, 374 insertions(+), 75 deletions(-) diff --git a/modules/private/websites/aten/integration.nix b/modules/private/websites/aten/integration.nix index 38068a7..6768f80 100644 --- a/modules/private/websites/aten/integration.nix +++ b/modules/private/websites/aten/integration.nix @@ -36,7 +36,7 @@ in { secrets.keys = [{ dest = "webapps/${app.environment}-aten"; user = config.services.httpd.Inte.user; - group = config.services.httpd.Inte.user; + group = config.services.httpd.Inte.group; permissions = "0400"; text = '' SetEnv APP_ENV "${app.environment}" diff --git a/modules/private/websites/aten/production.nix b/modules/private/websites/aten/production.nix index 21ecdcf..97f4a08 100644 --- a/modules/private/websites/aten/production.nix +++ b/modules/private/websites/aten/production.nix @@ -38,7 +38,7 @@ in { secrets.keys = [{ dest = "webapps/${app.environment}-aten"; user = config.services.httpd.Prod.user; - group = config.services.httpd.Prod.user; + group = config.services.httpd.Prod.group; permissions = "0400"; text = '' SetEnv APP_ENV "${app.environment}" diff --git a/modules/private/websites/connexionswing/integration.nix b/modules/private/websites/connexionswing/integration.nix index 795d532..2ceaffa 100644 --- a/modules/private/websites/connexionswing/integration.nix +++ b/modules/private/websites/connexionswing/integration.nix @@ -1,40 +1,140 @@ { lib, pkgs, config, myconfig, ... }: let - connexionswing = pkgs.callPackage ./builder.nix { - inherit (pkgs.webapps) connexionswing; - config = myconfig.env.websites.connexionswing.integration; - apacheUser = config.services.httpd.Inte.user; - apacheGroup = config.services.httpd.Inte.group; - }; - + secrets = myconfig.env.websites.connexionswing.integration; + app = pkgs.webapps.connexionswing.override { environment = secrets.environment; }; cfg = config.myServices.websites.connexionswing.integration; + pcfg = config.services.phpApplication; in { options.myServices.websites.connexionswing.integration.enable = lib.mkEnableOption "enable Connexionswing's website in integration"; config = lib.mkIf cfg.enable { - secrets.keys = connexionswing.keys; - systemd.services.phpfpm-connexionswing_dev.after = lib.mkAfter connexionswing.phpFpm.serviceDeps; - systemd.services.phpfpm-connexionswing_dev.wants = connexionswing.phpFpm.serviceDeps; - systemd.services.phpfpm-connexionswing_dev.preStart = lib.mkAfter connexionswing.phpFpm.preStart; - services.phpfpm.pools.connexionswing_dev = { - listen = connexionswing.phpFpm.socket; - extraConfig = connexionswing.phpFpm.pool; - phpOptions = config.services.phpfpm.phpOptions + connexionswing.phpFpm.phpConfig; + services.phpApplication.apps.connexionswing_dev = { + websiteEnv = "integration"; + httpdUser = config.services.httpd.Inte.user; + httpdGroup = config.services.httpd.Inte.group; + inherit (app) webRoot varDir; + varDirPaths = { + "medias" = "0700"; + "uploads" = "0700"; + "var" = "0700"; + }; + inherit app; + serviceDeps = [ "mysql.service" ]; + preStartActions = [ + "./bin/console --env=${app.environment} cache:clear --no-warmup" + ]; + phpOpenbasedir = [ "/tmp" "/run/wrappers/bin/sendmail" ]; + phpPool = '' + php_admin_value[upload_max_filesize] = 20M + php_admin_value[post_max_size] = 20M + ;php_admin_flag[log_errors] = on + pm = ondemand + pm.max_children = 5 + pm.process_idle_timeout = 60 + env[SYMFONY_DEBUG_MODE] = "yes" + ''; + phpWatchFiles = [ + config.secrets.fullPaths."webapps/${app.environment}-connexionswing" + ]; }; - system.activationScripts.connexionswing_dev = connexionswing.activationScript; - myServices.websites.webappDirs."${connexionswing.apache.webappName}" = connexionswing.app.webRoot; - services.websites.env.integration.modules = connexionswing.apache.modules; - services.websites.env.integration.vhostConfs.connexionswing = { - certName = "eldiron"; + + secrets.keys = [ + { + dest = "webapps/${app.environment}-connexionswing"; + user = config.services.httpd.Inte.user; + group = config.services.httpd.Inte.group; + permissions = "0400"; + text = '' + # This file is auto-generated during the composer install + parameters: + database_host: ${secrets.mysql.host} + database_port: ${secrets.mysql.port} + database_name: ${secrets.mysql.name} + database_user: ${secrets.mysql.user} + database_password: ${secrets.mysql.password} + database_server_version: ${pkgs.mariadb.mysqlVersion} + mailer_transport: sendmail + mailer_host: null + mailer_user: null + mailer_password: null + subscription_email: ${secrets.email} + allow_robots: true + secret: ${secrets.secret} + ''; + } + ]; + + services.websites.env.integration.vhostConfs.connexionswing_dev = { + certName = "eldiron"; addToCerts = true; hosts = ["connexionswing.immae.eu" "sandetludo.immae.eu" ]; - root = connexionswing.apache.root; - extraConfig = [ connexionswing.apache.vhostConf ]; - }; - services.filesWatcher.phpfpm-connexionswing_dev = { - restart = true; - paths = [ "/var/secrets/webapps/${connexionswing.app.environment}-connexionswing" ]; + root = pcfg.webappDirs.connexionswing_dev; + extraConfig = [ + '' + + SetHandler "proxy:unix:${pcfg.phpListenPaths.connexionswing_dev}|fcgi://localhost" + + + + Options FollowSymLinks + AllowOverride None + Require all granted + + + + Options FollowSymLinks + AllowOverride None + Require all granted + + + + Use LDAPConnect + Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu + ErrorDocument 401 "" + + + + Options Indexes FollowSymLinks MultiViews Includes + AllowOverride None + Require all granted + + DirectoryIndex app_dev.php + + + Options -MultiViews + + + + RewriteEngine On + + RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ + RewriteRule ^(.*) - [E=BASE:%1] + + # Maintenance script + RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f + RewriteCond %{SCRIPT_FILENAME} !maintenance.php + RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] + ErrorDocument 503 /maintenance.php + + # Sets the HTTP_AUTHORIZATION header removed by Apache + RewriteCond %{HTTP:Authorization} . + RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + RewriteCond %{ENV:REDIRECT_STATUS} ^$ + RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] + + # If the requested filename exists, simply serve it. + # We only want to let Apache serve files and not directories. + RewriteCond %{REQUEST_FILENAME} -f + RewriteRule ^ - [L] + + # Rewrite all other queries to the front controller. + RewriteRule ^ %{ENV:BASE}/app_dev.php [L] + + + + '' + ]; }; }; } - diff --git a/modules/private/websites/florian/app.nix b/modules/private/websites/florian/app.nix index 5ce073a..3f44ec4 100644 --- a/modules/private/websites/florian/app.nix +++ b/modules/private/websites/florian/app.nix @@ -41,7 +41,7 @@ in { { dest = "webapps/${app.environment}-tellesflorian-passwords"; user = config.services.httpd.Inte.user; - group = config.services.httpd.Inte.user; + group = config.services.httpd.Inte.group; permissions = "0400"; text = '' invite:${secrets.invite_passwords} @@ -50,7 +50,7 @@ in { { dest = "webapps/${app.environment}-tellesflorian"; user = config.services.httpd.Inte.user; - group = config.services.httpd.Inte.user; + group = config.services.httpd.Inte.group; permissions = "0400"; text = '' # This file is auto-generated during the composer install diff --git a/modules/private/websites/ludivinecassal/integration.nix b/modules/private/websites/ludivinecassal/integration.nix index bc05d9b..55f2432 100644 --- a/modules/private/websites/ludivinecassal/integration.nix +++ b/modules/private/websites/ludivinecassal/integration.nix @@ -1,36 +1,139 @@ { lib, pkgs, config, myconfig, ... }: let - ludivinecassal = pkgs.callPackage ./builder.nix { - inherit (pkgs.webapps) ludivinecassal; - config = myconfig.env.websites.ludivinecassal.integration; - apacheUser = config.services.httpd.Inte.user; - apacheGroup = config.services.httpd.Inte.group; - }; - + secrets = myconfig.env.websites.ludivinecassal.integration; + app = pkgs.webapps.ludivinecassal.override { environment = secrets.environment; }; cfg = config.myServices.websites.ludivinecassal.integration; + pcfg = config.services.phpApplication; in { options.myServices.websites.ludivinecassal.integration.enable = lib.mkEnableOption "enable Ludivine's website in integration"; config = lib.mkIf cfg.enable { - secrets.keys = ludivinecassal.keys; - - systemd.services.phpfpm-ludivinecassal_dev.after = lib.mkAfter ludivinecassal.phpFpm.serviceDeps; - systemd.services.phpfpm-ludivinecassal_dev.wants = ludivinecassal.phpFpm.serviceDeps; - systemd.services.phpfpm-ludivinecassal_dev.preStart = lib.mkAfter ludivinecassal.phpFpm.preStart; - services.phpfpm.poolConfigs.ludivinecassal_dev = ludivinecassal.phpFpm.pool; - system.activationScripts.ludivinecassal_dev = ludivinecassal.activationScript; - myServices.websites.webappDirs."${ludivinecassal.apache.webappName}" = ludivinecassal.app.webRoot; - services.websites.env.integration.modules = ludivinecassal.apache.modules; - services.websites.env.integration.vhostConfs.ludivine = { - certName = "eldiron"; + services.phpApplication.apps.ludivinecassal_dev = { + websiteEnv = "integration"; + httpdUser = config.services.httpd.Inte.user; + httpdGroup = config.services.httpd.Inte.group; + inherit (app) webRoot varDir; + varDirPaths = { + "tmp" = "0700"; + }; + inherit app; + serviceDeps = [ "mysql.service" ]; + preStartActions = [ + "./bin/console --env=${app.environment} cache:clear --no-warmup" + ]; + phpOpenbasedir = [ "/tmp" ]; + phpPool = '' + php_admin_value[upload_max_filesize] = 20M + php_admin_value[post_max_size] = 20M + ;php_admin_flag[log_errors] = on + pm = ondemand + pm.max_children = 5 + pm.process_idle_timeout = 60 + env[SYMFONY_DEBUG_MODE] = "yes" + ''; + phpWatchFiles = [ + config.secrets.fullPaths."webapps/${app.environment}-ludivinecassal" + ]; + }; + + secrets.keys = [ + { + dest = "webapps/${app.environment}-ludivinecassal"; + user = config.services.httpd.Inte.user; + group = config.services.httpd.Inte.group; + permissions = "0400"; + text = '' + # This file is auto-generated during the composer install + parameters: + database_host: ${secrets.mysql.host} + database_port: ${secrets.mysql.port} + database_name: ${secrets.mysql.name} + database_user: ${secrets.mysql.user} + database_password: ${secrets.mysql.password} + database_server_version: ${pkgs.mariadb.mysqlVersion} + mailer_transport: smtp + mailer_host: 127.0.0.1 + mailer_user: null + mailer_password: null + secret: ${secrets.secret} + ldap_host: ldap.immae.eu + ldap_port: 636 + ldap_version: 3 + ldap_ssl: true + ldap_tls: false + ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu' + ldap_base_dn: 'dc=immae,dc=eu' + ldap_search_dn: '${secrets.ldap.dn}' + ldap_search_password: '${secrets.ldap.password}' + ldap_search_filter: '${secrets.ldap.search}' + leapt_im: + binary_path: ${pkgs.imagemagick}/bin + assetic: + sass: ${pkgs.sass}/bin/sass + ruby: ${pkgs.ruby}/bin/ruby + ''; + } + ]; + + services.websites.env.integration.vhostConfs.ludivinecassal_dev = { + certName = "eldiron"; addToCerts = true; hosts = [ "ludivine.immae.eu" ]; - root = ludivinecassal.apache.root; - extraConfig = [ ludivinecassal.apache.vhostConf ]; - }; - services.filesWatcher.phpfpm-ludivinecassal_dev = { - restart = true; - paths = [ "/var/secrets/webapps/${ludivinecassal.app.environment}-ludivinecassal" ]; + root = pcfg.webappDirs.ludivinecassal_dev; + extraConfig = [ + '' + + SetHandler "proxy:unix:${pcfg.phpListenPaths.ludivinecassal_dev}|fcgi://localhost" + + + + Use LDAPConnect + Require ldap-group cn=ludivine.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu + ErrorDocument 401 "" + + + + Options Indexes FollowSymLinks MultiViews Includes + AllowOverride None + Require all granted + + DirectoryIndex app_dev.php + + + Options -MultiViews + + + + RewriteEngine On + + RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ + RewriteRule ^(.*) - [E=BASE:%1] + + # Maintenance script + RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f + RewriteCond %{SCRIPT_FILENAME} !maintenance.php + RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] + ErrorDocument 503 /maintenance.php + + # Sets the HTTP_AUTHORIZATION header removed by Apache + RewriteCond %{HTTP:Authorization} . + RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + RewriteCond %{ENV:REDIRECT_STATUS} ^$ + RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] + + # If the requested filename exists, simply serve it. + # We only want to let Apache serve files and not directories. + RewriteCond %{REQUEST_FILENAME} -f + RewriteRule ^ - [L] + + # Rewrite all other queries to the front controller. + RewriteRule ^ %{ENV:BASE}/app_dev.php [L] + + + + '' + ]; }; }; } diff --git a/modules/private/websites/piedsjaloux/integration.nix b/modules/private/websites/piedsjaloux/integration.nix index 8007c91..0a33bc0 100644 --- a/modules/private/websites/piedsjaloux/integration.nix +++ b/modules/private/websites/piedsjaloux/integration.nix @@ -1,32 +1,128 @@ { lib, pkgs, config, myconfig, ... }: let - piedsjaloux = pkgs.callPackage ./builder.nix { - inherit (pkgs.webapps) piedsjaloux; - config = myconfig.env.websites.piedsjaloux.integration; - apacheUser = config.services.httpd.Inte.user; - apacheGroup = config.services.httpd.Inte.group; - }; - + secrets = myconfig.env.websites.piedsjaloux.integration; + app = pkgs.webapps.piedsjaloux.override { environment = secrets.environment; }; cfg = config.myServices.websites.piedsjaloux.integration; + pcfg = config.services.phpApplication; in { options.myServices.websites.piedsjaloux.integration.enable = lib.mkEnableOption "enable PiedsJaloux's website in integration"; config = lib.mkIf cfg.enable { - secrets.keys = piedsjaloux.keys; - systemd.services.phpfpm-piedsjaloux_dev.after = lib.mkAfter piedsjaloux.phpFpm.serviceDeps; - systemd.services.phpfpm-piedsjaloux_dev.wants = piedsjaloux.phpFpm.serviceDeps; - systemd.services.phpfpm-piedsjaloux_dev.preStart = lib.mkAfter piedsjaloux.phpFpm.preStart; - services.phpfpm.poolConfigs.piedsjaloux_dev = piedsjaloux.phpFpm.pool; - system.activationScripts.piedsjaloux_dev = piedsjaloux.activationScript; - myServices.websites.webappDirs."${piedsjaloux.apache.webappName}" = piedsjaloux.app.webRoot; - services.websites.env.integration.modules = piedsjaloux.apache.modules; - services.websites.env.integration.vhostConfs.piedsjaloux = { - certName = "eldiron"; + services.phpApplication.apps.piedsjaloux_dev = { + websiteEnv = "integration"; + httpdUser = config.services.httpd.Inte.user; + httpdGroup = config.services.httpd.Inte.group; + inherit (app) webRoot varDir; + varDirPaths = { + "tmp" = "0700"; + }; + inherit app; + serviceDeps = [ "mysql.service" ]; + preStartActions = [ + "./bin/console --env=${app.environment} cache:clear --no-warmup" + ]; + phpOpenbasedir = [ "/tmp" ]; + phpPool = '' + php_admin_value[upload_max_filesize] = 20M + php_admin_value[post_max_size] = 20M + ;php_admin_flag[log_errors] = on + env[PATH] = ${lib.makeBinPath [ pkgs.apg pkgs.unzip ]} + pm = ondemand + pm.max_children = 5 + pm.process_idle_timeout = 60 + env[SYMFONY_DEBUG_MODE] = "yes" + ''; + phpWatchFiles = [ + config.secrets.fullPaths."webapps/${app.environment}-piedsjaloux" + ]; + }; + + secrets.keys = [ + { + dest = "webapps/${app.environment}-piedsjaloux"; + user = config.services.httpd.Inte.user; + group = config.services.httpd.Inte.group; + permissions = "0400"; + text = '' + # This file is auto-generated during the composer install + parameters: + database_host: ${secrets.mysql.host} + database_port: ${secrets.mysql.port} + database_name: ${secrets.mysql.name} + database_user: ${secrets.mysql.user} + database_password: ${secrets.mysql.password} + database_server_version: ${pkgs.mariadb.mysqlVersion} + mailer_transport: smtp + mailer_host: 127.0.0.1 + mailer_user: null + mailer_password: null + secret: ${secrets.secret} + pdflatex: "${pkgs.texlive.combine { inherit (pkgs.texlive) attachfile preprint scheme-small; }}/bin/pdflatex" + leapt_im: + binary_path: ${pkgs.imagemagick}/bin + ''; + } + ]; + + services.websites.env.integration.vhostConfs.piedsjaloux_dev = { + certName = "eldiron"; addToCerts = true; hosts = [ "piedsjaloux.immae.eu" ]; - root = piedsjaloux.apache.root; - extraConfig = [ piedsjaloux.apache.vhostConf ]; + root = pcfg.webappDirs.piedsjaloux_dev; + extraConfig = [ + '' + + SetHandler "proxy:unix:${pcfg.phpListenPaths.piedsjaloux_dev}|fcgi://localhost" + + + + Use LDAPConnect + Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu + ErrorDocument 401 "" + + + + Options Indexes FollowSymLinks MultiViews Includes + AllowOverride None + Require all granted + + DirectoryIndex app_dev.php + + + Options -MultiViews + + + + RewriteEngine On + + RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ + RewriteRule ^(.*) - [E=BASE:%1] + + # Maintenance script + RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f + RewriteCond %{SCRIPT_FILENAME} !maintenance.php + RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] + ErrorDocument 503 /maintenance.php + + # Sets the HTTP_AUTHORIZATION header removed by Apache + RewriteCond %{HTTP:Authorization} . + RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + RewriteCond %{ENV:REDIRECT_STATUS} ^$ + RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] + + # If the requested filename exists, simply serve it. + # We only want to let Apache serve files and not directories. + RewriteCond %{REQUEST_FILENAME} -f + RewriteRule ^ - [L] + + # Rewrite all other queries to the front controller. + RewriteRule ^ %{ENV:BASE}/app_dev.php [L] + + + + '' + ]; }; }; } - -- 2.41.0