Docker multi-architecture, .NET 6.0 and OpenCVSharp

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • OpenCvSharp

    OpenCV wrapper for .NET

  • FROM debian:bullseye-slim AS build-native-env ARG TARGETPLATFORM ENV DEBIAN_FRONTEND=noninteractive # 4.5.5: released 25 Dec 2021 ENV OPENCV_VERSION=4.5.5 # 4.5.3.20211228: released 28 Dec 2021 ENV OPENCVSHARP_VERSION=4.5.3.20211228 WORKDIR / # install dependencies required for building OpenCV and OpenCvSharpExtern RUN apt-get update && apt-get -y install --no-install-recommends \ # details omitted \ libgdiplus # Get OpenCV and opencv-contrib sources using the specified release. RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ unzip ${OPENCV_VERSION}.zip && \ rm ${OPENCV_VERSION}.zip && \ mv opencv-${OPENCV_VERSION} opencv RUN wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \ unzip ${OPENCV_VERSION}.zip && \ rm ${OPENCV_VERSION}.zip && \ mv opencv_contrib-${OPENCV_VERSION} opencv_contrib # configure and build OpenCV optionally specifying architecture related cmake options. RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ ADDITIONAL_FLAGS='' ; \ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ ADDITIONAL_FLAGS='-D ENABLE_NEON=ON -D CPU_BASELINE=NEON ' ; \ elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ ADDITIONAL_FLAGS='-D CPU_BASELINE=NEON -D ENABLE_NEON=ON ' ; \ fi && cd opencv && mkdir build && cd build && \ cmake $ADDITIONAL_FLAGS \ # additional flags omitted for clarity \ && make -j$(nproc) \ && make install \ && ldconfig # Download OpenCvSharp to build OpenCvSharpExtern native library RUN git clone https://github.com/shimat/opencvsharp.git RUN cd opencvsharp && git fetch --all --tags --prune && git checkout ${OPENCVSHARP_VERSION} WORKDIR /opencvsharp/src RUN mkdir /opencvsharp/make \ && cd /opencvsharp/make \ && cmake -D CMAKE_INSTALL_PREFIX=/opencvsharp/make /opencvsharp/src \ && make -j$(nproc) \ && make install \ && cp /opencvsharp/make/OpenCvSharpExtern/libOpenCvSharpExtern.so /usr/lib/ \ && ldconfig # Copy the library and dependencies to /artifacts (to be used by images consuming this build) # cpld.sh will copy the library we specify (./libOpenCvSharpExtern.so) and any dependencies # to the /artifacts directory. This is useful for sharing the library with other images # consuming this build. # credits: Hemanth.HM -> https://h3manth.com/content/copying-shared-library-dependencies WORKDIR /opencvsharp/make/OpenCvSharpExtern COPY cpld.sh . RUN chmod +x cpld.sh && \ mkdir /artifacts && \ ./cpld.sh ./libOpenCvSharpExtern.so /artifacts/ RUN cp ./libOpenCvSharpExtern.so /artifacts/ # Publish the artefacts using a clean image FROM debian:bullseye-slim AS final RUN mkdir /artifacts COPY --from=build-native-env /artifacts/ /artifacts WORKDIR /artifacts

  • docker-multi-arch-opencvsharp

    A demonstration of Docker multi architecture build for native dependencies for amd64, amrm64 and arm32 architecture

  • Build and push images build using the multi processor architecture.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • OpenCV

    Open Source Computer Vision Library

  • FROM debian:bullseye-slim AS build-native-env ARG TARGETPLATFORM ENV DEBIAN_FRONTEND=noninteractive # 4.5.5: released 25 Dec 2021 ENV OPENCV_VERSION=4.5.5 # 4.5.3.20211228: released 28 Dec 2021 ENV OPENCVSHARP_VERSION=4.5.3.20211228 WORKDIR / # install dependencies required for building OpenCV and OpenCvSharpExtern RUN apt-get update && apt-get -y install --no-install-recommends \ # details omitted \ libgdiplus # Get OpenCV and opencv-contrib sources using the specified release. RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ unzip ${OPENCV_VERSION}.zip && \ rm ${OPENCV_VERSION}.zip && \ mv opencv-${OPENCV_VERSION} opencv RUN wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \ unzip ${OPENCV_VERSION}.zip && \ rm ${OPENCV_VERSION}.zip && \ mv opencv_contrib-${OPENCV_VERSION} opencv_contrib # configure and build OpenCV optionally specifying architecture related cmake options. RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ ADDITIONAL_FLAGS='' ; \ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ ADDITIONAL_FLAGS='-D ENABLE_NEON=ON -D CPU_BASELINE=NEON ' ; \ elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ ADDITIONAL_FLAGS='-D CPU_BASELINE=NEON -D ENABLE_NEON=ON ' ; \ fi && cd opencv && mkdir build && cd build && \ cmake $ADDITIONAL_FLAGS \ # additional flags omitted for clarity \ && make -j$(nproc) \ && make install \ && ldconfig # Download OpenCvSharp to build OpenCvSharpExtern native library RUN git clone https://github.com/shimat/opencvsharp.git RUN cd opencvsharp && git fetch --all --tags --prune && git checkout ${OPENCVSHARP_VERSION} WORKDIR /opencvsharp/src RUN mkdir /opencvsharp/make \ && cd /opencvsharp/make \ && cmake -D CMAKE_INSTALL_PREFIX=/opencvsharp/make /opencvsharp/src \ && make -j$(nproc) \ && make install \ && cp /opencvsharp/make/OpenCvSharpExtern/libOpenCvSharpExtern.so /usr/lib/ \ && ldconfig # Copy the library and dependencies to /artifacts (to be used by images consuming this build) # cpld.sh will copy the library we specify (./libOpenCvSharpExtern.so) and any dependencies # to the /artifacts directory. This is useful for sharing the library with other images # consuming this build. # credits: Hemanth.HM -> https://h3manth.com/content/copying-shared-library-dependencies WORKDIR /opencvsharp/make/OpenCvSharpExtern COPY cpld.sh . RUN chmod +x cpld.sh && \ mkdir /artifacts && \ ./cpld.sh ./libOpenCvSharpExtern.so /artifacts/ RUN cp ./libOpenCvSharpExtern.so /artifacts/ # Publish the artefacts using a clean image FROM debian:bullseye-slim AS final RUN mkdir /artifacts COPY --from=build-native-env /artifacts/ /artifacts WORKDIR /artifacts

  • opencv_contrib

    Repository for OpenCV's extra modules

  • FROM debian:bullseye-slim AS build-native-env ARG TARGETPLATFORM ENV DEBIAN_FRONTEND=noninteractive # 4.5.5: released 25 Dec 2021 ENV OPENCV_VERSION=4.5.5 # 4.5.3.20211228: released 28 Dec 2021 ENV OPENCVSHARP_VERSION=4.5.3.20211228 WORKDIR / # install dependencies required for building OpenCV and OpenCvSharpExtern RUN apt-get update && apt-get -y install --no-install-recommends \ # details omitted \ libgdiplus # Get OpenCV and opencv-contrib sources using the specified release. RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ unzip ${OPENCV_VERSION}.zip && \ rm ${OPENCV_VERSION}.zip && \ mv opencv-${OPENCV_VERSION} opencv RUN wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \ unzip ${OPENCV_VERSION}.zip && \ rm ${OPENCV_VERSION}.zip && \ mv opencv_contrib-${OPENCV_VERSION} opencv_contrib # configure and build OpenCV optionally specifying architecture related cmake options. RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ ADDITIONAL_FLAGS='' ; \ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ ADDITIONAL_FLAGS='-D ENABLE_NEON=ON -D CPU_BASELINE=NEON ' ; \ elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ ADDITIONAL_FLAGS='-D CPU_BASELINE=NEON -D ENABLE_NEON=ON ' ; \ fi && cd opencv && mkdir build && cd build && \ cmake $ADDITIONAL_FLAGS \ # additional flags omitted for clarity \ && make -j$(nproc) \ && make install \ && ldconfig # Download OpenCvSharp to build OpenCvSharpExtern native library RUN git clone https://github.com/shimat/opencvsharp.git RUN cd opencvsharp && git fetch --all --tags --prune && git checkout ${OPENCVSHARP_VERSION} WORKDIR /opencvsharp/src RUN mkdir /opencvsharp/make \ && cd /opencvsharp/make \ && cmake -D CMAKE_INSTALL_PREFIX=/opencvsharp/make /opencvsharp/src \ && make -j$(nproc) \ && make install \ && cp /opencvsharp/make/OpenCvSharpExtern/libOpenCvSharpExtern.so /usr/lib/ \ && ldconfig # Copy the library and dependencies to /artifacts (to be used by images consuming this build) # cpld.sh will copy the library we specify (./libOpenCvSharpExtern.so) and any dependencies # to the /artifacts directory. This is useful for sharing the library with other images # consuming this build. # credits: Hemanth.HM -> https://h3manth.com/content/copying-shared-library-dependencies WORKDIR /opencvsharp/make/OpenCvSharpExtern COPY cpld.sh . RUN chmod +x cpld.sh && \ mkdir /artifacts && \ ./cpld.sh ./libOpenCvSharpExtern.so /artifacts/ RUN cp ./libOpenCvSharpExtern.so /artifacts/ # Publish the artefacts using a clean image FROM debian:bullseye-slim AS final RUN mkdir /artifacts COPY --from=build-native-env /artifacts/ /artifacts WORKDIR /artifacts

  • dotnet-docker

    Docker images for .NET and the .NET Tools.

  • ARG OPENCV_SHARP_BUILD_TAG=2 ARG SDK_VERSION=6.0.202-bullseye-slim-amd64 ARG RUNTIME_VERSION=6.0.4-bullseye-slim FROM syamaner/opencvsharp-build:$OPENCV_SHARP_BUILD_TAG AS opencv # Given we are building a .Net application, the build does not have to be in the target architecture. # Reference: https://github.com/dotnet/dotnet-docker/issues/1537#issuecomment-755351628 FROM mcr.microsoft.com/dotnet/sdk:$SDK_VERSION as build ARG TARGETPLATFORM WORKDIR /src COPY . . # Select the correct RID for the target architecture. # run dotnet publish as usual and pass the RID. RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ RID=linux-x64 ; \ elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ RID=linux-arm64 ; \ elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ RID=linux-arm ; \ fi && \ dotnet publish -c release -o /app -r $RID --self-contained false # Copy the application as well as native dependencies to the final stage and build the final image without any unnecessary files. FROM mcr.microsoft.com/dotnet/runtime:$RUNTIME_VERSION as final WORKDIR /app # Copy opencv sharp native binding and runtime dependencies. COPY --from=opencv /artifacts/ /usr/lib/ RUN ldconfig COPY --from=build /app/ /app/ ENTRYPOINT [ "dotnet", "/app/OpenCVSharpBenchmarkApp.dll" ]

  • BenchmarkDotNet

    Powerful .NET library for benchmarking

  • In order to test compatibility with the target devices / platforms, a basic benchmark application has been built using BenchmarkDotNet

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts