From e7913740adb4a2a2bf72161c62abb997d2701d02 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Fri, 10 May 2019 12:27:03 +0200
Subject: [PATCH] Collect static files and apply migrations

---
 molecule/default/tests/test_default.py | 14 ++++++++++++++
 tasks/funkwhale.yml                    | 20 ++++++++++++++++++++
 tasks/main.yml                         |  6 +++---
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py
index c47ed8e..613d975 100644
--- a/molecule/default/tests/test_default.py
+++ b/molecule/default/tests/test_default.py
@@ -105,3 +105,17 @@ def test_virtualenv(host):
 
     intersection = expected_packages & names
     assert intersection == expected_packages
+
+
+def test_static_files_copied(host):
+    f = host.file("/srv/funkwhale/data/static/admin/css/base.css")
+
+    assert f.exists is True
+
+
+def test_migrations_applied(host):
+    cmd = """
+        sudo -u postgres psql funkwhale -A -t -c "SELECT 1 from django_migrations where app = 'music' and name = '0039_auto_20190423_0820';"
+    """
+    result = host.run(cmd)
+    assert result.stdout == "1"
diff --git a/tasks/funkwhale.yml b/tasks/funkwhale.yml
index 1090306..0e0ea95 100644
--- a/tasks/funkwhale.yml
+++ b/tasks/funkwhale.yml
@@ -74,6 +74,8 @@
     remote_src: true
 
 - name: "Setup virtualenv"
+  become: true
+  become_user: "{{ funkwhale_username }}"
   pip:
     name: wheel
     virtualenv: "{{ funkwhale_install_path }}/virtualenv"
@@ -81,7 +83,25 @@
 
 
 - name: "Install python dependencies"
+  become: true
+  become_user: "{{ funkwhale_username }}"
   pip:
     requirements: "{{ funkwhale_install_path }}/api/requirements.txt"
     virtualenv: "{{ funkwhale_install_path }}/virtualenv"
     virtualenv_python: python3
+
+
+- name: "Collect static files"
+  command: "{{ funkwhale_install_path }}/virtualenv/bin/python api/manage.py collectstatic --no-input"
+  become: true
+  become_user: "{{ funkwhale_username }}"
+  args:
+    chdir: "{{ funkwhale_install_path }}"
+
+
+- name: "Apply database migrations"
+  become: true
+  become_user: "{{ funkwhale_username }}"
+  command: "{{ funkwhale_install_path }}/virtualenv/bin/python api/manage.py migrate --no-input"
+  args:
+    chdir: "{{ funkwhale_install_path }}"
diff --git a/tasks/main.yml b/tasks/main.yml
index 1f5d635..f22e3ac 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,6 +1,6 @@
 ---
-- include: packages.yml
-- include: db.yml
-- include: redis.yml
+# - include: packages.yml
+# - include: db.yml
+# - include: redis.yml
 - include: funkwhale.yml
 - include: nginx.yml
-- 
GitLab