diff --git a/Dockerfile b/Dockerfile index 1083f11..cfaccf6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -72,6 +72,8 @@ ENV CHROME_DISABLE_GPU=${CHROME_DISABLE_GPU} ENV DEBUG=false ENV VERBOSE=false ENV FORKS= +ENV PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages/ +#< trick for use apt installed packages on package installation with using pip. # Copy dummy packages COPY --from=builder ${PACKAGES_DIR} ${PACKAGES_DIR} @@ -113,27 +115,17 @@ RUN echo '%sudo ALL=(ALL:ALL) NOPASSWD:ALL' >/etc/sudoers.d/nopasswd \ WORKDIR /app # for armv7l install additional packages for build python modules (no binary distribution for some python packages). -RUN apt-get update && apt install -y --no-install-recommends python3-opencv && ( \ - BUILD_ARCH="$(arch)" ; \ - if [ "$BUILD_ARCH" = "armv7l" ] ; then \ - apt install -y --no-install-recommends cmake build-essential libssl-dev ; \ - fi ; \ - ) +RUN apt-get update && apt install -y --no-install-recommends python3-opencv python3-numpy RUN echo "Install python package for arch: $(arch)" COPY . flare_bypasser -RUN pip install --prefer-binary flare_bypasser/ +RUN ADDITIONAL_PYTHONPATH="$PYTHONPATH" pip install --prefer-binary flare_bypasser/ COPY rootfs / # Cleanup environment - decrease image size. -RUN pip cache purge && apt clean && ( \ - BUILD_ARCH="$(arch)" ; \ - if [ "$BUILD_ARCH" = "armv7l" ] ; then \ - apt autoremove -y cmake build-essential libssl-dev ; \ - fi ; \ - ) +RUN pip cache purge && apt clean USER ${UID} diff --git a/setup.py b/setup.py index 07ae51b..6b7d811 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,23 @@ +import sys +import os +import importlib import distutils.core +# Trick for avoid installation of non pip installed packages (apt), available by ADDITIONAL_PYTHONPATH def is_installed(pkgname): try: - import cv2 # noqa - return True + m = importlib.import_module(pkgname) + return m is not None except Exception: - return False + pass + return False +if "ADDITIONAL_PYTHONPATH" in os.environ: + add_path = os.environ["ADDITIONAL_PYTHONPATH"] + sys.path += add_path.split(':') + install_requires = [ 'asyncio', 'uuid', @@ -29,8 +38,8 @@ def is_installed(pkgname): 'gunicorn ; platform_system != "Windows"', ] -if not is_installed('cv2'): - # can be installed as opencv-python or opencv-contrib-python - install_requires += ['opencv-python'] +for package_import_name, package in [('numpy', 'numpy'), ('cv2', 'opencv-python')]: + if not is_installed(package_import_name): + install_requires += [package] distutils.core.setup(install_requires=install_requires)