diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-04-23 01:12:02 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-04-23 01:41:27 +0200 |
commit | 76fd3abc7e4ba2f478f7e3d823b3ab8c8946b97c (patch) | |
tree | b7082f4f6e87438d3296d37bc52d3a1b5c6f9ccf /modules | |
parent | 441b866a095bd177a8faa541ea7ef605ba369fe9 (diff) | |
download | Puppet-76fd3abc7e4ba2f478f7e3d823b3ab8c8946b97c.tar.gz Puppet-76fd3abc7e4ba2f478f7e3d823b3ab8c8946b97c.tar.zst Puppet-76fd3abc7e4ba2f478f7e3d823b3ab8c8946b97c.zip |
Fix caldance app deployment
Diffstat (limited to 'modules')
-rw-r--r-- | modules/role/manifests/caldance.pp | 83 | ||||
-rw-r--r-- | modules/role/templates/caldance/app.ini.erb | 3 | ||||
-rw-r--r-- | modules/role/templates/caldance/manage.py.erb | 9 |
3 files changed, 66 insertions, 29 deletions
diff --git a/modules/role/manifests/caldance.pp b/modules/role/manifests/caldance.pp index df02b07..374b251 100644 --- a/modules/role/manifests/caldance.pp +++ b/modules/role/manifests/caldance.pp | |||
@@ -27,10 +27,15 @@ class role::caldance ( | |||
27 | ensure_packages(["python-pip", "python-virtualenv", "python-django", "uwsgi-plugin-python"]) | 27 | ensure_packages(["python-pip", "python-virtualenv", "python-django", "uwsgi-plugin-python"]) |
28 | 28 | ||
29 | $caldance_app = "${home}/app" | 29 | $caldance_app = "${home}/app" |
30 | $caldance_app_old = "${home}/app_old" | ||
31 | $caldance_app_tmp = "${home}/app_tmp" | ||
30 | $pg_password = generate_password(24, $password_seed, "postgres_caldance") | 32 | $pg_password = generate_password(24, $password_seed, "postgres_caldance") |
31 | $secret_key = generate_password(24, $password_seed, "secret_key_caldance") | 33 | $secret_key = generate_password(24, $password_seed, "secret_key_caldance") |
32 | $socket = "/run/caldance/app.sock" | 34 | $socket = "/run/caldance/app.sock" |
33 | 35 | ||
36 | $uwsgi_path = "${home}/virtualenv/bin/uwsgi" | ||
37 | $python_path = "${home}/virtualenv/bin/python" | ||
38 | |||
34 | $environment = { | 39 | $environment = { |
35 | "DB_NAME" => $pg_db, | 40 | "DB_NAME" => $pg_db, |
36 | "DB_USER" => $pg_user, | 41 | "DB_USER" => $pg_user, |
@@ -39,19 +44,21 @@ class role::caldance ( | |||
39 | "DB_PORT" => $pg_port, | 44 | "DB_PORT" => $pg_port, |
40 | "SECRET_KEY" => $secret_key, | 45 | "SECRET_KEY" => $secret_key, |
41 | "DEBUG" => "False", | 46 | "DEBUG" => "False", |
42 | "LOG_FILE" => "$home/caldev_django.log", | 47 | "LOG_FILE" => "$home/caldance.log", |
43 | "MEDIA_ROOT" => "$home/media", | 48 | "MEDIA_ROOT" => "$home/media", |
44 | } | 49 | } |
45 | 50 | ||
46 | file { $home: | 51 | file { $home: |
47 | mode => "0755", | 52 | mode => "0755", |
48 | } | 53 | } |
49 | file { "${home}/caldev_django.log": | 54 | |
50 | mode => "0664", | 55 | file { $caldance_app_tmp: |
56 | ensure => "directory", | ||
57 | mode => "0755", | ||
51 | owner => $user, | 58 | owner => $user, |
52 | group => "http", | 59 | group => $group, |
60 | require => User["$user:"], | ||
53 | } | 61 | } |
54 | |||
55 | file { $caldance_app: | 62 | file { $caldance_app: |
56 | ensure => "directory", | 63 | ensure => "directory", |
57 | mode => "0755", | 64 | mode => "0755", |
@@ -83,41 +90,40 @@ class role::caldance ( | |||
83 | user => $user, | 90 | user => $user, |
84 | username => lookup("base_installation::ldap_cn"), | 91 | username => lookup("base_installation::ldap_cn"), |
85 | password => generate_password(24, $password_seed, "ldap"), | 92 | password => generate_password(24, $password_seed, "ldap"), |
86 | extract_path => $caldance_app, | 93 | extract_path => $caldance_app_tmp, |
87 | require => [User["$user:"], File[$caldance_app]], | 94 | require => [User["$user:"], File[$caldance_app_tmp]], |
88 | } ~> | 95 | } ~> |
89 | exec { "py-requirements": | 96 | exec { "py-requirements": |
90 | cwd => $caldance_app, | 97 | cwd => $caldance_app_tmp, |
91 | user => $user, | 98 | user => $user, |
92 | environment => ["HOME=${home}"], | 99 | environment => ["HOME=${home}"], |
93 | command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade", | 100 | command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade", |
94 | require => User["$user:"], | 101 | require => User["$user:"], |
95 | refreshonly => true, | 102 | refreshonly => true, |
96 | } ~> | 103 | } ~> |
97 | exec { "py-migrate": | 104 | exec { "stop uwsgi application": |
98 | cwd => $caldance_app, | 105 | command => "/usr/bin/systemctl stop caldance-app.service || /usr/bin/true", |
99 | user => $user, | 106 | require => [User["$user:"]], |
100 | environment => ["HOME=${home}"], | ||
101 | command => "$caldance_app/manage migrate", | ||
102 | require => [User["$user:"], File["$caldance_app/manage"]], | ||
103 | refreshonly => true, | 107 | refreshonly => true, |
104 | } ~> | 108 | } ~> |
105 | exec { "py-static": | 109 | exec { "mv app_tmp": |
106 | cwd => $caldance_app, | 110 | cwd => $home, |
107 | user => $user, | 111 | user => $user, |
108 | environment => ["HOME=${home}"], | 112 | environment => ["HOME=${home}"], |
109 | command => "$caldance_app/manage collectstatic --no-input", | 113 | command => "/usr/bin/rm -rf $caldance_app_old && /usr/bin/mv $caldance_app $caldance_app_old && /usr/bin/mv $caldance_app_tmp $caldance_app && /usr/bin/mkdir $caldance_app_tmp", |
110 | require => [User["$user:"], File["$caldance_app/manage"]], | 114 | require => [User["$user:"]], |
111 | refreshonly => true, | 115 | refreshonly => true, |
112 | } ~> | 116 | } ~> |
113 | exec { "restart uwsgi application": | 117 | file { "$caldance_app/manage.py": |
114 | command => "/usr/bin/systemctl restart caldance-app.service", | 118 | owner => $user, |
115 | require => [User["$user:"], File["$caldance_app/app.ini"]], | 119 | group => $group, |
116 | refreshonly => true, | 120 | mode => "0755", |
117 | } | 121 | content => template("role/caldance/manage.py.erb"), |
118 | 122 | require => [ | |
119 | $uwsgi_path = "${home}/virtualenv/bin/uwsgi" | 123 | User["$user:"], |
120 | $python_path = "${home}/virtualenv/bin/python" | 124 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], |
125 | ], | ||
126 | } ~> | ||
121 | file { "$caldance_app/manage": | 127 | file { "$caldance_app/manage": |
122 | owner => $user, | 128 | owner => $user, |
123 | group => $group, | 129 | group => $group, |
@@ -125,10 +131,10 @@ class role::caldance ( | |||
125 | content => template("role/caldance/manage.sh.erb"), | 131 | content => template("role/caldance/manage.sh.erb"), |
126 | require => [ | 132 | require => [ |
127 | User["$user:"], | 133 | User["$user:"], |
134 | File["$caldance_app/manage.py"], | ||
128 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], | 135 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], |
129 | ], | 136 | ], |
130 | } | 137 | } ~> |
131 | |||
132 | file { "$caldance_app/app.ini": | 138 | file { "$caldance_app/app.ini": |
133 | owner => $user, | 139 | owner => $user, |
134 | group => $group, | 140 | group => $group, |
@@ -138,6 +144,27 @@ class role::caldance ( | |||
138 | User["$user:"], | 144 | User["$user:"], |
139 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], | 145 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], |
140 | ], | 146 | ], |
147 | } ~> | ||
148 | exec { "py-migrate": | ||
149 | cwd => $caldance_app, | ||
150 | user => $user, | ||
151 | environment => ["HOME=${home}"], | ||
152 | command => "$caldance_app/manage migrate", | ||
153 | require => [User["$user:"], File["$caldance_app/manage"]], | ||
154 | refreshonly => true, | ||
155 | } ~> | ||
156 | exec { "py-static": | ||
157 | cwd => $caldance_app, | ||
158 | user => $user, | ||
159 | environment => ["HOME=${home}"], | ||
160 | command => "$caldance_app/manage collectstatic --no-input", | ||
161 | require => [User["$user:"], File["$caldance_app/manage"]], | ||
162 | refreshonly => true, | ||
163 | } ~> | ||
164 | exec { "restart uwsgi application": | ||
165 | command => "/usr/bin/systemctl restart caldance-app.service", | ||
166 | require => [User["$user:"], File["$caldance_app/app.ini"]], | ||
167 | refreshonly => true, | ||
141 | } | 168 | } |
142 | 169 | ||
143 | profile::postgresql::master { "postgresql master for caldance": | 170 | profile::postgresql::master { "postgresql master for caldance": |
diff --git a/modules/role/templates/caldance/app.ini.erb b/modules/role/templates/caldance/app.ini.erb index df6fcb9..f7d70ed 100644 --- a/modules/role/templates/caldance/app.ini.erb +++ b/modules/role/templates/caldance/app.ini.erb | |||
@@ -4,7 +4,8 @@ wsgi-file = main_app/wsgi.py | |||
4 | 4 | ||
5 | master = true | 5 | master = true |
6 | processes = 10 | 6 | processes = 10 |
7 | gevent = 1000 | 7 | #This produces failure loops |
8 | #gevent = 1000 | ||
8 | http-websockets = true | 9 | http-websockets = true |
9 | 10 | ||
10 | socket = <%= @socket %> | 11 | socket = <%= @socket %> |
diff --git a/modules/role/templates/caldance/manage.py.erb b/modules/role/templates/caldance/manage.py.erb new file mode 100644 index 0000000..03cc97a --- /dev/null +++ b/modules/role/templates/caldance/manage.py.erb | |||
@@ -0,0 +1,9 @@ | |||
1 | #!<%= @home %>/virtualenv/bin/python -O | ||
2 | import os | ||
3 | import sys | ||
4 | |||
5 | if __name__ == "__main__": | ||
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main_app.settings") | ||
7 | |||
8 | from django.core.management import execute_from_command_line | ||
9 | execute_from_command_line(sys.argv) | ||