From 37e9987b20c49438fa0ee21f60ab2e6d1ef15bb5 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sun, 15 Mar 2020 15:56:50 +0100
Subject: [PATCH] [Docker] Server static files via nginx

---
 docker-compose.yml      |  2 ++
 docker/entrypoint.sh    |  1 +
 docker/nginx/nginx.conf | 11 ++++++++---
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index 7dfda92d1..9d4b11498 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -15,6 +15,7 @@ services:
     image: registry.edugit.org/aleksis/official/aleksis:${ALEKSIS_IMAGE_TAG:-latest}
     volumes:
       - aleksis_data:/var/lib/aleksis/
+      - aleksis_static:/usr/share/aleksis/static/
     environment:
       - ALEKSIS_http__allowed_hosts="['*']"
       - ALEKSIS_caching__memcached__address=memcached:11211
@@ -28,6 +29,7 @@ services:
     image: registry.edugit.org/aleksis/official/aleksis/nginx:${ALEKSIS_IMAGE_TAG:-latest}
     volumes:
       - aleksis_data:/var/lib/aleksis/
+      - aleksis_static:/usr/share/aleksis/static/:ro
     ports:
       - ${NGINX_HTTP_PORT:-8080}:80
     depends_on:
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index bb5eca2a1..bd6cc310b 100755
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -17,6 +17,7 @@ while ! nc -z $ALEKSIS_database__host $ALEKSIS_database__port; do
     sleep 0.1
 done
 
+python manage.py collectstatic --no-input --clear
 python manage.py migrate
 
 if [[ -n "$@" ]]; then
diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf
index 49c1f9a75..759f38504 100644
--- a/docker/nginx/nginx.conf
+++ b/docker/nginx/nginx.conf
@@ -5,6 +5,14 @@ upstream aleksis {
 server {
     listen 80;
 
+    location /media/ {
+        alias /var/lib/aleksis/media/;
+    }
+
+    location /static/ {
+        alias /usr/share/aleksis/static/;
+    }
+
     location / {
         proxy_pass http://aleksis;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -12,7 +20,4 @@ server {
         proxy_redirect off;
     }
 
-    location /media/ {
-        alias /var/lib/aleksis/media/;
-    }
 }
-- 
GitLab