]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/isabelle/aten_integration.nix
Rework webhooks
[perso/Immae/Config/Nix.git] / modules / private / websites / isabelle / aten_integration.nix
CommitLineData
ab8f306d 1{ lib, pkgs, config, ... }:
f8026b6e 2let
829ef7f1 3 secrets = config.myEnv.websites.isabelle.aten_integration;
829ef7f1 4 cfg = config.myServices.websites.isabelle.aten_integration;
2ff9258e
IB
5 ftpRoot = "/var/lib/isabelle_aten_integration";
6 phpRoot = "${ftpRoot}/php";
7 webRoot = "${phpRoot}/public";
8 varDir = "${ftpRoot}/var";
9 sessionDir = "${ftpRoot}/sessions";
10 packagePath = "/var/lib/ftp/release.immae.eu/buildbot/IsabelleAten";
11 branch = "test";
f8026b6e 12in {
829ef7f1 13 options.myServices.websites.isabelle.aten_integration.enable = lib.mkEnableOption "enable Aten's website in integration";
f8026b6e
IB
14
15 config = lib.mkIf cfg.enable {
2ff9258e
IB
16 services.phpfpm.pools.isabelle_aten_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/isabelle/aten_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";
34 };
35 phpEnv = {
d3452fc5 36 SYMFONY_DEBUG_MODE = "\"yes\"";
5400b9b6 37 };
dcac3ec7 38 phpPackage = pkgs.php72;
2e48907d 39 };
2ff9258e
IB
40 systemd.services."phpfpm-isabelle_aten_integration" = {
41 after = lib.mkAfter ["postgresql.service"];
42 wants = ["postgresql.service"];
43 path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ];
44 preStart = let
45 script = pkgs.writeScriptBin "isabelle-aten-integration" ''
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/{log,cache}
60 ln -sf ${varDir}/{log,cache} var/
61 SYMFONY_ENV=dev APP_ENV=dev ./bin/console --env=dev cache:clear --no-warmup
62 sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum
63 '';
64 in
65 "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/isabelle-aten-integration";
66 postStart = let
67 script = pkgs.writeScriptBin "isabelle-aten-integration-post" ''
68 #! ${pkgs.stdenv.shell}
69
70 cd ${ftpRoot}
71 if [ -d php_old ]; then
72 rm -rf php_old
73 fi
74 '';
75 in
76 "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/isabelle-aten-integration-post";
77 serviceConfig.TimeoutStartSec="infinity";
78 };
79 services.filesWatcher.phpfpm-isabelle_aten_integration = {
80 restart = true;
81 paths = [ "${packagePath}/${branch}.tar.gz" ];
82 };
83
84 system.activationScripts.isabelle_aten_integration = {
85 deps = ["users"];
86 text = ''
87 install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot} ${sessionDir}
88 '';
89 };
2e48907d 90
4c4652aa 91 secrets.keys."websites/isabelle/aten_integration" = {
717ccfd9 92 user = config.services.httpd.Inte.user;
9f66adf4 93 group = config.services.httpd.Inte.group;
717ccfd9 94 permissions = "0400";
ab8f306d
IB
95 text = let
96 # cf:
97 # https://secure.php.net/manual/fr/function.parse-url.php
98 # vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php#parseDatabaseUrlQuery
99 psql_url = with secrets.postgresql; "pdo-pgsql://${user}:${password}@invalid:${port}/${database}?host=${socket}";
100 in ''
2ff9258e 101 SetEnv APP_ENV "${secrets.environment}"
717ccfd9 102 SetEnv APP_SECRET "${secrets.secret}"
ab8f306d 103 SetEnv DATABASE_URL "${psql_url}"
717ccfd9 104 '';
4c4652aa 105 };
d3452fc5 106 services.websites.env.integration.vhostConfs.isabelle_aten_integration = {
0f71cd76 107 certName = "integration";
f8026b6e 108 addToCerts = true;
7c5e6fe8 109 hosts = [ "aten.ic.immae.dev" ];
41cce84a 110 root = webRoot;
717ccfd9
IB
111 extraConfig = [
112 ''
113 <FilesMatch "\.php$">
2ff9258e 114 SetHandler "proxy:unix:${config.services.phpfpm.pools.isabelle_aten_integration.socket}|fcgi://localhost"
717ccfd9
IB
115 </FilesMatch>
116
d3452fc5 117 Include ${config.secrets.fullPaths."websites/isabelle/aten_integration"}
717ccfd9
IB
118
119 <Location />
120 Use LDAPConnect
7c5e6fe8 121 Require ldap-group cn=ic.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu
717ccfd9
IB
122 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
123 </Location>
124
125 <Location /backend>
126 Use LDAPConnect
7c5e6fe8 127 Require ldap-group cn=ic.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu
717ccfd9
IB
128 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
129 </Location>
130
41cce84a 131 <Directory ${webRoot}>
717ccfd9
IB
132 Options Indexes FollowSymLinks MultiViews Includes
133 AllowOverride All
134 Require all granted
135 DirectoryIndex index.php
136 FallbackResource /index.php
137 </Directory>
138 ''
139 ];
f8026b6e
IB
140 };
141 };
142}