From fda56d582b3707d41c8c33972abba4ff0f215410 Mon Sep 17 00:00:00 2001
From: Creak <romain.failliot@foolstep.com>
Date: Wed, 6 May 2020 00:30:31 +0200
Subject: [PATCH] Simplify all-in-one docker installation

Use docker-compose only to deploy the service on the server.
---
 docs/installation/docker.rst | 135 +++++++++++++++--------------------
 1 file changed, 57 insertions(+), 78 deletions(-)

diff --git a/docs/installation/docker.rst b/docs/installation/docker.rst
index 7bb912b81..08c531480 100644
--- a/docs/installation/docker.rst
+++ b/docs/installation/docker.rst
@@ -23,7 +23,21 @@ Mono-container installation
 
     This installation method was contributed by @thetarkus, at https://github.com/thetarkus/docker-funkwhale
 
-First, ensure you have `Docker <https://docs.docker.com/engine/installation/>`_ installed.
+These are the installation steps:
+
+1. Install docker
+2. Create ``funkwhale`` user
+3. Create ``.env`` file
+4. Create ``docker-compose.yml`` file
+5. Start Funkwhale service
+
+Install docker
+~~~~~~~~~~~~~~
+
+Ensure you have `Docker <https://docs.docker.com/engine/installation/>`_ and `docker-compose <https://docs.docker.com/compose/install/>`_ installed.
+
+Create ``funkwhale`` user
+~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Create the user and the directory:
 
@@ -38,11 +52,10 @@ Log in as the newly created user from now on:
 
     sudo -u funkwhale -H bash
 
-Export the `version you want <https://hub.docker.com/r/funkwhale/all-in-one/tags>`_ to deploy (e.g., ``0.19.1``):
+Create ``.env`` file
+~~~~~~~~~~~~~~~~~~~~
 
-.. parsed-literal::
-
-    export FUNKWHALE_VERSION="|version|"
+Export the `version you want <https://hub.docker.com/r/funkwhale/all-in-one/tags>`_ to deploy (e.g., ``0.21``):
 
 Create an env file to store a few important configuration options:
 
@@ -50,7 +63,7 @@ Create an env file to store a few important configuration options:
 
     touch .env
     chmod 600 .env  # reduce permissions on the .env file since it contains sensitive data
-    cat > .env <<EOD
+    cat > .env << EOF
     # Replace 'your.funkwhale.example' with your actual domain
     FUNKWHALE_HOSTNAME=your.funkwhale.example
     # Protocol may also be: http
@@ -65,29 +78,44 @@ Create an env file to store a few important configuration options:
     DJANGO_SECRET_KEY=$(openssl rand -hex 45)
     # Remove this if you expose the container directly on ports 80/443
     NESTED_PROXY=1
-    EOD
+    EOF
+
+Create ``docker-compose.yml`` file
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. code-block:: yaml
+
+    version: "3"
+    services:
+      funkwhale:
+        container_name: funkwhale
+        restart: unless-stopped
+        # change version number here when you want to do an upgrade
+        image: funkwhale/all-in-one:|version|
+        env_file: .env
+        environment:
+          # adapt to the pid/gid that own /srv/funkwhale/data
+          - PUID=1000
+          - PGID=1000
+        volumes:
+          - /srv/funkwhale/data:/data
+          - /path/to/your/music/dir:/music:ro
+        ports:
+          - "5000:80"
 
+.. note::
 
-Then start the container:
+    - ``PUID`` and ``PGID`` are optional but useful to prevent permission issues with docker volumes
+    - ``/path/to/your/music/dir`` should point to a path on your host where music you would like to import is located. You can safely remove the volume if you don't want to import music that way.
 
-.. code-block:: shell
+Start Funkwhale service
+~~~~~~~~~~~~~~~~~~~~~~~
 
-    docker run \
-        --name=funkwhale \
-        --restart=unless-stopped \
-        --env-file=/srv/funkwhale/.env \
-        -v /srv/funkwhale/data:/data \
-        -v /path/to/your/music/dir:/music:ro \
-        -e PUID=$UID \
-        -e PGID=$GID \
-        -p 5000:80 \
-        -d \
-        funkwhale/all-in-one:$FUNKWHALE_VERSION
+Start the container:
 
-.. note::
+.. code-block:: shell
 
-    - ``-e PUID`` and ``-e PGID`` are optional but useful to prevent permission issues with docker volumes
-    - ``-v /path/to/your/music/dir`` should point to a path on your host were is located music you want to import in your Funkwhale instance. You can safely remove the volume if you don't want to import music that way.
+    docker-compose up -d
 
 Your container should start in the background, and your instance be available at ``yourip:5000`` shortly.
 
@@ -95,66 +123,17 @@ You will need an admin account to login and manage your account, create one usin
 
 Useful commands:
 
+- You can start and stop your instance using ``docker-compose start`` and ``docker-compose stop``, respectively
 - You can examine the logs by running ``docker logs -f --tail=50 funkwhale``
-- You can start and stop your instance using ``docker start funkwhale`` and ``docker stop funkwhale``, respectively
 - To have a better idea of the resource usage of your instance (CPU, memory), run ``docker stats funkwhale``
 
-.. note::
-
-    The container will not pick up changes made in .env file automatically.
-    In order to load new configuration, run:
-
-    .. parsed-literal::
-
-        export FUNKWHALE_VERSION="|version|"
-
-    .. code-block:: shell
-
-        # stop and remove the existing container
-        docker stop funkwhale
-        docker rm funkwhale
-        # relaunch a new container
-        docker run \
-            --name=funkwhale \
-            --restart=unless-stopped \
-            --env-file=/srv/funkwhale/.env \
-            -v /srv/funkwhale/data:/data \
-            -v /path/to/your/music/dir:/music:ro \
-            -e PUID=$UID \
-            -e PGID=$GID \
-            -p 5000:80 \
-            -d \
-            funkwhale/all-in-one:$FUNKWHALE_VERSION
-
-
-    You can use the following docker-compose file to make the management process easier:
-
-    .. code-block:: yaml
-
-        version: "3"
-
-        services:
-          funkwhale:
-            container_name: funkwhale
-            restart: unless-stopped
-            # add the version number in your .env file, or hardcode it
-            image: funkwhale/all-in-one:${FUNKWHALE_VERSION}
-            env_file: .env
-            environment:
-              # adapt to the pid/gid that own /srv/funkwhale/data
-              - PUID=1000
-              - PGID=1000
-            volumes:
-              - /srv/funkwhale/data:/data
-              - /path/to/your/music/dir:/music:ro
-            ports:
-              - "5000:80"
+Now, you just need to configure your :ref:`reverse-proxy <reverse-proxy-setup>`. Don't worry, it's quite easy.
 
-    Then start the container:
+.. note::
 
-    .. code-block:: shell
+    To upgrade your service, change the version number in ``docker-compose.yml`` and re-run ``docker-compose up -d``.
 
-        docker-compose up -d
+    Don't forget you might have manual changes to do when upgrading to a newer version.
 
 .. _docker-multi-container:
 
@@ -163,7 +142,7 @@ Multi-container installation
 
 First, ensure you have `Docker <https://docs.docker.com/engine/installation/>`_ and `docker-compose <https://docs.docker.com/compose/install/>`_ installed.
 
-Export the `version you want <https://hub.docker.com/r/funkwhale/all-in-one/tags>`_ to deploy (e.g., ``0.19.1``):
+Export the `version you want <https://hub.docker.com/r/funkwhale/all-in-one/tags>`_ to deploy (e.g., ``0.21``):
 
 .. parsed-literal::
 
-- 
GitLab