funkwhale/docs/developer/setup/docker.md

5.2 KiB

Develop using Docker

Funkwhale can be run in Docker containers for local development. You can work on any part of the Funkwhale codebase and run the container setup to test your changes. To work with Docker:

Prerequisites

  1. Install Docker

  2. Install Docker Compose

  3. Install mkcert

  4. Install pre-commit

  5. Clone the Funkwhale repository to your system. The develop branch is checked out by default.

    ::::{tab-set}

    :::{tab-item} SSH

    git clone git@dev.funkwhale.audio/funkwhale/funkwhale.git
    cd funkwhale
    

    :::

    :::{tab-item} HTTPS

    git clone https://dev.funkwhale.audio/funkwhale/funkwhale.git
    cd funkwhale
    

    :::

    ::::

  6. Activate the pre-commit hook:

    pre-commit install
    
  7. Finally, initialise the environment:

    cp .env.example .env
    

Set up the Docker environment

Funkwhale provides a `compose.yml` file following the default file naming convention of a Docker Compose manifest. For Linux users, we assume that you finished the post-install steps to [manage Docker as a non-root user](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user).

To set up your Docker environment:

  1. Create a network for federation support:

    docker network create federation
    
  2. Then build the application containers. Run this command any time there are upstream changes or dependency changes to ensure you're up-to-date.

    docker compose build
    

Set up auxiliary services

  1. Create a wildcard certificate for funkwhale.test and *.funkwhale.test which will be installed into your system and browser trust stores with:
    mkcert -install -cert-file compose/var/test.crt -key-file compose/var/test.key "funkwhale.test" "*.funkwhale.test"
    

Then run the network services to access the running containers.

  1. Launch Træfik and dnsmasq using the bundled configuration:

    docker compose -f compose.net.yml up -d
    
  2. Add the DNS search domain for ~funkwhale.test to your system. This allows your system to dereference our domain names funkwhale.funkwhale.test, node2.funkwhale.test, node3.…, to the IP address of the Træfik reverse proxy listening at 172.17.0.1.

    ::::{tab-set}

    :::{tab-item} Linux

    sudo resolvectl dns docker0 172.17.0.1
    sudo resolvectl domain docker0 '~funkwhale.test.'
    

    :::

    :::{tab-item} Mac Follow the instructions at [macOS: Using Custom DNS Resolvers · vNinja.net] (https://vninja.net/2020/02/06/macos-custom-dns-resolvers/) :::

    ::::

:::{tip} You can now reach your Træfik dashboard at http://funkwhale.test:8008/dashboard/#/http/routers. :::

:::{note} If your docker0 network has no running containers presently attached to it, uncomment the net.helpers.docker0.yml rule in compose.net.yml.

Then restart the networking stack with docker compose -f compose.net.yml up -d. :::

Set up application services

Once you have set up the dependencies, launch all services to start working:

docker compose up -d

Find instructions for starting multiple instances further below.

:::{tip} This gives you access to the following:

Create a local superuser to be able to login:

docker compose run --rm api funkwhale-manage fw users create --superuser

Once you're done with the containers, you can stop them all:

docker compose stop

If you want to destroy your containers, run the following:

docker compose down

Destroy the state of your containers:

docker compose down --volumes
rm -rf .state/

Set up local data for development

You can create local data to mimic a live environment.

Add some fake data to populate the database. The following command creates 25 artists with random albums, tracks, and metadata.

artists=25 # Adds 25 fake artists
command="from funkwhale_api.music import fake_data; fake_data.create_data($artists)"
echo $command | docker compose run --rm -T api funkwhale-manage shell -i python

Running multiple instances

Set up as many different projects as you need. Make sure the COMPOSE_PROJECT_NAME and VUE_PORT variables are unique per instance

export COMPOSE_PROJECT_NAME=node2
# VUE_PORT this has to be unique for each instance
export VUE_PORT=1234
docker compose run --rm api funkwhale-manage fw users create --superuser
docker compose up -d

You can access your project at https://{COMPOSE_PROJECT_NAME}.funkwhale.test.

:::{warning} Federation between Alpine containers in Docker is broken due to upstream errors.