FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1

RUN apt-get update \
 && apt-get install -y --no-install-recommends software-properties-common gpg-agent \
 && add-apt-repository -y ppa:deluge-team/stable \
 && apt-get install -y --no-install-recommends deluge-web \
 && apt-get purge -y --auto-remove software-properties-common gpg-agent \
 && rm -rf /var/lib/apt/lists/*

COPY deluge-web_init.sh /usr/local/bin/deluge-web_init.sh

VOLUME ["/config"]
EXPOSE 80

HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
  CMD python3 -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:80/', timeout=4)" || exit 1

CMD ["/usr/local/bin/deluge-web_init.sh"]
