Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.sqlite3
*_cache
.git
.github
.venv
venv
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: pip install -r requirements.txt -r requirements_dev.txt

- name: Run tests
run: python -m pytest -v
run: python -m pytest -v --cov src

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ settings.ini

# Pyenv config
.python-version

/docker-compose.yaml
54 changes: 54 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM alpine:3.23

ARG FRONT_VERSION="1.9.2"

ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN apk add --no-cache \
nginx \
py3-pip \
python3 \
supervisor \
unzip \
wget

COPY requirements.txt requirements_prod.txt /app/

# install dependencies
RUN pip install \
--no-cache-dir \
--root-user-action ignore \
--break-system-packages \
-r /app/requirements.txt \
-r /app/requirements_prod.txt

# get the front archive
RUN FRONT_ARCHIVE="dakara-client-web_$FRONT_VERSION.zip" && \
wget \
-P /tmp \
https://github.com/DakaraProject/dakara-client-web/releases/download/$FRONT_VERSION/$FRONT_ARCHIVE && \
unzip \
/tmp/$FRONT_ARCHIVE \
-d /app && \
rm -rf \
/tmp/$FRONT_ARCHIVE \
/tmp/front

COPY deployment/etc/supervisor/apscheduler.ini /etc/supervisor.d/apscheduler.ini
COPY deployment/etc/supervisor/daphne.ini /etc/supervisor.d/daphne.ini
COPY deployment/etc/supervisor/gunicorn.ini /etc/supervisor.d/gunicorn.ini
COPY deployment/etc/supervisor/logging.ini /etc/supervisor.d/logging.ini
COPY deployment/etc/supervisor/nginx.ini /etc/supervisor.d/nginx.ini

COPY deployment/etc/nginx/nginx.conf /etc/nginx/nginx.conf

COPY . /app

EXPOSE 80
VOLUME /data

WORKDIR /

CMD ["sh", "/app/deployment/bin/run.sh"]
104 changes: 97 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
# Dakara server

