diff options
Diffstat (limited to 'modules/private/websites/connexionswing/builder.nix')
-rw-r--r-- | modules/private/websites/connexionswing/builder.nix | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/modules/private/websites/connexionswing/builder.nix b/modules/private/websites/connexionswing/builder.nix new file mode 100644 index 00000000..b4b04cb2 --- /dev/null +++ b/modules/private/websites/connexionswing/builder.nix | |||
@@ -0,0 +1,163 @@ | |||
1 | { apacheUser, apacheGroup, connexionswing, pkgs, phpPackages, config }: | ||
2 | rec { | ||
3 | app = connexionswing.override { inherit (config) environment; }; | ||
4 | keys = [{ | ||
5 | dest = "webapps/${app.environment}-connexionswing"; | ||
6 | user = apacheUser; | ||
7 | group = apacheGroup; | ||
8 | permissions = "0400"; | ||
9 | text = '' | ||
10 | # This file is auto-generated during the composer install | ||
11 | parameters: | ||
12 | database_host: ${config.mysql.host} | ||
13 | database_port: ${config.mysql.port} | ||
14 | database_name: ${config.mysql.name} | ||
15 | database_user: ${config.mysql.user} | ||
16 | database_password: ${config.mysql.password} | ||
17 | database_server_version: ${pkgs.mariadb.mysqlVersion} | ||
18 | mailer_transport: sendmail | ||
19 | mailer_host: null | ||
20 | mailer_user: null | ||
21 | mailer_password: null | ||
22 | subscription_email: ${config.email} | ||
23 | allow_robots: true | ||
24 | secret: ${config.secret} | ||
25 | ${if app.environment == "prod" then '' | ||
26 | services: | ||
27 | swiftmailer.mailer.default.transport: | ||
28 | class: Swift_SendmailTransport | ||
29 | arguments: ['/run/wrappers/bin/sendmail -bs'] | ||
30 | '' else ""} | ||
31 | ''; | ||
32 | }]; | ||
33 | phpFpm = rec { | ||
34 | preStart = '' | ||
35 | if [ ! -f "${app.varDir}/currentWebappDir" -o \ | ||
36 | ! -f "${app.varDir}/currentKey" -o \ | ||
37 | "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \ | ||
38 | || ! sha512sum -c --status ${app.varDir}/currentKey; then | ||
39 | pushd ${app} > /dev/null | ||
40 | /run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup | ||
41 | popd > /dev/null | ||
42 | echo -n "${app}" > ${app.varDir}/currentWebappDir | ||
43 | sha512sum /var/secrets/webapps/${app.environment}-connexionswing > ${app.varDir}/currentKey | ||
44 | fi | ||
45 | ''; | ||
46 | serviceDeps = [ "mysql.service" ]; | ||
47 | socket = "/var/run/phpfpm/connexionswing-${app.environment}.sock"; | ||
48 | phpConfig = '' | ||
49 | extension=${phpPackages.imagick}/lib/php/extensions/imagick.so | ||
50 | ''; | ||
51 | pool = '' | ||
52 | user = ${apacheUser} | ||
53 | group = ${apacheGroup} | ||
54 | listen.owner = ${apacheUser} | ||
55 | listen.group = ${apacheGroup} | ||
56 | php_admin_value[upload_max_filesize] = 20M | ||
57 | php_admin_value[post_max_size] = 20M | ||
58 | ;php_admin_flag[log_errors] = on | ||
59 | php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/var/secrets/webapps/${app.environment}-connexionswing:${app}:${app.varDir}:/tmp" | ||
60 | php_admin_value[session.save_path] = "${app.varDir}/phpSessions" | ||
61 | ${if app.environment == "dev" then '' | ||
62 | pm = ondemand | ||
63 | pm.max_children = 5 | ||
64 | pm.process_idle_timeout = 60 | ||
65 | env[SYMFONY_DEBUG_MODE] = "yes" | ||
66 | '' else '' | ||
67 | pm = dynamic | ||
68 | pm.max_children = 20 | ||
69 | pm.start_servers = 2 | ||
70 | pm.min_spare_servers = 1 | ||
71 | pm.max_spare_servers = 3 | ||
72 | ''}''; | ||
73 | }; | ||
74 | apache = rec { | ||
75 | modules = [ "proxy_fcgi" ]; | ||
76 | webappName = "connexionswing_${app.environment}"; | ||
77 | root = "/run/current-system/webapps/${webappName}"; | ||
78 | vhostConf = '' | ||
79 | <FilesMatch "\.php$"> | ||
80 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | ||
81 | </FilesMatch> | ||
82 | |||
83 | <Directory ${app.varDir}/medias> | ||
84 | Options FollowSymLinks | ||
85 | AllowOverride None | ||
86 | Require all granted | ||
87 | </Directory> | ||
88 | |||
89 | <Directory ${app.varDir}/uploads> | ||
90 | Options FollowSymLinks | ||
91 | AllowOverride None | ||
92 | Require all granted | ||
93 | </Directory> | ||
94 | |||
95 | ${if app.environment == "dev" then '' | ||
96 | <Location /> | ||
97 | Use LDAPConnect | ||
98 | Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu | ||
99 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>" | ||
100 | </Location> | ||
101 | |||
102 | <Directory ${root}> | ||
103 | Options Indexes FollowSymLinks MultiViews Includes | ||
104 | AllowOverride None | ||
105 | Require all granted | ||
106 | |||
107 | DirectoryIndex app_dev.php | ||
108 | |||
109 | <IfModule mod_negotiation.c> | ||
110 | Options -MultiViews | ||
111 | </IfModule> | ||
112 | |||
113 | <IfModule mod_rewrite.c> | ||
114 | RewriteEngine On | ||
115 | |||
116 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | ||
117 | RewriteRule ^(.*) - [E=BASE:%1] | ||
118 | |||
119 | # Maintenance script | ||
120 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | ||
121 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | ||
122 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | ||
123 | ErrorDocument 503 /maintenance.php | ||
124 | |||
125 | # Sets the HTTP_AUTHORIZATION header removed by Apache | ||
126 | RewriteCond %{HTTP:Authorization} . | ||
127 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | ||
128 | |||
129 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | ||
130 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | ||
131 | |||
132 | # If the requested filename exists, simply serve it. | ||
133 | # We only want to let Apache serve files and not directories. | ||
134 | RewriteCond %{REQUEST_FILENAME} -f | ||
135 | RewriteRule ^ - [L] | ||
136 | |||
137 | # Rewrite all other queries to the front controller. | ||
138 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | ||
139 | </IfModule> | ||
140 | |||
141 | </Directory> | ||
142 | '' else '' | ||
143 | Use Stats connexionswing.com | ||
144 | |||
145 | <Directory ${root}> | ||
146 | Options Indexes FollowSymLinks MultiViews Includes | ||
147 | AllowOverride All | ||
148 | Require all granted | ||
149 | </Directory> | ||
150 | ''} | ||
151 | ''; | ||
152 | }; | ||
153 | activationScript = { | ||
154 | deps = [ "wrappers" ]; | ||
155 | text = '' | ||
156 | install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir} \ | ||
157 | ${app.varDir}/medias \ | ||
158 | ${app.varDir}/uploads \ | ||
159 | ${app.varDir}/var | ||
160 | install -m 0750 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/phpSessions | ||
161 | ''; | ||
162 | }; | ||
163 | } | ||