diff --git a/.github/workflows/docker-builds.yml b/.github/workflows/docker-builds.yml index 733df6b..af3d840 100644 --- a/.github/workflows/docker-builds.yml +++ b/.github/workflows/docker-builds.yml @@ -17,9 +17,15 @@ jobs: strategy: fail-fast: false matrix: - python_version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] + ubuntu_version: ["20.04"] + python_version: ["2.7", "3.6", "3.7", "3.8", "3.9"] opencv_version: ["4.8.1"] device: ["cpu", "gpu"] + include: + - {ubuntu_version: "22.04", python_version: "3.10", opencv_version: "4.8.1", device: "cpu"} + - {ubuntu_version: "22.04", python_version: "3.10", opencv_version: "4.8.1", device: "gpu"} + - {ubuntu_version: "22.04", python_version: "3.11", opencv_version: "4.8.1", device: "cpu"} + - {ubuntu_version: "22.04", python_version: "3.11", opencv_version: "4.8.1", device: "gpu"} steps: - name: Checkout uses: actions/checkout@v3 @@ -36,6 +42,7 @@ jobs: # https://github.com/docker/build-push-action#cache-to-registry with: build-args: | + UBUNTU_VERSION=${{ matrix.ubuntu_version }} PYTHON_VERSION=${{ matrix.python_version }} OPENCV_VERSION=${{ matrix.opencv_version }} file: ${{ matrix.device }}/Dockerfile diff --git a/README.md b/README.md index e5e2fb7..f7da6c2 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ You can build it on your own, note it takes lots of time, be prepared. ```bash git clone cd docker_python-opencv-ffmpeg -docker image build -t python-opencv-ffmpeg:py3.8 -f gpu/Dockerfile --build-arg PYTHON_VERSION=3.8 . +docker image build -t python-opencv-ffmpeg:py3.9 -f cpu/Dockerfile --build-arg PYTHON_VERSION=3.9 . ``` To build other versions, select different Dockerfile. diff --git a/cpu/Dockerfile b/cpu/Dockerfile index ea501b0..8cf0b5e 100644 --- a/cpu/Dockerfile +++ b/cpu/Dockerfile @@ -1,7 +1,9 @@ # https://www.learnopencv.com/install-opencv3-on-ubuntu/ # https://www.osradar.com/how-to-install-opencv-on-ubuntu-20-04/ -FROM ubuntu:20.04 +ARG UBUNTU_VERSION=22.04 + +FROM ubuntu:${UBUNTU_VERSION} LABEL maintainer="https://github.com/Borda" @@ -11,14 +13,17 @@ ARG OPENCV_VERSION=4.8.0 # Needed for string substitution SHELL ["/bin/bash", "-c"] # https://techoverflow.net/2019/05/18/how-to-fix-configuring-tzdata-interactive-input-when-building-docker-images/ -ENV DEBIAN_FRONTEND=noninteractive -ENV TZ=Europe/Prague +ENV DEBIAN_FRONTEND=noninteractive \ + TZ=Europe/Prague + RUN \ # add sources for older pythons - apt-get update --fix-missing && \ + apt-get update -q --fix-missing && \ apt-get install -y --no-install-recommends software-properties-common && \ - add-apt-repository ppa:deadsnakes/ppa && \ + if [[ "$PYTHON_VERSION" =~ ^(2.7|3.6|3.7)$ ]]; then \ + add-apt-repository ppa:deadsnakes/ppa ; \ + fi && \ apt-add-repository universe && \ apt-get -y update -qq --fix-missing && \ apt-get -y install --no-install-recommends \ @@ -28,6 +33,7 @@ RUN \ curl \ wget \ && \ + rm -rf /var/lib/apt/lists/* && \ # Set the default python and install PIP packages update-alternatives --install /usr/bin/python${PYTHON_VERSION%%.*} python${PYTHON_VERSION%%.*} /usr/bin/python${PYTHON_VERSION} 1 && \ @@ -41,8 +47,7 @@ RUN \ apt-get -y install --no-install-recommends python${PYTHON_VERSION}-distutils ; \ PIP_URL="https://bootstrap.pypa.io/get-pip.py" ; \ fi && \ - curl $PIP_URL | python && \ - rm -rf /var/lib/apt/lists/* + curl $PIP_URL | python ENV PYTHONPATH="/usr/lib/python${PYTHON_VERSION}/site-packages:/usr/local/lib/python${PYTHON_VERSION}/site-packages" @@ -53,30 +58,24 @@ RUN \ unzip \ cmake \ ffmpeg \ - libtbb2 \ + $( [ "$UBUNTU_VERSION" = "20.04" ] && libtbb2 || libtbb12 ) \ gfortran \ apt-utils \ pkg-config \ checkinstall \ - qt5-default \ + qtbase5-dev qt5-qmake \ build-essential \ libopenblas-base \ libopenblas-dev \ liblapack-dev \ libatlas-base-dev \ - #libgtk-3-dev \ - #libavcodec58 \ libavcodec-dev \ - #libavformat58 \ libavformat-dev \ libavutil-dev \ - #libswscale5 \ libswscale-dev \ libjpeg8-dev \ libpng-dev \ libtiff5-dev \ - #libdc1394-22 \ - libdc1394-22-dev \ libxine2-dev \ libv4l-dev \ libgstreamer1.0 \ @@ -92,7 +91,7 @@ RUN \ libxext6 \ libxrender1 \ && \ - pip${PYTHON_VERSION} install numpy && \ + pip install numpy && \ # Install OpenCV wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip -O opencv.zip --progress=bar:force:noscroll --no-check-certificate && \ @@ -152,7 +151,6 @@ RUN \ libopenblas-dev \ liblapack-dev \ libatlas-base-dev \ - #libgtk-3-dev \ libavcodec-dev \ libavformat-dev \ libavutil-dev \ @@ -160,7 +158,6 @@ RUN \ libjpeg8-dev \ libpng-dev \ libtiff5-dev \ - libdc1394-22-dev \ libxine2-dev \ libv4l-dev \ libgstreamer1.0-dev \ @@ -168,15 +165,16 @@ RUN \ libglew-dev \ libpostproc-dev \ libeigen3-dev \ - libtbb-dev \ zlib1g-dev \ && \ apt-get autoremove -y && \ apt-get clean && \ - rm -rf /opencv /opencv_contrib /var/lib/apt/lists/* && \ + rm -rf /opencv /opencv_contrib /var/lib/apt/lists/* -# Call default command. +RUN \ + # Call default command. ffmpeg -version && \ #ldd `which ffmpeg` && \ python --version && \ + pip list && \ python -c "import cv2 ; print(cv2.__version__)" diff --git a/gpu/Dockerfile b/gpu/Dockerfile index 1c929f8..57284a1 100644 --- a/gpu/Dockerfile +++ b/gpu/Dockerfile @@ -5,9 +5,10 @@ # CALL: docker image build -t python-opencv-ffmpeg:py36 -f cpu/Dockerfile --build-arg PYTHON_VERSION=3.6 . -ARG CUDA_VERSION=11.7.1 +ARG CUDA_VERSION=11.8.0 +ARG UBUNTU_VERSION=22.04 -FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu20.04 +FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} LABEL maintainer="https://github.com/Borda" @@ -17,8 +18,8 @@ ARG OPENCV_VERSION=4.8.0 # Needed for string substitution SHELL ["/bin/bash", "-c"] # https://techoverflow.net/2019/05/18/how-to-fix-configuring-tzdata-interactive-input-when-building-docker-images/ -ENV DEBIAN_FRONTEND=noninteractive -ENV TZ=Europe/Prague +ENV DEBIAN_FRONTEND=noninteractive \ + TZ=Europe/Prague # ENV LD_LIBRARY_PATH /usr/local/${CUDA}/compat:$LD_LIBRARY_PATH @@ -26,7 +27,9 @@ RUN \ # add sources for older pythons apt-get update -qq --fix-missing && \ apt-get install -y --no-install-recommends software-properties-common && \ - add-apt-repository ppa:deadsnakes/ppa && \ + if [[ "$PYTHON_VERSION" =~ ^(2.7|3.6|3.7)$ ]]; then \ + add-apt-repository ppa:deadsnakes/ppa ; \ + fi && \ apt-add-repository universe && \ apt-get -y update -qq --fix-missing && \ apt-get -y install --no-install-recommends \ @@ -36,6 +39,7 @@ RUN \ curl \ wget \ && \ + rm -rf /var/lib/apt/lists/* && \ # Set the default python and install PIP packages update-alternatives --install /usr/bin/python${PYTHON_VERSION%%.*} python${PYTHON_VERSION%%.*} /usr/bin/python${PYTHON_VERSION} 1 && \ @@ -49,8 +53,7 @@ RUN \ apt-get -y install --no-install-recommends python${PYTHON_VERSION}-distutils ; \ PIP_URL="https://bootstrap.pypa.io/get-pip.py" ; \ fi && \ - curl $PIP_URL | python && \ - rm -rf /var/lib/apt/lists/* + curl $PIP_URL | python ENV PYTHONPATH="/usr/lib/python${PYTHON_VERSION}/site-packages:/usr/local/lib/python${PYTHON_VERSION}/site-packages" @@ -67,30 +70,24 @@ RUN \ unzip \ cmake \ ffmpeg \ - libtbb2 \ + $( [ "$UBUNTU_VERSION" = "20.04" ] && libtbb2 || libtbb12 ) \ gfortran \ apt-utils \ pkg-config \ checkinstall \ - qt5-default \ + qtbase5-dev qt5-qmake \ build-essential \ libopenblas-base \ libopenblas-dev \ liblapack-dev \ libatlas-base-dev \ - #libgtk-3-dev \ - #libavcodec58 \ libavcodec-dev \ - #libavformat58 \ libavformat-dev \ libavutil-dev \ - #libswscale5 \ libswscale-dev \ libjpeg8-dev \ libpng-dev \ libtiff5-dev \ - #libdc1394-22 \ - libdc1394-22-dev \ libxine2-dev \ libv4l-dev \ libgstreamer1.0 \ @@ -106,7 +103,7 @@ RUN \ libxext6 \ libxrender1 \ && \ - pip${PYTHON_VERSION} install numpy && \ + pip install numpy && \ # Install OpenCV wget https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip -O opencv.zip --progress=bar:force:noscroll && \ @@ -177,7 +174,6 @@ RUN \ libopenblas-dev \ liblapack-dev \ libatlas-base-dev \ - #libgtk-3-dev \ libavcodec-dev \ libavformat-dev \ libavutil-dev \ @@ -185,7 +181,6 @@ RUN \ libjpeg8-dev \ libpng-dev \ libtiff5-dev \ - libdc1394-22-dev \ libxine2-dev \ libv4l-dev \ libgstreamer1.0-dev \ @@ -193,15 +188,16 @@ RUN \ libglew-dev \ libpostproc-dev \ libeigen3-dev \ - libtbb-dev \ zlib1g-dev \ && \ apt-get autoremove -y && \ apt-get clean && \ - rm -rf /opencv /opencv_contrib /var/lib/apt/lists/* && \ + rm -rf /opencv /opencv_contrib /var/lib/apt/lists/* -# Call default command. +RUN \ + # Call default command. ffmpeg -version && \ #ldd `which ffmpeg` && \ python --version && \ + pip list && \ python -c "import cv2 ; print(cv2.__version__)"