]>
Commit | Line | Data |
---|---|---|
851ca3c6 | 1 | class role::caldance ( |
a25b5f82 IB |
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, | |
01d9e644 | 15 | Optional[Array] $cron_pip = [], |
851ca3c6 | 16 | ) { |
a25b5f82 | 17 | $password_seed = lookup("base_installation::puppet_pass_seed") |
851ca3c6 IB |
18 | include "base_installation" |
19 | ||
01d9e644 | 20 | include "profile::mail" |
851ca3c6 IB |
21 | include "profile::tools" |
22 | include "profile::postgresql" | |
23 | include "profile::apache" | |
24 | include "profile::redis" | |
d8f933bd | 25 | include "profile::monitoring" |
851ca3c6 | 26 | |
98ee93b9 | 27 | ensure_packages(["python-pip", "python-virtualenv", "python-django", "uwsgi-plugin-python"]) |
b3ac23bb | 28 | |
a25b5f82 | 29 | $caldance_app = "${home}/app" |
d3948290 IB |
30 | $pg_password = generate_password(24, $password_seed, "postgres_caldance") |
31 | $secret_key = generate_password(24, $password_seed, "secret_key_caldance") | |
98ee93b9 | 32 | $socket = "/run/caldance/app.sock" |
d3948290 IB |
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", | |
3f485c9e | 43 | "MEDIA_ROOT" => "$home/media", |
d3948290 IB |
44 | } |
45 | $shell_env = $environment.map |$key, $value| { "$key=$value" } | |
d3948290 IB |
46 | |
47 | file { $home: | |
48 | mode => "0755", | |
49 | } | |
50 | file { "${home}/caldev_django.log": | |
51 | mode => "0664", | |
52 | owner => $user, | |
53 | group => "http", | |
d3948290 | 54 | } |
a25b5f82 IB |
55 | |
56 | file { $caldance_app: | |
57 | ensure => "directory", | |
58 | mode => "0755", | |
59 | owner => $user, | |
60 | group => $group, | |
61 | require => User["$user:"], | |
459e12d0 IB |
62 | } -> |
63 | file { "${home}/media": | |
64 | ensure => "directory", | |
65 | mode => "0755", | |
66 | owner => "http", | |
67 | group => "http", | |
a25b5f82 IB |
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, | |
d3948290 | 93 | environment => concat(["HOME=${home}"], $shell_env), |
f22a16c8 | 94 | command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade", |
a25b5f82 IB |
95 | require => User["$user:"], |
96 | refreshonly => true, | |
97 | } ~> | |
98 | exec { "py-migrate": | |
99 | cwd => $caldance_app, | |
100 | user => $user, | |
d3948290 | 101 | environment => concat(["HOME=${home}"], $shell_env), |
a25b5f82 | 102 | command => "$caldance_app/manage.py migrate", |
d3948290 | 103 | require => [User["$user:"], File["$caldance_app/manage.py"]], |
a25b5f82 IB |
104 | refreshonly => true, |
105 | } ~> | |
106 | exec { "py-static": | |
107 | cwd => $caldance_app, | |
108 | user => $user, | |
d3948290 | 109 | environment => concat(["HOME=${home}"], $shell_env), |
a25b5f82 | 110 | command => "$caldance_app/manage.py collectstatic --no-input", |
d3948290 | 111 | require => [User["$user:"], File["$caldance_app/manage.py"]], |
a25b5f82 IB |
112 | refreshonly => true, |
113 | } ~> | |
98ee93b9 IB |
114 | exec { "restart uwsgi application": |
115 | command => "/usr/bin/systemctl restart caldance-app.service", | |
116 | require => [User["$user:"], File["$caldance_app/app.ini"]], | |
a25b5f82 IB |
117 | refreshonly => true, |
118 | } | |
119 | ||
98ee93b9 | 120 | $uwsgi_path = "${home}/virtualenv/bin/uwsgi" |
a25b5f82 IB |
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 | ||
98ee93b9 IB |
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 | ||
a25b5f82 IB |
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 | ||
b3ac23bb IB |
154 | # pour le script de génération de mdp |
155 | ensure_packages(["perl-digest-sha1"]) | |
156 | ||
a25b5f82 | 157 | ensure_packages(["postgis", "python-gdal", "ripgrep"]) |
b3ac23bb IB |
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 | } | |
a25b5f82 IB |
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': | |
d3948290 IB |
174 | wsgi_python_home => "${home}/virtualenv", |
175 | wsgi_python_path => $caldance_app, | |
a25b5f82 IB |
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': } | |
98ee93b9 IB |
182 | class { 'apache::mod::proxy': } |
183 | apache::mod { 'proxy_uwsgi': } | |
a25b5f82 IB |
184 | |
185 | apache::vhost { $web_host: | |
98ee93b9 IB |
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 => [ | |
a25b5f82 | 204 | { |
d3948290 | 205 | path => "$caldance_app/main_app", |
a25b5f82 IB |
206 | require => "all granted", |
207 | }, | |
208 | { | |
d3948290 | 209 | path => "$caldance_app/www/static", |
a25b5f82 IB |
210 | require => "all granted", |
211 | }, | |
83341b3c IB |
212 | { |
213 | path => "$home/media", | |
214 | require => "all granted", | |
215 | options => ["-Indexes"], | |
216 | }, | |
a25b5f82 IB |
217 | { |
218 | path => "/", | |
219 | provider => "location", | |
220 | require => "valid-user", | |
221 | auth_type => "Basic", | |
222 | auth_name => "Authentification requise", | |
b1072a47 | 223 | auth_user_file => "$home/htpasswd", |
a25b5f82 IB |
224 | }, |
225 | ], | |
98ee93b9 | 226 | aliases => [ |
a25b5f82 IB |
227 | { |
228 | alias => "/static/", | |
d3948290 | 229 | path => "$caldance_app/www/static/", |
a25b5f82 | 230 | }, |
83341b3c IB |
231 | { |
232 | alias => "/media/", | |
233 | path => "$home/media/", | |
234 | }, | |
98ee93b9 IB |
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 | |
a25b5f82 | 249 | } |
01d9e644 IB |
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 | } | |
851ca3c6 | 261 | } |