opencv-opencv
SUCCESS
124m 15s
History Source
SummaryIterations3Transcript36Dockerfile
Dockerfile58 lines · 1632 chars
# Multi-stage build for building OpenCV-like project from source

FROM ubuntu:22.04 AS builder

ENV DEBIAN_FRONTEND=noninteractive

# Install essential build dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        build-essential cmake git python3-dev pkg-config \
        libjpeg-dev libpng-dev libtiff-dev \
        libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
    && rm -rf /var/lib/apt/lists/*

# Copy source code
WORKDIR /src
COPY . .

# Create a separate build directory and configure
RUN rm -rf build && mkdir build
WORKDIR /src/build

# Configure OpenCV build (minimal, focused on core components)
RUN cmake -D CMAKE_BUILD_TYPE=Release \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D BUILD_LIST=core,highgui,imgproc \
          -D BUILD_opencv_world=OFF \
          -D BUILD_EXAMPLES=OFF \
          -D BUILD_TESTS=OFF \
          -D BUILD_PERF_TESTS=OFF \
          -D WITH_QT=OFF \
          -D WITH_OPENGL=OFF \
          ..

# Build and install to /usr/local
RUN cmake --build . -j$(nproc) \
    && cmake --install .


FROM ubuntu:22.04 AS runtime

ENV DEBIAN_FRONTEND=noninteractive

# Install runtime dependencies (no header files)
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libjpeg-dev libpng-dev libtiff-dev \
        libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
    && rm -rf /var/lib/apt/lists/*

# Copy built artifacts from the builder stage
COPY --from=builder /usr/local /usr/local

ENV PATH="/usr/local/bin:${PATH}"

# Provide a simple check: opencv_version on startup
CMD ["opencv_version"]