]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Fix caldance app deployment
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 22 Apr 2020 23:12:02 +0000 (01:12 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 22 Apr 2020 23:41:27 +0000 (01:41 +0200)
modules/role/manifests/caldance.pp
modules/role/templates/caldance/app.ini.erb
modules/role/templates/caldance/manage.py.erb [new file with mode: 0644]

index df02b078e3f785ce595129411cf4abd6c690186e..374b251e0e68f1cfd567178060236f3ed92752f3 100644 (file)
@@ -27,10 +27,15 @@ class role::caldance (
   ensure_packages(["python-pip", "python-virtualenv", "python-django", "uwsgi-plugin-python"])
 
   $caldance_app = "${home}/app"
+  $caldance_app_old = "${home}/app_old"
+  $caldance_app_tmp = "${home}/app_tmp"
   $pg_password = generate_password(24, $password_seed, "postgres_caldance")
   $secret_key = generate_password(24, $password_seed, "secret_key_caldance")
   $socket = "/run/caldance/app.sock"
 
+  $uwsgi_path = "${home}/virtualenv/bin/uwsgi"
+  $python_path = "${home}/virtualenv/bin/python"
+
   $environment = {
     "DB_NAME"     => $pg_db,
     "DB_USER"     => $pg_user,
@@ -39,19 +44,21 @@ class role::caldance (
     "DB_PORT"     => $pg_port,
     "SECRET_KEY"  => $secret_key,
     "DEBUG"       => "False",
-    "LOG_FILE"    => "$home/caldev_django.log",
+    "LOG_FILE"    => "$home/caldance.log",
     "MEDIA_ROOT"  => "$home/media",
   }
 
   file { $home:
     mode => "0755",
   }
-  file { "${home}/caldev_django.log":
-    mode    => "0664",
+
+  file { $caldance_app_tmp:
+    ensure  => "directory",
+    mode    => "0755",
     owner   => $user,
-    group   => "http",
+    group   => $group,
+    require => User["$user:"],
   }
-
   file { $caldance_app:
     ensure  => "directory",
     mode    => "0755",
@@ -83,41 +90,40 @@ class role::caldance (
     user          => $user,
     username      => lookup("base_installation::ldap_cn"),
     password      => generate_password(24, $password_seed, "ldap"),
-    extract_path  => $caldance_app,
-    require       => [User["$user:"], File[$caldance_app]],
+    extract_path  => $caldance_app_tmp,
+    require       => [User["$user:"], File[$caldance_app_tmp]],
   } ~>
   exec { "py-requirements":
-    cwd         => $caldance_app,
+    cwd         => $caldance_app_tmp,
     user        => $user,
     environment => ["HOME=${home}"],
     command     => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade",
     require     => User["$user:"],
     refreshonly => true,
   } ~>
-  exec { "py-migrate":
-    cwd         => $caldance_app,
-    user        => $user,
-    environment => ["HOME=${home}"],
-    command     => "$caldance_app/manage migrate",
-    require     => [User["$user:"], File["$caldance_app/manage"]],
+  exec { "stop uwsgi application":
+    command     => "/usr/bin/systemctl stop caldance-app.service || /usr/bin/true",
+    require     => [User["$user:"]],
     refreshonly => true,
   } ~>
-  exec { "py-static":
-    cwd         => $caldance_app,
+  exec { "mv app_tmp":
+    cwd         => $home,
     user        => $user,
     environment => ["HOME=${home}"],
-    command     => "$caldance_app/manage collectstatic --no-input",
-    require     => [User["$user:"], File["$caldance_app/manage"]],
+    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",
+    require     => [User["$user:"]],
     refreshonly => true,
   } ~>
-  exec { "restart uwsgi application":
-    command     => "/usr/bin/systemctl restart caldance-app.service",
-    require     => [User["$user:"], File["$caldance_app/app.ini"]],
-    refreshonly => true,
-  }
-
-  $uwsgi_path = "${home}/virtualenv/bin/uwsgi"
-  $python_path = "${home}/virtualenv/bin/python"
+  file { "$caldance_app/manage.py":
+    owner   => $user,
+    group   => $group,
+    mode    => "0755",
+    content => template("role/caldance/manage.py.erb"),
+    require => [
+      User["$user:"],
+      Archive[ "${home}/caldance_${caldance_version}.tar.gz"],
+    ],
+  } ~>
   file { "$caldance_app/manage":
     owner   => $user,
     group   => $group,
@@ -125,10 +131,10 @@ class role::caldance (
     content => template("role/caldance/manage.sh.erb"),
     require => [
       User["$user:"],
+      File["$caldance_app/manage.py"],
       Archive[ "${home}/caldance_${caldance_version}.tar.gz"],
     ],
-  }
-
+  } ~>
   file { "$caldance_app/app.ini":
     owner   => $user,
     group   => $group,
@@ -138,6 +144,27 @@ class role::caldance (
       User["$user:"],
       Archive[ "${home}/caldance_${caldance_version}.tar.gz"],
     ],
+  } ~>
+  exec { "py-migrate":
+    cwd         => $caldance_app,
+    user        => $user,
+    environment => ["HOME=${home}"],
+    command     => "$caldance_app/manage migrate",
+    require     => [User["$user:"], File["$caldance_app/manage"]],
+    refreshonly => true,
+  } ~>
+  exec { "py-static":
+    cwd         => $caldance_app,
+    user        => $user,
+    environment => ["HOME=${home}"],
+    command     => "$caldance_app/manage collectstatic --no-input",
+    require     => [User["$user:"], File["$caldance_app/manage"]],
+    refreshonly => true,
+  } ~>
+  exec { "restart uwsgi application":
+    command     => "/usr/bin/systemctl restart caldance-app.service",
+    require     => [User["$user:"], File["$caldance_app/app.ini"]],
+    refreshonly => true,
   }
 
   profile::postgresql::master { "postgresql master for caldance":
index df6fcb905f8283f17f3e9ecac54e66e9feaf8e12..f7d70ed68f244db691d0e8a15a286e82808f07d4 100644 (file)
@@ -4,7 +4,8 @@ wsgi-file = main_app/wsgi.py
 
 master = true
 processes = 10
-gevent = 1000
+#This produces failure loops
+#gevent = 1000
 http-websockets = true
 
 socket = <%= @socket %>
diff --git a/modules/role/templates/caldance/manage.py.erb b/modules/role/templates/caldance/manage.py.erb
new file mode 100644 (file)
index 0000000..03cc97a
--- /dev/null
@@ -0,0 +1,9 @@
+#!<%= @home %>/virtualenv/bin/python -O
+import os
+import sys
+
+if __name__ == "__main__":
+        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main_app.settings")
+
+        from django.core.management import execute_from_command_line
+        execute_from_command_line(sys.argv)