0

I have a Dockerfile which compiles opencv for quite a while. Recently I decided to try out buildkit (for cross compilation). However, with buildkit the opencv compilation fails. With the following error:

#9 130.0 [ 87%] Linking CXX shared library ../../lib/libopencv_imgcodecs.so
#9 130.5 [ 87%] Built target opencv_imgcodecs
#9 130.5 [ 87%] Generating src/moc_window_QT.cpp
#9 130.5 [ 87%] Generating qrc_window_QT.cpp
#9 130.5 standard input:0: Note: No relevant classes found. No output generated.
#9 130.5 RCC: Error in '/opencv/modules/highgui/src/window_QT.qrc': Cannot find file 'files_Qt/Milky/48/28.png'
#9 130.5 make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:78: modules/highgui/qrc_window_QT.cpp] Error 1
#9 130.5 make[1]: *** [CMakeFiles/Makefile2:1684: modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
#9 130.5 make: *** [Makefile:163: all] Error 2

I tried stopping the build after the git clone to see if the file files_Qt/Milky/48/28.png exists inside the container and it does. Moreover, if I start the compilation process from the interactive shell in the container, the compilation process succeeds.

So it seems the compilation only fails if it is part of the docker build.

Does anybody know more details about how buildkit works and if this could have an impact on the compilation process?

Here is a minimal example of the build command and Dockerfile:

DOCKER_BUILDKIT=1 docker build --no-cache --progress=plain -t "buildkit_error:latest" -f Dockerfile .
FROM ubuntu:20.04

WORKDIR /

# Setup apt repositories
RUN \
  apt update && \
  apt install -y --no-install-recommends \
      wget \
      software-properties-common && \
  add-apt-repository ppa:deadsnakes/ppa && \
  apt install -y --fix-broken && \
  apt update && \
  apt upgrade -y && \
  apt dist-upgrade -y && \
  apt remove -y python3 && \
  apt clean && \
  apt autoremove -y && \
  apt autoclean -y

# Install apt packages
# ORDER ALPHABETICALLY!
RUN \
  apt install -y --no-install-recommends \
      build-essential \
      clang-10 \
      cmake \
      cpio \
      git \
      libdrm-dev \
      libcairo2-dev \
      libomp-10-dev \
      llvm-10-dev \
      openssh-client \
      pkg-config \
      python3.6-dev \
      python3.6-distutils\
      python3.6-minimal \
      python3-pip \
      qt5-default

# Install pip dependencies
# ORDER ALPHABETICALLY!
RUN python3.6 -m pip install --no-cache-dir \
  numpy==1.16.1 \
  setuptools==59.6.0 \
  wheel==0.37.1

RUN \
    ln -sf /usr/bin/python3.6 /usr/bin/python3 && \
    ln -sf /usr/bin/python3 /usr/bin/python

ENV opencv=3.4.3
RUN git clone --branch $opencv --depth 1 https://github.com/opencv/opencv.git

RUN ls -al /opencv/modules/highgui/src/files_Qt/Milky/48

# build opencv from source
RUN \
  mkdir opencv/build && cd opencv/build && cmake -DBUILD_TIFF=ON \
  -DCMAKE_C_COMPILER=clang-10 \
  -DCMAKE_CXX_COMPILER=clang++-10 \
  -DENABLE_FAST_MATH=ON \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_opencv_java=OFF \
  -DWITH_CUDA=OFF \
  -DENABLE_CXX11=ON \
  -DWITH_OPENGL=ON \
  -DWITH_OPENCL=ON \
  -DWITH_IPP=ON \
  -DWITH_TBB=ON \
  -DWITH_EIGEN=ON \
  -DWITH_V4L=OFF \
  -DWITH_GTK=ON \
  -DWITH_GTK_2_X=ON \
  -DBUILD_PERF_TESTS=OFF \
  -DBUILD_opencv_apps=OFF \
  -DBUILD_JAVA=OFF \
  -DBUILD_PROTOBUF=OFF \
  -DBUILD_PACKAGE=OFF \
  -DBUILD_TESTS=OFF \
  -DBUILD_opencv=OFF \
  -DBUILD_opencv_dnn=OFF \
  -DBUILD_opencv_java_bindings_generator=OFF \
  -DBUILD_opencv_shape=OFF \
  -DBUILD_opencv_stitching=OFF \
  -DBUILD_opencv_superres=OFF \
  -DBUILD_opencv_ts=OFF \
  -DBUILD_opencv_video=OFF \
  -DBUILD_opencv_videoio=OFF \
  -DBUILD_opencv_videostab=OFF \
  -DBUILD_opencv_world=OFF \
  -DBUILD_opencv_ml=OFF \
  -DBUILD_opencv_photo=OFF \
  -DWITH_1394=OFF \
  -DWITH_FFMPEG=OFF \
  -DWITH_GSTREAMER=OFF \
  -DWITH_IMGCODEC_HDR=OFF \
  -DWITH_IMGCODEC_PXM=OFF \
  -DWITH_IMGCODEC_SUNRASTER=OFF \
  -DWITH_JASPER=OFF \
  -DWITH_OPENCVAMDBLAS=OFF \
  -DWITH_OPENCVAMDFFT=OFF \
  -DWITH_OPENEXR=OFF \
  -DWITH_OPENNI=OFF \
  -DWITH_OPENNI2=OFF \
  -DWITH_OPENVX=OFF \
  -DWITH_VTK=OFF \
  -DWITH_V4L=OFF \
  -DWITH_QUIRC=OFF \
  -DWITH_QT=ON \
  -DBUILD_opencv_calib3d=ON \
  -DBUILD_opencv_core=ON \
  -DBUILD_opencv_python3=ON \
  -DBUILD_opencv_flann=ON \
  -DBUILD_opencv_python_binding_generator=ON \
  -DBUILD_opencv_highgui=ON \
  -DBUILD_opencv_imgcodecs=ON \
  -DBUILD_opencv_features2d=ON \
  -DBUILD_opencv_imgproc=ON \
  -DWITH_OPENMP=ON \
  -DWITH_PNG=ON \
  -DWITH_HALIDE=OFF .. && \
  make -j6 && make install

1 Answers1

0

After a lot of investigation, I finally stumbled upon this ticket: https://gitlab.archlinux.org/archlinux/archlinux-docker/-/issues/32

The comments gave me the idea that the kernel might be the problem. I upgraded the kernel and that seemed to have resolved the problem.

Hopefully this helps someone else in the future.