]>
Commit | Line | Data |
---|---|---|
1 | { lib, pkgs, config, ... }: | |
2 | let | |
3 | secrets = config.myEnv.websites.chloe.new; | |
4 | cfg = config.myServices.websites.chloe.new; | |
5 | ftpRoot = "/var/lib/chloe_new"; | |
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/Chloe"; | |
11 | branch = "test"; | |
12 | in { | |
13 | options.myServices.websites.chloe.new.enable = lib.mkEnableOption "enable Chloe's new website in integration"; | |
14 | ||
15 | config = lib.mkIf cfg.enable { | |
16 | services.phpfpm.pools.chloe_new_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/chloe/new" | |
25 | "/tmp" | |
26 | ]; | |
27 | "php_admin_value[session.save_path]" = sessionDir; | |
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"; | |
34 | }; | |
35 | phpEnv = { | |
36 | SYMFONY_DEBUG_MODE = "\"yes\""; | |
37 | }; | |
38 | phpPackage = pkgs.php72; | |
39 | }; | |
40 | systemd.services."phpfpm-chloe_new_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 "chloe-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,data,miniatures,tmp} | |
60 | ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/ | |
61 | ln -sf ${config.secrets.fullPaths."websites/chloe/new"} app/config/parameters.yml | |
62 | SYMFONY_ENV=dev ./bin/console --env=dev cache:clear --no-warmup | |
63 | sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum | |
64 | ''; | |
65 | in | |
66 | "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/chloe-integration-pre"; | |
67 | postStart = let | |
68 | script = pkgs.writeScriptBin "chloe-integration-post" '' | |
69 | #! ${pkgs.stdenv.shell} | |
70 | ||
71 | cd ${ftpRoot} | |
72 | if [ -d php_old ]; then | |
73 | rm -rf php_old | |
74 | fi | |
75 | ''; | |
76 | in | |
77 | "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/chloe-integration-post"; | |
78 | serviceConfig.TimeoutStartSec="infinity"; | |
79 | }; | |
80 | services.filesWatcher.phpfpm-chloe_new_integration = { | |
81 | restart = true; | |
82 | paths = [ "${packagePath}/${branch}.tar.gz" ]; | |
83 | }; | |
84 | ||
85 | system.activationScripts.chloe_new_integration = { | |
86 | deps = ["users"]; | |
87 | text = '' | |
88 | install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot} ${sessionDir} | |
89 | ''; | |
90 | }; | |
91 | ||
92 | secrets.keys."websites/chloe/new" = { | |
93 | user = config.services.httpd.Inte.user; | |
94 | group = config.services.httpd.Inte.group; | |
95 | permissions = "0400"; | |
96 | text = '' | |
97 | # This file is auto-generated during the composer install | |
98 | parameters: | |
99 | database_host: ${secrets.mysql.host} | |
100 | database_port: ${secrets.mysql.port} | |
101 | database_name: ${secrets.mysql.database} | |
102 | database_user: ${secrets.mysql.user} | |
103 | database_password: ${secrets.mysql.password} | |
104 | database_server_version: ${pkgs.mariadb.mysqlVersion} | |
105 | mailer_transport: smtp | |
106 | mailer_host: 127.0.0.1 | |
107 | mailer_user: null | |
108 | mailer_password: null | |
109 | secret: ${secrets.secret} | |
110 | ldap_host: ldap.immae.eu | |
111 | ldap_port: 636 | |
112 | ldap_version: 3 | |
113 | ldap_ssl: true | |
114 | ldap_tls: false | |
115 | ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu' | |
116 | ldap_base_dn: 'dc=immae,dc=eu' | |
117 | ldap_search_dn: '${secrets.ldap.dn}' | |
118 | ldap_search_password: '${secrets.ldap.password}' | |
119 | ldap_search_filter: '${secrets.ldap.filter}' | |
120 | leapt_im: | |
121 | binary_path: ${pkgs.imagemagick}/bin | |
122 | assetic: | |
123 | sass: ${pkgs.sass}/bin/sass | |
124 | ruby: ${pkgs.ruby}/bin/ruby | |
125 | ''; | |
126 | }; | |
127 | ||
128 | services.websites.env.integration.vhostConfs.chloe_new_integration = { | |
129 | certName = "integration"; | |
130 | addToCerts = true; | |
131 | hosts = [ "new.chc.immae.dev" ]; | |
132 | root = webRoot; | |
133 | extraConfig = [ | |
134 | '' | |
135 | <FilesMatch "\.php$"> | |
136 | SetHandler "proxy:unix:${config.services.phpfpm.pools.chloe_new_integration.socket}|fcgi://localhost" | |
137 | </FilesMatch> | |
138 | ||
139 | <Location /> | |
140 | Use LDAPConnect | |
141 | Require ldap-group cn=chc.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu | |
142 | </Location> | |
143 | ||
144 | <Directory ${webRoot}> | |
145 | Options Indexes FollowSymLinks MultiViews Includes | |
146 | AllowOverride None | |
147 | Require all granted | |
148 | ||
149 | DirectoryIndex app_dev.php | |
150 | ||
151 | <IfModule mod_negotiation.c> | |
152 | Options -MultiViews | |
153 | </IfModule> | |
154 | ||
155 | <IfModule mod_rewrite.c> | |
156 | RewriteEngine On | |
157 | ||
158 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | |
159 | RewriteRule ^(.*) - [E=BASE:%1] | |
160 | ||
161 | # Maintenance script | |
162 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | |
163 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | |
164 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | |
165 | ErrorDocument 503 /maintenance.php | |
166 | ||
167 | # Sets the HTTP_AUTHORIZATION header removed by Apache | |
168 | RewriteCond %{HTTP:Authorization} . | |
169 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
170 | ||
171 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | |
172 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | |
173 | ||
174 | # If the requested filename exists, simply serve it. | |
175 | # We only want to let Apache serve files and not directories. | |
176 | RewriteCond %{REQUEST_FILENAME} -f | |
177 | RewriteRule ^ - [L] | |
178 | ||
179 | # Rewrite all other queries to the front controller. | |
180 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | |
181 | </IfModule> | |
182 | ||
183 | </Directory> | |
184 | '' | |
185 | ]; | |
186 | }; | |
187 | }; | |
188 | } |