Skip to content
23 changes: 11 additions & 12 deletions components/cli_runner/mpf_python_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
# limitations under the License. #
#############################################################################

import pkg_resources
from typing import Any, Mapping, Union, Iterable
import importlib.metadata
from typing import Any, Iterable, Mapping, Union

import mpf_cli_runner_util as util
import mpf_component_api
from mpf_component_api import ImageLocation, VideoTrack, AudioTrack, GenericTrack

from mpf_component_api import AudioTrack, GenericTrack, ImageLocation, VideoTrack


class PythonComponentHandle(util.ComponentHandle):
Expand All @@ -42,26 +41,26 @@ def __init__(self, descriptor: Mapping[str, Any]):
self.track_type = descriptor['algorithm']['trackType']


@classmethod
def _load_component(cls, descriptor) -> type:
@staticmethod
def _load_component(descriptor) -> type:
distribution_name = descriptor['batchLibrary']
entry_points = pkg_resources.get_entry_map(distribution_name, 'mpf.exported_component')

dist = importlib.metadata.distribution(distribution_name)
entry_points = dist.entry_points.select(group='mpf.exported_component')
if not entry_points:
raise RuntimeError(f'The "{distribution_name}" component did not declare a '
'"mpf.exported_component" entrypoint')

# The left hand side of the '=' in entry point declaration should be "component".
# For example: 'mpf.exported_component': 'component = my_module:MyComponentClass'
component_entry_point = entry_points.get('component')
if component_entry_point is None:
if component_entry_points := entry_points.select(name='component'):
return next(iter(component_entry_points)).load()
else:
# An entry point in the "mpf.exported_component" group was found,
# but the left hand side of the '=' was something else.
# For example: 'mpf.exported_component': 'MyComponentClass = my_module:MyComponentClass'
# We really only care about the entry point group, since we don't do anything with
# entry point name.
component_entry_point = next(iter(entry_points.values()))
return component_entry_point.load()
return next(iter(entry_points)).load()


def supports(self, media_type: util.MediaType) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion components/cli_runner/tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# limitations under the License. #
#############################################################################

FROM python:3.8-alpine
FROM python:3.12-alpine

RUN wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.3.tgz -O- \
| tar --extract --gzip --directory /bin --strip-components 1 docker/docker
Expand Down
15 changes: 9 additions & 6 deletions components/cpp_executor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \
--mount=type=tmpfs,target=/tmp \
apt-get update; \
apt-get upgrade -y; \
apt-get install --no-install-recommends -y \
python3.8 libpython3.8 wget ca-certificates gnupg2; \
apt-get install --no-install-recommends -y wget ca-certificates gnupg2; \
# Can't set up cuda repo at the beginning because it requires wget ca-certificates gnupg2
wget -O- https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub \
| apt-key add -; \
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" \
> /etc/apt/sources.list.d/cuda.list; \
wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \
| apt-key add -; \
echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \
> /etc/apt/sources.list.d/deadsnakes.list; \
apt-get update; \
apt-get install -y --no-install-recommends cuda-cudart-11-4; \
ln --symbolic /usr/bin/python3.8 /usr/bin/python3
apt-get install -y --no-install-recommends cuda-cudart-11-4 python3.12 libpython3.12; \
ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3

COPY --from=openmpf_build /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /usr/local/bin/

Expand Down Expand Up @@ -85,8 +88,8 @@ COPY --from=openmpf_build /build-artifacts/install/bin/amq_detection_component \
# component executor log config
COPY --from=openmpf_build /build-artifacts/install/config/Log4cxxConfig.xml $MPF_HOME/config/

COPY --from=openmpf_build /build-artifacts/install/lib/mpf_cpp_sdk.cpython-38-x86_64-linux-gnu.so \
/usr/lib/python3.8/lib-dynload
COPY --from=openmpf_build /build-artifacts/install/lib/mpf_cpp_sdk.cpython-312-x86_64-linux-gnu.so \
/usr/lib/python3.12/lib-dynload

