]>
Commit | Line | Data |
---|---|---|
1 | class role::caldance ( | |
2 | String $user, | |
3 | String $group, | |
4 | String $home, | |
5 | String $web_host, | |
6 | String $pg_user, | |
7 | String $pg_db, | |
8 | String $mail_from, | |
9 | String $smtp_host, | |
10 | String $smtp_port, | |
11 | Optional[String] $pg_hostname = "/run/postgresql", | |
12 | Optional[String] $pg_port = "5432", | |
13 | Optional[String] $caldance_version = undef, | |
14 | Optional[String] $caldance_sha256 = undef, | |
15 | Optional[Array] $cron_pip = [], | |
16 | ) { | |
17 | $password_seed = lookup("base_installation::puppet_pass_seed") | |
18 | include "base_installation" | |
19 | ||
20 | include "profile::mail" | |
21 | include "profile::tools" | |
22 | include "profile::postgresql" | |
23 | include "profile::apache" | |
24 | include "profile::redis" | |
25 | include "profile::monitoring" | |
26 | ||
27 | ensure_packages(["python-pip", "python-virtualenv", "python-django", "uwsgi-plugin-python"]) | |
28 | ||
29 | $caldance_app = "${home}/app" | |
30 | $pg_password = generate_password(24, $password_seed, "postgres_caldance") | |
31 | $secret_key = generate_password(24, $password_seed, "secret_key_caldance") | |
32 | $socket = "/run/caldance/app.sock" | |
33 | ||
34 | $environment = { | |
35 | "DB_NAME" => $pg_db, | |
36 | "DB_USER" => $pg_user, | |
37 | "DB_PASSWORD" => $pg_password, | |
38 | "DB_HOST" => $pg_hostname, | |
39 | "DB_PORT" => $pg_port, | |
40 | "SECRET_KEY" => $secret_key, | |
41 | "DEBUG" => "False", | |
42 | "LOG_FILE" => "$home/caldev_django.log", | |
43 | "MEDIA_ROOT" => "$home/media", | |
44 | } | |
45 | $shell_env = $environment.map |$key, $value| { "$key=$value" } | |
46 | ||
47 | file { $home: | |
48 | mode => "0755", | |
49 | } | |
50 | file { "${home}/caldev_django.log": | |
51 | mode => "0664", | |
52 | owner => $user, | |
53 | group => "http", | |
54 | } | |
55 | ||
56 | file { $caldance_app: | |
57 | ensure => "directory", | |
58 | mode => "0755", | |
59 | owner => $user, | |
60 | group => $group, | |
61 | require => User["$user:"], | |
62 | } -> | |
63 | file { "${home}/media": | |
64 | ensure => "directory", | |
65 | mode => "0755", | |
66 | owner => "http", | |
67 | group => "http", | |
68 | } | |
69 | ||
70 | exec { "initialize_venv": | |
71 | user => $user, | |
72 | require => User["$user:"], | |
73 | command => "/usr/bin/virtualenv ${home}/virtualenv", | |
74 | creates => "${home}/virtualenv", | |
75 | } | |
76 | -> | |
77 | archive { "${home}/caldance_${caldance_version}.tar.gz": | |
78 | path => "${home}/caldance_${caldance_version}.tar.gz", | |
79 | source => "https://release.immae.eu/caldance/caldance_${caldance_version}.tar.gz", | |
80 | checksum_type => "sha256", | |
81 | checksum => $caldance_sha256, | |
82 | cleanup => false, | |
83 | extract => true, | |
84 | user => $user, | |
85 | username => lookup("base_installation::ldap_cn"), | |
86 | password => generate_password(24, $password_seed, "ldap"), | |
87 | extract_path => $caldance_app, | |
88 | require => [User["$user:"], File[$caldance_app]], | |
89 | } ~> | |
90 | exec { "py-requirements": | |
91 | cwd => $caldance_app, | |
92 | user => $user, | |
93 | environment => concat(["HOME=${home}"], $shell_env), | |
94 | command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade", | |
95 | require => User["$user:"], | |
96 | refreshonly => true, | |
97 | } ~> | |
98 | exec { "py-migrate": | |
99 | cwd => $caldance_app, | |
100 | user => $user, | |
101 | environment => concat(["HOME=${home}"], $shell_env), | |
102 | command => "$caldance_app/manage.py migrate", | |
103 | require => [User["$user:"], File["$caldance_app/manage.py"]], | |
104 | refreshonly => true, | |
105 | } ~> | |
106 | exec { "py-static": | |
107 | cwd => $caldance_app, | |
108 | user => $user, | |
109 | environment => concat(["HOME=${home}"], $shell_env), | |
110 | command => "$caldance_app/manage.py collectstatic --no-input", | |
111 | require => [User["$user:"], File["$caldance_app/manage.py"]], | |
112 | refreshonly => true, | |
113 | } ~> | |
114 | exec { "restart uwsgi application": | |
115 | command => "/usr/bin/systemctl restart caldance-app.service", | |
116 | require => [User["$user:"], File["$caldance_app/app.ini"]], | |
117 | refreshonly => true, | |
118 | } | |
119 | ||
120 | $uwsgi_path = "${home}/virtualenv/bin/uwsgi" | |
121 | $python_path = "${home}/virtualenv/bin/python" | |
122 | file { "$caldance_app/manage.py": | |
123 | owner => $user, | |
124 | group => $group, | |
125 | mode => "0755", | |
126 | content => template("role/caldance/manage.py.erb"), | |
127 | require => [ | |
128 | User["$user:"], | |
129 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], | |
130 | ], | |
131 | } | |
132 | ||
133 | file { "$caldance_app/app.ini": | |
134 | owner => $user, | |
135 | group => $group, | |
136 | mode => "0644", | |
137 | content => template("role/caldance/app.ini.erb"), | |
138 | require => [ | |
139 | User["$user:"], | |
140 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], | |
141 | ], | |
142 | } | |
143 | ||
144 | profile::postgresql::master { "postgresql master for caldance": | |
145 | letsencrypt_host => $web_host, | |
146 | backup_hosts => ["backup-1"], | |
147 | } | |
148 | ||
149 | postgresql::server::db { $pg_db: | |
150 | user => $pg_user, | |
151 | password => postgresql_password($pg_user, $pg_password), | |
152 | } | |
153 | ||
154 | # pour le script de génération de mdp | |
155 | ensure_packages(["perl-digest-sha1"]) | |
156 | ||
157 | ensure_packages(["postgis", "python-gdal", "ripgrep"]) | |
158 | file { "/usr/local/bin/ldap_ssha": | |
159 | owner => "root", | |
160 | group => "root", | |
161 | mode => "0755", | |
162 | source => "puppet:///modules/base_installation/scripts/ldap_ssha", | |
163 | require => Package["perl-digest-sha1"], | |
164 | } | |
165 | ||
166 | sudo::conf { 'wheel_nopasswd': | |
167 | priority => 99, | |
168 | content => "%wheel ALL=(ALL) NOPASSWD: ALL", | |
169 | require => Package["sudo"], | |
170 | } | |
171 | ||
172 | ensure_packages(["mod_wsgi"]) | |
173 | class { 'apache::mod::wsgi': | |
174 | wsgi_python_home => "${home}/virtualenv", | |
175 | wsgi_python_path => $caldance_app, | |
176 | require => Package["mod_wsgi"], | |
177 | } | |
178 | class { 'apache::mod::authn_file': } | |
179 | class { 'apache::mod::authn_core': } | |
180 | class { 'apache::mod::authz_user': } | |
181 | class { 'apache::mod::auth_basic': } | |
182 | class { 'apache::mod::proxy': } | |
183 | apache::mod { 'proxy_uwsgi': } | |
184 | ||
185 | apache::vhost { $web_host: | |
186 | port => '443', | |
187 | docroot => false, | |
188 | manage_docroot => false, | |
189 | ssl => true, | |
190 | ssl_cert => "/etc/letsencrypt/live/$web_host/cert.pem", | |
191 | ssl_key => "/etc/letsencrypt/live/$web_host/privkey.pem", | |
192 | ssl_chain => "/etc/letsencrypt/live/$web_host/chain.pem", | |
193 | require => Letsencrypt::Certonly[$web_host], | |
194 | proxy_preserve_host => true, | |
195 | proxy_pass => [ | |
196 | { | |
197 | path => "/", | |
198 | url => "unix:$socket|uwsgi://caldance-app", | |
199 | reverse_urls => [], | |
200 | no_proxy_uris => [ "/media/", "/static/" ], | |
201 | } | |
202 | ], | |
203 | directories => [ | |
204 | { | |
205 | path => "$caldance_app/main_app", | |
206 | require => "all granted", | |
207 | }, | |
208 | { | |
209 | path => "$caldance_app/www/static", | |
210 | require => "all granted", | |
211 | }, | |
212 | { | |
213 | path => "$home/media", | |
214 | require => "all granted", | |
215 | options => ["-Indexes"], | |
216 | }, | |
217 | { | |
218 | path => "/", | |
219 | provider => "location", | |
220 | require => "valid-user", | |
221 | auth_type => "Basic", | |
222 | auth_name => "Authentification requise", | |
223 | auth_user_file => "$home/htpasswd", | |
224 | }, | |
225 | ], | |
226 | aliases => [ | |
227 | { | |
228 | alias => "/static/", | |
229 | path => "$caldance_app/www/static/", | |
230 | }, | |
231 | { | |
232 | alias => "/media/", | |
233 | path => "$home/media/", | |
234 | }, | |
235 | ]; | |
236 | default: * => $::profile::apache::apache_vhost_default; | |
237 | } | |
238 | ||
239 | file { "/etc/systemd/system/caldance-app.service": | |
240 | mode => "0644", | |
241 | owner => "root", | |
242 | group => "root", | |
243 | content => template("role/caldance/caldance-app.service.erb"), | |
244 | require => File["$caldance_app/app.ini"], | |
245 | } -> | |
246 | service { "caldance-app": | |
247 | ensure => "running", | |
248 | enable => true | |
249 | } | |
250 | ||
251 | $mailtos = join($cron_pip, ",") | |
252 | cron::job { "list_outdated_pip_packages": | |
253 | ensure => present, | |
254 | user => $user, | |
255 | environment => concat(["HOME=${home}","MAILTO=${mailtos}"], $shell_env), | |
256 | command => "${home}/virtualenv/bin/pip list --outdated", | |
257 | minute => "15", | |
258 | hour => "0", | |
259 | require => Exec["initialize_venv"], | |
260 | } | |
261 | } |