Dockerize deluge

This commit is contained in:
gmega 2024-10-25 19:20:55 -03:00
parent 73b59fb24b
commit bc81481c4c
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18
4 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,89 @@
# Simple wrapper on top of the Deluge config manager which allows us to generate
# an initial config file from env vars.
#
import copy
import os
import sys
from dataclasses import dataclass
from typing import Optional, Dict
from deluge.configmanager import ConfigManager, set_config_dir
from deluge.core.preferencesmanager import DEFAULT_PREFS
@dataclass
class ConfigOption:
name: str
description: str
default: Optional[str] = None
OPTIONS = [
ConfigOption(
name='DELUGE_CONFIG_DIR',
default='/var/lib/deluge',
description='Directory where config files should be stored',
),
ConfigOption(
name='DELUGE_DOWNLOAD_DIR',
default='/var/lib/deluge/downloads',
description='Directory where download files should be stored after completion',
),
ConfigOption(
'DELUGE_TORRENTFILE_DIR',
default='/var/lib/deluge/torrentfiles',
description='Directory where known torrent files should be stored',
),
ConfigOption(
name='DELUGE_RPC_PORT',
default='9889',
description='Port on which to listen for RPC requests',
),
ConfigOption(
name='DELUGE_LISTEN_PORTS',
default='6881,6891',
description='Listen ports for DHT and transfer connections'
),
ConfigOption(
name='DELUGE_EXTERNAL_IP',
description='IP on which to listen for connections',
)
]
def read_options() -> Dict[str, str]:
options = {}
for opt in OPTIONS:
if opt.name not in os.environ:
if not opt.default:
print(f'Required option missing {opt.name}: {opt.description}')
sys.exit(1)
value = opt.default
else:
value = os.environ[opt.name]
options[opt.name] = value
return options
def main():
options = read_options()
set_config_dir(options['DELUGE_CONFIG_DIR'])
defaults = copy.deepcopy(DEFAULT_PREFS)
defaults['listen_random_port'] = None
defaults['listen_interface'] = options['DELUGE_EXTERNAL_IP']
defaults['outgoing_interface'] = options['DELUGE_EXTERNAL_IP']
defaults['daemon_port'] = int(options['DELUGE_RPC_PORT'])
defaults['download_location'] = options['DELUGE_DOWNLOAD_DIR']
defaults['torrentfiles_location'] = options['DELUGE_TORRENTFILE_DIR']
defaults['listen_ports'] = [int(p) for p in options['DELUGE_LISTEN_PORTS'].split(',')]
manager = ConfigManager('core.conf', defaults=defaults)
manager.save()
if __name__ == '__main__':
main()

13
docker/bin/start.sh Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
if [ -z "${DELUGE_EXTERNAL_IP}" ]; then
echo "Warning: the listen IP address for the container has not been set."
DELUGE_EXTERNAL_IP=$(hostname -i)
echo "Using ${DELUGE_EXTERNAL_IP}"
export DELUGE_EXTERNAL_IP
fi
cd "${DELUGE_APP}"
python ./docker/bin/create_config.py
python -m deluge.core.daemon_entry -c "${DELUGE_CONFIG_DIR}" -d -L debug

36
docker/deluge.Dockerfile Normal file
View File

@ -0,0 +1,36 @@
# It's easier to use miniconda or we'll have to build python-boost manually.
FROM continuumio/miniconda3:24.9.2-0
ENV DELUGE_APP=/opt/deluge
ENV DELUGE_CONFIG_DIR=/var/lib/deluge
ENV DELUGE_DOWNLOAD_DIR=/var/lib/deluge/download
ENV DELUGE_TORRENTFILE_DIR=/var/lib/deluge/torrents
ENV DELUGE_RPC_PORT=6890
ENV DELUGE_LISTEN_PORTS=6891,6892
RUN mkdir -p ${DELUGE_APP}
WORKDIR ${DELUGE_APP}
# SHELL modifies the shell form to a login shell so we
# can autoactivate the conda env at every RUN command.
SHELL ["/bin/bash", "--login", "-c"]
RUN conda create -y -n 'deluge' python=3.8
# Populates the .bashrc so that conda is initialized
# and the proper env is activated before every call to RUN.
RUN conda init bash
RUN echo "conda activate deluge" > ~/.bashrc
RUN conda install -y anaconda::py-boost\
anaconda::gxx_linux-64\
anaconda:openssl
COPY . ./
RUN git submodule update --init --recursive &&\
cd vendor/libtorrent/bindings/python &&\
python setup.py build_ext install
RUN pip install .
ENTRYPOINT ["bash", "--login", "-c", "${DELUGE_APP}/docker/bin/start.sh"]

View File

@ -550,6 +550,7 @@ install_requires = [
"pywin32; sys_platform == 'win32'", "pywin32; sys_platform == 'win32'",
"certifi; sys_platform == 'win32'", "certifi; sys_platform == 'win32'",
'zope.interface', 'zope.interface',
'prometheus-client>=0.21.0',
] ]
extras_require = { extras_require = {
'all': [ 'all': [