<!-- Badges are displayed for the develop branch -->
[![Python versions](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13-blue)](https://github.com/DakaraProject/dakara-server)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/DakaraProject/dakara-server?tab=MIT-1-ov-file#readme)
[![Tests status](https://github.com/DakaraProject/dakara-server/actions/workflows/ci.yml/badge.svg)](https://github.com/DakaraProject/dakara-server/actions/workflows/ci.yml)
[![Codecov coverage analysis](https://codecov.io/gh/DakaraProject/dakara-server/branch/develop/graph/badge.svg)](https://codecov.io/gh/DakaraProject/dakara-server)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

Server for the Dakara project.

## Installation
## Local installation

To install Dakara completely, you have to get all the parts of the project.
Installation guidelines are provided over here:
Installation guidelines are provided here:

* [Dakara web client](https://github.com/DakaraProject/dakara-client-web/);
* [Dakara player VLC](https://github.com/DakaraProject/dakara-player-vlc/);
* [Dakara feeder](https://github.com/DakaraProject/dakara-feeder).

### System requirements

* Python3, to make everything up and running (supported versions: 3.10, 3.11, 3.12, and 3.13).
* Python3, to make everything up and running (supported versions: see above).

Linux, Mac and Windows are supported.

### Virtual environment

It is strongly recommended to run the Dakara server in a virtual environment.

```sh
python -m virtualenv venv
source venv/bin/activate
```

### Dependencies

Having a recent enough versio of `pip` is required to install some dependencies properly:
Expand All @@ -41,7 +48,36 @@ Install dependencies, at the root level of the repo (in the virtual environment)
pip install -r requirements.txt
```

### Setting up the server
For production, you will need some extra dependencies:

```sh
pip install -r requirements_prod.txt
```

## Setup

### Settings presets

The project provides settings presets:

- "development": for development purpose only. Uses a SQLite database, has debug mode enabled, an in-terminal pseudo mail backend, and security features turned off. Do not use this preset for production!
- "test": for test purpose only. Uses an in-memory SQLite database, and has security features turned off. Do not use this preset for production!
- "production": for use in the provided Docker image.

By default, the development preset is used.

You can create your own settings preset by duplicating the production file.

To select a preset, set the `DJANGO_SETTINGS_MODULE` environment variable accordingly, by instance for production:


```sh
export DJANGO_SETTINGS_MODULE="dakara_server.settings.production"
```

### Preparation of the server

Running the server in development requires some preliminary steps.

Let's create the server database, after loading the virtual environment, do:

Expand All @@ -65,17 +101,71 @@ You're almost done! To start the server app, in the right virtual environment, d
dakara_server/manage.py runserver
```

In a separate terminal, also run the scheduler.
This is currently only required for the kara date stop feature (which stops the karaoke at a certain date):

```sh
dakara_server/manage.py runapscheduler
```

The server part is now set up correctly.

### Web client, Feeder and player
### Web client, feeder and player

Now setup the [web client](https://github.com/DakaraProject/dakara-client-web), [feeder](https://github.com/DakaraProject/dakara-feeder) and [player](https://github.com/DakaraProject/dakara-player-vlc) according to their respective documentations.
The feeder can authenticate to the server using a token, or a couple login/password, of a playlist manager account.
The feeder can authenticate to the server using a token or a couple login/password of a playlist manager account.
The player can authenticate using a special token that only a playlist manager can generate.
Both token can be obtained from the web interface.
Both tokens can be obtained from the web interface.

After all of this is setup, just grab some friends and have fun!

## Docker image

For production, it is recommended to use the provided Docker image, which takes care of all the aspects of the execution.

You can build the local Docker image with:

```sh
sudo docker build . -t dakara-server
```

Then, run the container with:

```sh
sudo docker run \
-d \
-v path/to/persistent/data:/data \
-e DAKARA_DATABASE_URL="mysql://user:password@mysql/dakara" \
-e DAKARA_REDIS_URL="redis://redis:6379" \
-e DAKARA_ALLOWED_HOSTS="localhost,example.com" \
-e DAKARA_HOST_URL="http://example.com" \
-e DAKARA_SECRET_KEY="your-secret-key" \
-e DAKARA_LANGUAGE_CODE="en-us" \
-e DAKARA_TIME_ZONE="UTC" \
-e DAKARA_LOG_LEVEL="INFO" \
-e DAKARA_EMAIL_ENABLED=<true or false> \
-e DAKARA_EMAIL_HOST="postfix" \
-e DAKARA_EMAIL_HOST_USER="user" \
-e DAKARA_EMAIL_HOST_PASSWORD="password" \
-e DAKARA_SENDER_EMAIL="no-reply@example.com" \
-p 80:80 \
dakara-server
```

A `docker-compose.yaml` file is given as an example in `deployment/docker-compose/docker-compose.yaml`.

```sh
cp deployment/docker-compose/docker-compose.yaml ./
# edit it as you like
sudo docker compose up -d
```

Then, use your browser to acces the web page:

```sh
xdg-open http://localhost
```

## Development

Please read the [developers documentation](CONTRIBUTING.md).
66 changes: 31 additions & 35 deletions dakara_server/dakara_server/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
Django base settings for the Dakara server project.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
https://docs.djangoproject.com/en/5.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
https://docs.djangoproject.com/en/5.1/ref/settings/

This file should not be modified if you are not a dev.
"""

import os
from pathlib import Path

from decouple import config

from dakara_server.version import __date__ as DATE # noqa F401
from dakara_server.version import __version__ as VERSION # noqa F401

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
BASE_DIR = Path(__file__).resolve().parent.parent.parent
PROJECT_DIR = BASE_DIR.parent


# Application definition
Expand All @@ -30,6 +31,7 @@
"django.contrib.messages",
"daphne",
"django.contrib.staticfiles",
"django_apscheduler",
"rest_framework",
"rest_framework.authtoken",
"drf_spectacular",
Expand Down Expand Up @@ -83,18 +85,12 @@
}
]

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"TIMEOUT": None,
}
}

WSGI_APPLICATION = "dakara_server.wsgi.application"


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
# https://docs.djangoproject.com/en/5.1/topics/i18n/

USE_I18N = True

Expand All @@ -104,12 +100,10 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = "/static/"

STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]

# Django REST config
REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
Expand All @@ -132,34 +126,36 @@
}


SENDER_EMAIL = config("SENDER_EMAIL", default="no-reply@example.com")
HOST_URL = config("HOST_URL")
EMAIL_ENABLED = config("EMAIL_ENABLED", default=True, cast=bool)
EMAIL_ENABLED = config("DAKARA_EMAIL_ENABLED", default=True, cast=bool)


# Django rest registration config
REST_REGISTRATION = {
"LOGIN_AUTHENTICATE_SESSION": False,
"LOGIN_SERIALIZER_CLASS": "users.serializers.DakaraLoginSerializer",
"REGISTER_VERIFICATION_URL": HOST_URL + "/verify-registration/",
"RESET_PASSWORD_VERIFICATION_URL": HOST_URL + "/reset-password/",
"REGISTER_EMAIL_VERIFICATION_URL": HOST_URL + "/verify-email/",
"VERIFICATION_FROM_EMAIL": SENDER_EMAIL,
"USER_VERIFICATION_FLAG_FIELD": "validated_by_email",
"USER_LOGIN_FIELDS": ["username", "email"],
"REGISTER_VERIFICATION_ENABLED": EMAIL_ENABLED,
"REGISTER_EMAIL_VERIFICATION_ENABLED": EMAIL_ENABLED,
"RESET_PASSWORD_VERIFICATION_ENABLED": EMAIL_ENABLED,
}
def get_rest_registration(host_url, sender_email, email_enabled):
return {
"LOGIN_AUTHENTICATE_SESSION": False,
"LOGIN_SERIALIZER_CLASS": "users.serializers.DakaraLoginSerializer",
"REGISTER_VERIFICATION_URL": host_url + "/verify-registration/",
"RESET_PASSWORD_VERIFICATION_URL": host_url + "/reset-password/",
"REGISTER_EMAIL_VERIFICATION_URL": host_url + "/verify-email/",
"VERIFICATION_FROM_EMAIL": sender_email,
"USER_VERIFICATION_FLAG_FIELD": "validated_by_email",
"USER_LOGIN_FIELDS": ["username", "email"],
"REGISTER_VERIFICATION_ENABLED": email_enabled,
"REGISTER_EMAIL_VERIFICATION_ENABLED": email_enabled,
"RESET_PASSWORD_VERIFICATION_ENABLED": email_enabled,
}


AUTHENTICATION_BACKENDS = ["users.backends.DakaraModelBackend"]


# Front URLs
HOST_URLS = {
"USER_EDIT_URL": HOST_URL + "/settings/users/{id}",
"LOGIN_URL": HOST_URL + "/login",
}
def get_host_urls(host_url):
return {
"USER_EDIT_URL": host_url + "/settings/users/{id}",
"LOGIN_URL": host_url + "/login",
}


# limit of the playlist size
PLAYLIST_SIZE_LIMIT = config("PLAYLIST_SIZE_LIMIT", cast=int, default=100)
PLAYLIST_SIZE_LIMIT = config("DAKARA_PLAYLIST_SIZE_LIMIT", cast=int, default=100)
Loading