COPY --from=openmpf_build /scripts/* /scripts/

Expand Down
10 changes: 8 additions & 2 deletions components/java_executor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \
--mount=type=tmpfs,target=/tmp \
apt-get update; \
apt-get upgrade -y; \
apt-get install --no-install-recommends -y openjdk-17-jre-headless python3.8; \
ln --symbolic /usr/bin/python3.8 /usr/bin/python3;
apt-get install --no-install-recommends -y openjdk-17-jre-headless wget ca-certificates gnupg2; \
wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \
| apt-key add -; \
echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \
> /etc/apt/sources.list.d/deadsnakes.list; \
apt-get update; \
apt-get install -y --no-install-recommends python3.12; \
ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3;

COPY --from=openmpf_build /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /usr/local/bin/

Expand Down
15 changes: 12 additions & 3 deletions components/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,24 @@ SHELL ["/bin/bash", "-o", "errexit", "-o", "pipefail", "-c"]
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8


RUN --mount=type=tmpfs,target=/var/cache/apt \
--mount=type=tmpfs,target=/var/lib/apt/lists \
--mount=type=tmpfs,target=/tmp \
apt-get update; \
apt-get upgrade -y; \
apt-get install --no-install-recommends -y wget ca-certificates gnupg2; \
wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \
| apt-key add -; \
echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \
> /etc/apt/sources.list.d/deadsnakes.list; \
apt-get update; \
apt-get install --no-install-recommends -y \
python3.8 python3.8-venv libpython3.8 \
python3.12 python3.12-venv libpython3.12 \
# Required for opencv-python
libglib2.0-0 libgl1-mesa-glx;
libglib2.0-0 libgl1-mesa-glx; \
python3.12 -m ensurepip --upgrade --default-pip; \
ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3;

COPY --from=openmpf_build /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /usr/local/bin/

Expand All @@ -67,7 +76,7 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \
apt-get update; \
# Some pip packages will try to compile C/C++ extensions during install. To compile the C/C++
# extensions, a C++ compiler and the Python development headers must be installed.
apt-get install --no-install-recommends -y g++ python3.8-dev
apt-get install --no-install-recommends -y g++ python3.12-dev

RUN python3 -m venv "$COMPONENT_VIRTUALENV"; \
pip config --site set global.no-cache-dir true; \
Expand Down
15 changes: 11 additions & 4 deletions openmpf_build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,33 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
wget ca-certificates gnupg2 unzip xz-utils cmake make g++ libgtest-dev mediainfo libssl-dev \
liblog4cxx-dev libboost-dev file openjdk-17-jdk-headless \
python3.8-dev python3-pip libgl1-mesa-glx \
libgl1-mesa-glx \
# libheif build deps
libde265-dev git nasm ninja-build pkg-config \
# OpenCV build deps \
libopenblas-dev liblapacke-dev libavcodec-dev libavcodec-extra libavformat-dev \
libavutil-dev libswscale-dev libavresample-dev libharfbuzz-dev libfreetype-dev; \
# Can't set up cuda repo at the beginning because it requires wget ca-certificates gnupg2
wget -O- https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub \
| apt-key add -; \
| apt-key add -; \
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" \
> /etc/apt/sources.list.d/cuda.list; \
wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \
| apt-key add -; \
echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \
> /etc/apt/sources.list.d/deadsnakes.list; \
apt-get update; \
apt-get install -y --no-install-recommends cuda-minimal-build-11-4 libcufft-dev-11-4 \
libnpp-dev-11-4 libcudnn8-dev=8.2.4.15-1+cuda11.4 libcudnn8=8.2.4.15-1+cuda11.4 \
libcublas-dev-11-4; \
libcublas-dev-11-4 \
python3.12-dev python3.12-venv; \
# OpenCV doesn't use the statically compiled CUDA libraries except for libcudart and they are relatively large.
find /usr/local/cuda/lib64/ -name '*.a' -not -name 'libcudart_static.a' -delete; \
rm /usr/lib/x86_64-linux-gnu/libcudnn*.a; \
ln --symbolic /usr/include/x86_64-linux-gnu/openblas-pthread/cblas.h /usr/include/cblas.h; \
ln --symbolic /usr/bin/cmake /usr/bin/cmake3;
ln --symbolic /usr/bin/cmake /usr/bin/cmake3; \
python3.12 -m ensurepip --upgrade --default-pip; \
ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3;


FROM apt_install AS ocv_install
Expand Down
18 changes: 13 additions & 5 deletions subject-components/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \
<<eot
apt-get update
apt-get upgrade -y
apt-get install --no-install-recommends -y python3.8 python3.8-venv libpython3.8 tini \
libgl1-mesa-glx libglib2.0-0
apt-get install --no-install-recommends -y tini libgl1-mesa-glx libglib2.0-0 \
wget ca-certificates gnupg2
wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \
| apt-key add -
echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \
> /etc/apt/sources.list.d/deadsnakes.list
apt-get update
apt-get install --no-install-recommends -y python3.12 python3.12-venv libpython3.12
ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3
eot

ENV MPF_HOME /opt/mpf
Expand All @@ -65,19 +72,20 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \
--mount=type=tmpfs,target=/tmp \
<<eot
apt-get update
apt-get install --no-install-recommends -y gcc python3.8-dev
apt-get install --no-install-recommends -y gcc python3.12-dev
eot

RUN <<eot
python3 -m venv "$COMPONENT_VIRTUALENV"
pip config --site set global.no-cache-dir true
pip install --upgrade pip
pip install --upgrade setuptools
eot

RUN --mount=from=openmpf_build,source=/home/mpf/openmpf-projects/openmpf-python-component-sdk/detection,target=/tmp/python \
RUN --mount=from=openmpf_build,source=/home/mpf/openmpf-projects/openmpf-python-component-sdk/detection,target=/tmp/python,rw \
pip3 install --no-cache-dir /tmp/python/api /tmp/python/component_util;

RUN --mount=from=openmpf_build,source=/home/mpf/openmpf-projects/openmpf-python-component-sdk/subject,target=/tmp/python \
RUN --mount=from=openmpf_build,source=/home/mpf/openmpf-projects/openmpf-python-component-sdk/subject,target=/tmp/python,rw \
pip3 install --no-cache-dir /tmp/python/api;

RUN --mount=from=openmpf_build,source=/build-artifacts/install/bin/subject_executor/requirements.txt,target=/tmp/requirements.txt \
Expand Down
12 changes: 10 additions & 2 deletions workflow_manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@ SHELL ["/bin/bash", "-o", "errexit", "-o", "pipefail", "-c"]
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8


RUN --mount=type=tmpfs,target=/var/cache/apt \
--mount=type=tmpfs,target=/var/lib/apt/lists \
--mount=type=tmpfs,target=/tmp \
apt-get update; \
apt-get upgrade -y; \
apt-get install --no-install-recommends -y \
openjdk-17-jre-headless libtcnative-1 file mediainfo wget ca-certificates \
python3.8 python3-pip;
openjdk-17-jre-headless libtcnative-1 file mediainfo wget ca-certificates gnupg2; \
wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \
| apt-key add -; \
echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \
> /etc/apt/sources.list.d/deadsnakes.list; \
apt-get update; \
apt-get install --no-install-recommends -y python3.12-venv; \
python3.12 -m ensurepip --upgrade --default-pip; \
ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3;


RUN wget --directory-prefix /scripts \
Expand Down