Sign inSign up

pkscout1/nextpvr-python3

By pkscout1

Updated about 3 years ago

A NextPVR image built from nextpvr/nextpvr_amd64:latest that includes Python3.

Image
0

3.2K

pkscout1/nextpvr-python3 repository overview

Introduction

There are two different ways you can run this Docker. The stable tag includes NextPVR, Python 3.9.6, and the following modules:

  • requests
  • xmltodict
  • websocket-client
  • opencv-python

These are included so two Python scripts I wrote (trigger.kodiscan and iguana-blaster) will work properly in a NextPVR docker container.

The pub tag includes NextPVR and Python 3.9.6. It is setup so that you can map a directory to user level python module installs and install them outside the Docker container. This provides more flexibility if you want to install other modules but don't want to have to redo it every time the image is updated.

Both tags also includes NTP and a couple options to set the timezone for your container. This was added because on certain platforms Docker containers don't seem to be able to get the time/timezone from the host OS. And having accurate times seems important for a DVR. If your Docker container is getting the time correctly from the Host OS, you don't need to include those options.

Stable Tag

Here's an example Docker run command:

docker run -d --name nextpvr \
--volume ~/Documents/NPVR/config:/config \
--volume ~/Documents/NPVR/recordings:/recordings \
--volume ~/Documents/NPVR/buffer:/buffer \
-e "SET_CONTAINER_TIMEZONE=true" \
-e "CONTAINER_TIMEZONE=Pacific/Honolulu" \
--publish 8866:8866 \
--publish 16891:16891/udp \
pkscout1/nextpvr-python3:stable

This image was built using the following Dockerfile:

FROM nextpvr/nextpvr_amd64:stable

ARG DEBIAN_FRONTEND=noninteractive
ADD startup.sh /usr/sbin/

WORKDIR /opt
RUN apt-get update && \
    apt-get install -y --no-install-recommends apt-utils  && \
    apt-get install -y --no-install-recommends ntp libsm6 libxext6 libxrender-dev && \
    apt-get install -y --no-install-recommends build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev && \
    curl --output Python-3.8.5.tgz https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz && \
    tar xzf Python-3.8.5.tgz && \
    Python-3.8.5/configure --enable-optimizations && \
    make install && \
    /usr/local/bin/python3.8 -m pip install --upgrade pip && \
    apt-get remove --purge -y apt-utils build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev && \
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /opt/*
RUN pip3 install requests xmltodict websocket-client opencv-python
WORKDIR /app

ENV SET_CONTAINER_TIMEZONE false
ENV CONTAINER_TIMEZONE Europe/Stockholm
ENV LD_LIBRARY_PATH=/app/runtimes/linux-arm64/native/
ENTRYPOINT /usr/sbin/startup.sh

Pub Tag

The pub tag uses Python's PYTHONUSERBASE option to define a place to install Python modules outside the standard install. By combining that with an external drive mapping, you can install whatever Python modules you want, and they will survive even if you replace the image. The most important thing to remember is that when you use pip3 to install modules, you MUST use the --user flag. Here's an example:

pip3 install requests --user

Here's an example Docker run command (with the mapping for the Python modules):

docker run -d --name nextpvr \
--volume ~/Documents/NPVR/config:/config \
--volume ~/Documents/NPVR/recordings:/recordings \
--volume ~/Documents/NPVR/buffer:/buffer \
--volume ~/Documents/NPVR/pub:/opt/pub \
-e "SET_CONTAINER_TIMEZONE=true" \
-e "CONTAINER_TIMEZONE=Pacific/Honolulu" \
--publish 8866:8866 \
--publish 16891:16891/udp \
pkscout1/nextpvr-python3:stable

This image was built using the following Dockerfile:

FROM nextpvr/nextpvr_amd64:stable

ARG DEBIAN_FRONTEND=noninteractive
ADD startup.sh /usr/sbin/

WORKDIR /opt
RUN apt-get update && \
    apt-get install -y --no-install-recommends apt-utils  && \
    apt-get install -y --no-install-recommends ntp libsm6 libxext6 libxrender-dev && \
    apt-get install -y --no-install-recommends build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev && \
    curl --output Python-3.8.5.tgz https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz && \
    tar xzf Python-3.8.5.tgz && \
    Python-3.8.5/configure --enable-optimizations && \
    make install && \
    /usr/local/bin/python3.8 -m pip install --upgrade pip && \
    apt-get remove --purge -y apt-utils build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev && \
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /opt/*
ENV PYTHONUSERBASE=/opt/pub
ENV PATH="$PYTHONUSERBASE/bin:$PATH"

WORKDIR /app
ENV SET_CONTAINER_TIMEZONE false
ENV CONTAINER_TIMEZONE Europe/Stockholm
ENV LD_LIBRARY_PATH=/app/runtimes/linux-arm64/native/
ENTRYPOINT /usr/sbin/startup.sh

Entry Point

Just for completeness, here's the startup.sh that is used as the entry point:

#!/bin/bash

# turn on bash's job control
set -m

# Fix the timezone if needed
if [ "$SET_CONTAINER_TIMEZONE" = "true" ]; then
    rm -f /etc/localtime
    ln -s /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime
	echo "Container timezone set to: $CONTAINER_TIMEZONE"
    # setup NTP
    ntpd -gq
    # Start the helper processes
    service ntp start
else
	echo "Container timezone not modified"
fi

# Start NextPVR
/usr/bin/dotnet /app/NextPVRServer.dll

# Now don't let the script stop, or the container will stop too
while :
do
    sleep 1
done

Tag summary

Content type

Image

Digest

sha256:b3487534b

Size

434.9 MB

Last updated

about 3 years ago

docker pull pkscout1/nextpvr-python3:pub