diff --git a/Dockerfile b/Dockerfile index 118a285..fa62b3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,15 @@ LABEL description='Slim Docker container featuring embedded Nut server from blaw LABEL repo='eskwisit/nut-server' LABEL email='mru2683@gmail.com' +# Fail the build on any error, including inside pipes +SHELL ["/bin/bash", "-euo", "pipefail", "-c"] + +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONUNBUFFERED=1 \ + PYTHONFAULTHANDLER=1 + # Prepare Nut install -RUN apt-get update && apt-get -y install \ +RUN apt-get update && apt-get -y install --no-install-recommends \ wget \ unzip \ gcc \ @@ -16,31 +23,37 @@ RUN apt-get update && apt-get -y install \ libjpeg-dev # Fetch Nut codebase -RUN wget https://github.com/blawar/nut/archive/refs/tags/v3.3.zip -RUN unzip v3.3.zip -d /root +RUN wget --no-verbose --tries=3 -O /tmp/nut.zip https://github.com/blawar/nut/archive/refs/tags/v3.3.zip +RUN unzip -q /tmp/nut.zip -d /root RUN mv /root/nut-3.3 /root/nut +RUN test -f /root/nut/nut.py # Edit config RUN mv /root/nut/conf/nut.default.conf /root/nut/conf/nut.conf -RUN sed -i '/scan/c "scan": ["\/titles"]' /root/nut/conf/nut.conf +RUN sed -i '/scan/c "scan": ["\/titles"]' /root/nut/conf/nut.conf \ + && grep -qF '"scan": ["/titles"]' /root/nut/conf/nut.conf # Remove GUI packages -RUN sed -i '/pyqt5/d' /root/nut/requirements.txt -RUN sed -i '/qt-range-slider/d' /root/nut/requirements.txt +RUN sed -i -e '/pyqt5/d' -e '/qt-range-slider/d' /root/nut/requirements.txt \ + && ! grep -qiE 'pyqt5|qt-range-slider' /root/nut/requirements.txt # Add missing requirements RUN echo markupsafe==2.0.1 >>/root/nut/requirements.txt # Install project dependencies -RUN pip3 install -U pip -RUN pip3 install -r /root/nut/requirements.txt +RUN pip3 install -U --no-cache-dir pip +RUN pip3 install --no-cache-dir -r /root/nut/requirements.txt VOLUME [ "/titles", "/root/nut/conf", "/root/nut/_NSPOUT" ] EXPOSE 9000 +# Surface a dead or wedged server instead of reporting the container as healthy +HEALTHCHECK --interval=30s --timeout=5s --start-period=180s --retries=3 \ + CMD python3 -c "import socket; socket.create_connection(('127.0.0.1', 9000), 3).close()" + # clean up -RUN rm v3.3.zip -RUN apt-get autoremove +RUN rm /tmp/nut.zip +RUN apt-get -y autoremove && apt-get clean && rm -rf /var/lib/apt/lists/* CMD ["python3", "/root/nut/nut.py", "--server"] diff --git a/README.md b/README.md index 7ae2e75..6e1e266 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Slim Docker image featuring embedded Nut server from [blawar/nut](https://github - Very low memory usage. - Designed to work on amd64 arch (Linux, Unix). - Auto refresh of titles directory. +- Built-in healthcheck on port 9000. - Zero config bundle. - Seamless integration for [Tinfoil](https://tinfoil.io/).