From d166ccd797a94199a1367592f6e4f635a8876065 Mon Sep 17 00:00:00 2001
From: phil <phil@systemausfall.org>
Date: Wed, 7 Jun 2023 23:17:12 +0200
Subject: [PATCH] Zammad: Add redis as dependecy for Zammad 6 Remove yarn - it
 will be installed by rake assets:precompile

---
 tasks/packages.yml         | 14 +-------------
 tasks/webserver.yml        |  3 +++
 templates/nginx-rp-site.j2 |  5 +++++
 templates/nginx-site.j2    | 25 +++++++++++++++++++++++--
 4 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/tasks/packages.yml b/tasks/packages.yml
index 95844b4..f29752c 100644
--- a/tasks/packages.yml
+++ b/tasks/packages.yml
@@ -33,18 +33,6 @@
       - patch
       - pkg-config
       - rbenv
+      - redis
       - sudo
-      - yarnpkg
       - zlib1g-dev
-
-# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=940511
-- name: "packages | ensure cmdtest is not installed"
-  apt:
-    name: cmdtest
-    state: absent
-
-- name: "packages | Erstelle yarn-Symlink"
-  file:
-    src: /usr/bin/yarnpkg
-    dest: /usr/local/bin/yarn
-    state: link
diff --git a/tasks/webserver.yml b/tasks/webserver.yml
index 9dce030..5e35c87 100644
--- a/tasks/webserver.yml
+++ b/tasks/webserver.yml
@@ -2,11 +2,14 @@
   template:
     src: nginx-site.j2
     dest: "{{ zammad_webserver_configuration }}"
+  notify: reload nginx
 
 - name: "webserver: Kofiguration aktivieren"
   file:
     src: "{{ zammad_webserver_configuration }}"
     dest: "/etc/nginx/sites-enabled/{{ zammad_domain }}"
     state: link
+  notify: reload nginx
+
 
 
diff --git a/templates/nginx-rp-site.j2 b/templates/nginx-rp-site.j2
index 5983dbb..aa4e0be 100644
--- a/templates/nginx-rp-site.j2
+++ b/templates/nginx-rp-site.j2
@@ -11,6 +11,11 @@ server {
     ssl_certificate /var/lib/dehydrated/certs/{{ zammad_domain }}/fullchain.pem;
     ssl_certificate_key /var/lib/dehydrated/certs/{{ zammad_domain }}/privkey.pem;
     include /etc/nginx/snippets/add_headers.conf;
+    location /cable {
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "Upgrade";
+        proxy_pass http://{{ inventory_hostname }}:80;
+    }
     location /ws {
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "Upgrade";
diff --git a/templates/nginx-site.j2 b/templates/nginx-site.j2
index 7a4b59c..77b9b28 100644
--- a/templates/nginx-site.j2
+++ b/templates/nginx-site.j2
@@ -1,3 +1,13 @@
+### {{ ansible_managed }}
+
+upstream zammad-railsserver {
+    server 127.0.0.1:3000;
+}
+
+upstream zammad-websocket {
+    server 127.0.0.1:6042;
+}
+
 server {
     listen 80;
     server_name {{ zammad_domain }};
@@ -11,6 +21,17 @@ server {
         expires max;
     }
 
+    location /cable {
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "Upgrade";
+        proxy_set_header CLIENT_IP $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header X-Forwarded-Proto $scheme;
+        proxy_read_timeout 86400;
+        proxy_pass http://zammad-railsserver;
+    }
+
     location /ws {
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
@@ -18,7 +39,7 @@ server {
         proxy_set_header CLIENT_IP $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto $scheme;
         proxy_read_timeout 86400;
-        proxy_pass http://127.0.0.1:6042;
+        proxy_pass http://zammad-websocket;
     }
 
     location / {
@@ -28,6 +49,6 @@ server {
         # Change this line in an SSO setup
         proxy_set_header X-Forwarded-User "";
         proxy_read_timeout 300;
-        proxy_pass http://127.0.0.1:3000;
+        proxy_pass http://zammad-railsserver;
     }
 }