]>
Commit | Line | Data |
---|---|---|
ab8f306d | 1 | { lib, pkgs, config, ... }: |
f8026b6e | 2 | let |
ab8f306d | 3 | secrets = config.myEnv.websites.connexionswing.integration; |
f8026b6e | 4 | cfg = config.myServices.websites.connexionswing.integration; |
2ff9258e IB |
5 | ftpRoot = "/var/lib/connexionswing_integration"; |
6 | phpRoot = "${ftpRoot}/php"; | |
7 | webRoot = "${phpRoot}/web"; | |
8 | varDir = "${ftpRoot}/var"; | |
9 | sessionDir = "${ftpRoot}/sessions"; | |
10 | packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Connexionswing"; | |
11 | branch = "test"; | |
f8026b6e IB |
12 | in { |
13 | options.myServices.websites.connexionswing.integration.enable = lib.mkEnableOption "enable Connexionswing's website in integration"; | |
14 | ||
15 | config = lib.mkIf cfg.enable { | |
2ff9258e IB |
16 | services.phpfpm.pools.connexionswing_integration = { |
17 | user = config.services.httpd.Inte.user; | |
18 | group = config.services.httpd.Inte.group; | |
19 | settings = { | |
20 | "listen.owner" = config.services.httpd.Inte.user; | |
21 | "listen.group" = config.services.httpd.Inte.group; | |
22 | "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [ | |
23 | ftpRoot | |
24 | config.secrets.fullPaths."websites/connexionswing/integration" | |
25 | "/tmp" | |
26 | ]; | |
27 | "php_admin_value[session.save_path]" = sessionDir; | |
5400b9b6 IB |
28 | "php_admin_value[upload_max_filesize]" = "20M"; |
29 | "php_admin_value[post_max_size]" = "20M"; | |
30 | #"php_admin_flag[log_errors]" = "on"; | |
31 | "pm" = "ondemand"; | |
32 | "pm.max_children" = "5"; | |
33 | "pm.process_idle_timeout" = "60"; | |
2ff9258e | 34 | }; |
5400b9b6 | 35 | phpEnv = { |
d3452fc5 | 36 | SYMFONY_DEBUG_MODE = "\"yes\""; |
5400b9b6 | 37 | }; |
dcac3ec7 | 38 | phpPackage = pkgs.php72; |
f40f5b23 | 39 | }; |
2ff9258e IB |
40 | systemd.services."phpfpm-connexionswing_integration" = { |
41 | after = lib.mkAfter ["mysql.service"]; | |
42 | wants = ["mysql.service"]; | |
43 | path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ]; | |
44 | preStart = let | |
45 | script = pkgs.writeScriptBin "connexionswing-integration-pre" '' | |
46 | #! ${pkgs.stdenv.shell} | |
47 | ||
48 | [ -f ${packagePath}/${branch}.tar.gz ] || exit 1 | |
49 | ||
50 | cd ${ftpRoot} | |
51 | if ! [ -f .tarball_sum ] || ! sha256sum -c .tarball_sum; then | |
52 | tar -xf ${packagePath}/${branch}.tar.gz --one-top-level=php_new | |
53 | if [ -d php ]; then | |
54 | mv php php_old | |
55 | fi | |
56 | mv php_new php | |
57 | fi | |
58 | cd php | |
59 | rm -rf var/{logs,cache} | |
60 | ln -sf ${varDir}/var/{logs,cache} var/ | |
61 | ln -sf ${varDir}/{medias,uploads} web/images/ | |
62 | ln -sf ${config.secrets.fullPaths."websites/connexionswing/integration"} app/config/parameters.yml | |
63 | SYMFONY_ENV=dev ./bin/console --env=dev cache:clear --no-warmup | |
64 | sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum | |
65 | ''; | |
66 | in | |
67 | "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/connexionswing-integration-pre"; | |
68 | postStart = let | |
69 | script = pkgs.writeScriptBin "connexionswing-integration-post" '' | |
70 | #! ${pkgs.stdenv.shell} | |
71 | ||
72 | cd ${ftpRoot} | |
73 | if [ -d php_old ]; then | |
74 | rm -rf php_old | |
75 | fi | |
76 | ''; | |
77 | in | |
78 | "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/connexionswing-integration-post"; | |
79 | serviceConfig.TimeoutStartSec="infinity"; | |
80 | }; | |
81 | services.filesWatcher.phpfpm-connexionswing_integration = { | |
82 | restart = true; | |
83 | paths = [ "${packagePath}/${branch}.tar.gz" ]; | |
84 | }; | |
85 | ||
86 | system.activationScripts.connexionswing_integration = { | |
87 | deps = ["users"]; | |
88 | text = '' | |
89 | install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot} ${sessionDir} | |
90 | ''; | |
91 | }; | |
9f66adf4 | 92 | |
4c4652aa IB |
93 | secrets.keys."websites/connexionswing/integration" = { |
94 | user = config.services.httpd.Inte.user; | |
95 | group = config.services.httpd.Inte.group; | |
96 | permissions = "0400"; | |
97 | text = '' | |
98 | # This file is auto-generated during the composer install | |
99 | parameters: | |
100 | database_host: ${secrets.mysql.host} | |
101 | database_port: ${secrets.mysql.port} | |
102 | database_name: ${secrets.mysql.database} | |
103 | database_user: ${secrets.mysql.user} | |
104 | database_password: ${secrets.mysql.password} | |
105 | database_server_version: ${pkgs.mariadb.mysqlVersion} | |
106 | mailer_transport: sendmail | |
107 | mailer_host: null | |
108 | mailer_user: null | |
109 | mailer_password: null | |
110 | subscription_email: ${secrets.email} | |
111 | allow_robots: true | |
112 | secret: ${secrets.secret} | |
113 | ''; | |
114 | }; | |
9f66adf4 | 115 | |
d3452fc5 IB |
116 | services.websites.env.integration.vhostConfs.connexionswing_integration = { |
117 | certName = "integration"; | |
f8026b6e | 118 | addToCerts = true; |
7c5e6fe8 | 119 | hosts = ["connexionswing.cs.immae.dev" "sandetludo.cs.immae.dev" ]; |
41cce84a | 120 | root = webRoot; |
9f66adf4 IB |
121 | extraConfig = [ |
122 | '' | |
123 | <FilesMatch "\.php$"> | |
2ff9258e | 124 | SetHandler "proxy:unix:${config.services.phpfpm.pools.connexionswing_integration.socket}|fcgi://localhost" |
9f66adf4 IB |
125 | </FilesMatch> |
126 | ||
41cce84a | 127 | <Directory ${varDir}/medias> |
9f66adf4 IB |
128 | Options FollowSymLinks |
129 | AllowOverride None | |
130 | Require all granted | |
131 | </Directory> | |
132 | ||
41cce84a | 133 | <Directory ${varDir}/uploads> |
9f66adf4 IB |
134 | Options FollowSymLinks |
135 | AllowOverride None | |
136 | Require all granted | |
137 | </Directory> | |
138 | ||
139 | <Location /> | |
140 | Use LDAPConnect | |
7c5e6fe8 | 141 | Require ldap-group cn=cs.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu |
9f66adf4 IB |
142 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>" |
143 | </Location> | |
144 | ||
41cce84a | 145 | <Directory ${webRoot}> |
9f66adf4 IB |
146 | Options Indexes FollowSymLinks MultiViews Includes |
147 | AllowOverride None | |
148 | Require all granted | |
149 | ||
150 | DirectoryIndex app_dev.php | |
151 | ||
152 | <IfModule mod_negotiation.c> | |
153 | Options -MultiViews | |
154 | </IfModule> | |
155 | ||
156 | <IfModule mod_rewrite.c> | |
157 | RewriteEngine On | |
158 | ||
159 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | |
160 | RewriteRule ^(.*) - [E=BASE:%1] | |
161 | ||
162 | # Maintenance script | |
163 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | |
164 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | |
165 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | |
166 | ErrorDocument 503 /maintenance.php | |
167 | ||
168 | # Sets the HTTP_AUTHORIZATION header removed by Apache | |
169 | RewriteCond %{HTTP:Authorization} . | |
170 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
171 | ||
172 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | |
173 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | |
174 | ||
175 | # If the requested filename exists, simply serve it. | |
176 | # We only want to let Apache serve files and not directories. | |
177 | RewriteCond %{REQUEST_FILENAME} -f | |
178 | RewriteRule ^ - [L] | |
179 | ||
180 | # Rewrite all other queries to the front controller. | |
181 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | |
182 | </IfModule> | |
183 | ||
184 | </Directory> | |
185 | '' | |
186 | ]; | |
17f6eae9 | 187 | }; |
f8026b6e IB |
188 | }; |
189 | } |