From 120dda2c751f02b96e8fbd95ced43cf528ab9c39 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Sat, 3 Mar 2018 23:18:33 +0100
Subject: [PATCH] Sample updates, changelog and documentation for channels and
 activity

---
 api/Dockerfile                  |  1 +
 changes/changelog.d/23.feature  | 16 +++++++++
 changes/changelog.d/34.feature  | 59 +++++++++++++++++++++++++++++++++
 deploy/docker-compose.yml       |  1 -
 deploy/funkwhale-server.service |  2 +-
 deploy/nginx.conf               | 11 ++++++
 6 files changed, 88 insertions(+), 2 deletions(-)
 create mode 100644 changes/changelog.d/23.feature
 create mode 100644 changes/changelog.d/34.feature

diff --git a/api/Dockerfile b/api/Dockerfile
index a9aa33e3..9296785e 100644
--- a/api/Dockerfile
+++ b/api/Dockerfile
@@ -24,3 +24,4 @@ RUN pip install --upgrade youtube-dl
 WORKDIR /app
 
 ENTRYPOINT ["./compose/django/entrypoint.sh"]
+CMD ["./compose/django/daphne.sh"]
diff --git a/changes/changelog.d/23.feature b/changes/changelog.d/23.feature
new file mode 100644
index 00000000..fbfac0d9
--- /dev/null
+++ b/changes/changelog.d/23.feature
@@ -0,0 +1,16 @@
+Basic activity stream for listening and favorites (#23)
+
+A new "Activity" page is now available from the sidebar, where you can
+browse your instance activity. At the moment, this includes other users
+favorites and listening, but more activity types will be implemented in the
+future.
+
+Internally, we implemented those events by following the Activity Stream
+specification, which will help us to be compatible with other networks
+in the long-term.
+
+A new settings page has been added to control the visibility of your activity.
+By default, your activity will be browsable by anyone on your instance,
+but you can switch to a full private mode where nothing is shared.
+
+The setting form is available in your profile.
diff --git a/changes/changelog.d/34.feature b/changes/changelog.d/34.feature
new file mode 100644
index 00000000..1403f3dc
--- /dev/null
+++ b/changes/changelog.d/34.feature
@@ -0,0 +1,59 @@
+Switched to django-channels and daphne for serving HTTP and websocket (#34)
+
+Upgrade notes
+^^^^^^^^^^^^^
+
+This release include an important change in the way we serve the HTTP API.
+To prepare for new realtime features and enable websocket support in Funkwhale,
+we are now using django-channels and daphne to serve HTTP and websocket traffic.
+
+This replaces gunicorn and the switch should be easy assuming you
+follow the upgrade process described bellow.
+
+If you are using docker, please remove the command instruction inside the
+api service, as the up-to-date command is now included directly in the image
+as the default entry point:
+
+.. code-block:: yaml
+
+    api:
+      restart: unless-stopped
+      image: funkwhale/funkwhale:${FUNKWHALE_VERSION:-latest}
+      command: ./compose/django/gunicorn.sh  # You can remove this line
+
+On non docker setups, you'll have to update the [Service] block of your
+funkwhale-server systemd unit file to launch the application server using daphne instead of gunicorn.
+
+The new configuration should be similar to this:
+
+.. code-block:: ini
+
+    [Service]
+    User=funkwhale
+    # adapt this depending on the path of your funkwhale installation
+    WorkingDirectory=/srv/funkwhale/api
+    EnvironmentFile=/srv/funkwhale/config/.env
+    ExecStart=/usr/local/bin/daphne -b ${FUNKWHALE_API_IP} -p ${FUNKWHALE_API_PORT} config.asgi:application
+
+Ensure you update funkwhale's dependencies as usual to install the required
+packages.
+
+On both docker and non-docker setup, you'll also have to update your nginx
+configuration for websocket support. Ensure you have the following blocks
+included in your virtualhost file:
+
+.. code-block:: txt
+
+    map $http_upgrade $connection_upgrade {
+        default upgrade;
+        ''      close;
+    }
+
+    server {
+        ...
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection $connection_upgrade;
+    }
+
+Remember to reload your nginx server after the edit.
diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml
index 0c3b5654..e6292812 100644
--- a/deploy/docker-compose.yml
+++ b/deploy/docker-compose.yml
@@ -43,7 +43,6 @@ services:
     restart: unless-stopped
     image: funkwhale/funkwhale:${FUNKWHALE_VERSION:-latest}
     env_file: .env
-    command: ./compose/django/gunicorn.sh
     volumes:
       - ./data/music:/music:ro
       - ./data/media:/app/funkwhale_api/media
diff --git a/deploy/funkwhale-server.service b/deploy/funkwhale-server.service
index 7ef6e389..0027a80a 100644
--- a/deploy/funkwhale-server.service
+++ b/deploy/funkwhale-server.service
@@ -8,7 +8,7 @@ User=funkwhale
 # adapt this depending on the path of your funkwhale installation
 WorkingDirectory=/srv/funkwhale/api
 EnvironmentFile=/srv/funkwhale/config/.env
-ExecStart=/srv/funkwhale/virtualenv/bin/gunicorn config.wsgi:application -b ${FUNKWHALE_API_IP}:${FUNKWHALE_API_PORT}
+ExecStart=/usr/local/bin/daphne -b ${FUNKWHALE_API_IP} -p ${FUNKWHALE_API_PORT} config.asgi:application
 
 [Install]
 WantedBy=multi-user.target
diff --git a/deploy/nginx.conf b/deploy/nginx.conf
index cf3b3405..125fbc6d 100644
--- a/deploy/nginx.conf
+++ b/deploy/nginx.conf
@@ -19,6 +19,12 @@ server {
     location / { return 301 https://$host$request_uri; }
 }
 
+# required for websocket support
+map $http_upgrade $connection_upgrade {
+    default upgrade;
+    ''      close;
+}
+
 server {
     listen      443 ssl http2;
     listen [::]:443 ssl http2;
@@ -51,6 +57,11 @@ server {
     proxy_set_header X-Forwarded-Port   $server_port;
     proxy_redirect off;
 
+    # websocket support
+    proxy_http_version 1.1;
+    proxy_set_header Upgrade $http_upgrade;
+    proxy_set_header Connection $connection_upgrade;
+
     location / {
         try_files $uri $uri/ @rewrites;
     }
-- 
GitLab