X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=nixops%2Fmodules%2Fwebsites%2Fconnexionswing%2Fconnexionswing.nix;h=13d4fbabb228a794b5d9d05a98f2553b08b2e383;hb=8eded9ecb6220bb26599419a4aaea1743d3d187e;hp=f3945748764e98c1eef1036053913b38609da780;hpb=01f21083a897b86bf148f1d2bb9c8edca4d3786a;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/nixops/modules/websites/connexionswing/connexionswing.nix b/nixops/modules/websites/connexionswing/connexionswing.nix index f394574..13d4fba 100644 --- a/nixops/modules/websites/connexionswing/connexionswing.nix +++ b/nixops/modules/websites/connexionswing/connexionswing.nix @@ -3,25 +3,49 @@ let connexionswing = { config }: rec { environment = config.environment; varDir = "/var/lib/connexionswing_${environment}"; - configRoot = - writeText "parameters.yml" '' + keys."${environment}-connexionswing" = { + destDir = "/run/keys/webapps"; + user = apache.user; + group = apache.group; + permissions = "0400"; + text = '' # This file is auto-generated during the composer install parameters: - database_host: db-1.immae.eu - database_port: null + database_host: ${config.mysql.host} + database_port: ${config.mysql.port} database_name: ${config.mysql.name} database_user: ${config.mysql.user} database_password: ${config.mysql.password} database_server_version: ${pkgs.mariadb.mysqlVersion} - mailer_transport: smtp - mailer_host: mail.immae.eu + mailer_transport: sendmail + mailer_host: null mailer_user: null mailer_password: null subscription_email: ${config.email} allow_robots: true secret: ${config.secret} + ${if environment == "prod" then '' + services: + swiftmailer.mailer.default.transport: + class: Swift_SendmailTransport + arguments: ['/run/wrappers/bin/sendmail -bs'] + '' else ""} ''; + }; phpFpm = rec { + preStart = '' + if [ ! -f "${varDir}/currentWebappDir" -o \ + ! -f "${varDir}/currentKey" -o \ + "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ] \ + || ! sha512sum -c --status ${varDir}/currentKey; then + pushd ${webappDir} > /dev/null + /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup + popd > /dev/null + echo -n "${webappDir}" > ${varDir}/currentWebappDir + sha512sum /run/keys/webapps/${environment}-connexionswing > ${varDir}/currentKey + fi + ''; + serviceDeps = [ "mysql.service" "${environment}-connexionswing-key.service" ]; socket = "/var/run/phpfpm/connexionswing-${environment}.sock"; phpConfig = '' extension=${phpPackages.imagick}/lib/php/extensions/imagick.so @@ -35,7 +59,7 @@ let php_admin_value[upload_max_filesize] = 20M php_admin_value[post_max_size] = 20M ;php_admin_flag[log_errors] = on - php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp" + php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/run/keys/webapps/${environment}-connexionswing:${webappDir}:${varDir}:/tmp" php_admin_value[session.save_path] = "${varDir}/phpSessions" ${if environment == "dev" then '' pm = ondemand @@ -50,10 +74,12 @@ let pm.max_spare_servers = 3 ''}''; }; - apache = { + apache = rec { user = "wwwrun"; group = "wwwrun"; modules = [ "proxy_fcgi" ]; + webappName = "connexionswing_${environment}"; + root = "/run/current-system/webapps/${webappName}"; vhostConf = '' SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" @@ -78,7 +104,7 @@ let ErrorDocument 401 "" - + Options Indexes FollowSymLinks MultiViews Includes AllowOverride None Require all granted @@ -121,7 +147,7 @@ let '' else '' Use Stats connexionswing.com - + Options Indexes FollowSymLinks MultiViews Includes AllowOverride All Require all granted @@ -137,13 +163,6 @@ let ${varDir}/uploads \ ${varDir}/var install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions - if [ ! -f "${varDir}/currentWebappDir" -o \ - "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then - pushd ${webappDir} > /dev/null - $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup - popd > /dev/null - echo -n "${webappDir}" > ${varDir}/currentWebappDir - fi ''; }; webappDir = composerEnv.buildPackage ( @@ -158,10 +177,10 @@ let cd $out ${if environment == "prod" then "php ./bin/console assetic:dump --env=prod --no-debug" else ""} rm app/config/parameters.yml - ln -sf ${configRoot} app/config/parameters.yml + ln -sf /run/keys/webapps/${environment}-connexionswing app/config/parameters.yml rm -rf var/{logs,cache} - ln -sf ../../../../../../${varDir}/var/{logs,cache} var/ - ln -sf ../../../../../${varDir}/{medias,uploads} web/images/ + ln -sf ${varDir}/var/{logs,cache} var/ + ln -sf ${varDir}/{medias,uploads} web/images/ ''; }); webRoot = "${webappDir}/web";