|
| 1 | +# Version: 20250619 |
| 2 | +# musllinux-compatible build environment for OpenCV Python wheels |
| 3 | + |
| 4 | +FROM alpine:3.19 |
| 5 | + |
| 6 | +ARG CCACHE_VERSION=3.7.9 |
| 7 | +ARG FFMPEG_VERSION=5.1.6 |
| 8 | +ARG FREETYPE_VERSION=2.13.3 |
| 9 | +ARG LIBPNG_VERSION=1.6.48 |
| 10 | +ARG VPX_VERSION=v1.15.1 |
| 11 | +ARG NASM_VERSION=2.15.04 |
| 12 | +ARG OPENSSL_VERSION=1_1_1w |
| 13 | +ARG YASM_VERSION=1.3.0 |
| 14 | +ARG AOM_VERSION=v3.12.1 |
| 15 | +ARG AVIF_VERSION=v1.3.0 |
| 16 | + |
| 17 | +ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH |
| 18 | + |
| 19 | +RUN apk add --no-cache \ |
| 20 | + build-base \ |
| 21 | + diffutils \ |
| 22 | + cmake \ |
| 23 | + bash \ |
| 24 | + git \ |
| 25 | + curl \ |
| 26 | + wget \ |
| 27 | + tar \ |
| 28 | + xz \ |
| 29 | + zlib-dev \ |
| 30 | + xz-dev \ |
| 31 | + nasm \ |
| 32 | + yasm \ |
| 33 | + pkgconfig \ |
| 34 | + openssl-dev \ |
| 35 | + libjpeg-turbo-dev \ |
| 36 | + fontconfig-dev \ |
| 37 | + freetype-dev \ |
| 38 | + expat-dev \ |
| 39 | + libpng-dev \ |
| 40 | + alsa-lib-dev \ |
| 41 | + musl-dev \ |
| 42 | + linux-headers \ |
| 43 | + perl |
| 44 | + |
| 45 | +### libpng |
| 46 | +RUN mkdir ~/libpng_sources && \ |
| 47 | + cd ~/libpng_sources && \ |
| 48 | + curl -O -L https://download.sourceforge.net/libpng/libpng-${LIBPNG_VERSION}.tar.gz && \ |
| 49 | + tar -xf libpng-${LIBPNG_VERSION}.tar.gz && \ |
| 50 | + cd libpng-${LIBPNG_VERSION} && \ |
| 51 | + ./configure --prefix=/usr/local && \ |
| 52 | + make && \ |
| 53 | + make install && \ |
| 54 | + cd .. && \ |
| 55 | + rm -rf ~/libpng_sources |
| 56 | + |
| 57 | +### freetype |
| 58 | +RUN mkdir ~/freetype_sources && \ |
| 59 | + cd ~/freetype_sources && \ |
| 60 | + curl -O -L https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.gz && \ |
| 61 | + tar -xf freetype-${FREETYPE_VERSION}.tar.gz && \ |
| 62 | + cd freetype-${FREETYPE_VERSION} && \ |
| 63 | + ./configure --prefix="/ffmpeg_build" --enable-freetype-config && \ |
| 64 | + make && \ |
| 65 | + make install && \ |
| 66 | + cd .. && \ |
| 67 | + rm -rf ~/freetype_sources |
| 68 | + |
| 69 | +### OpenSSL |
| 70 | +RUN mkdir ~/openssl_sources && \ |
| 71 | + cd ~/openssl_sources && \ |
| 72 | + curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz && \ |
| 73 | + tar -xf OpenSSL_${OPENSSL_VERSION}.tar.gz && \ |
| 74 | + cd openssl-OpenSSL_${OPENSSL_VERSION} && \ |
| 75 | + ./config --prefix="/ffmpeg_build" --openssldir="/ffmpeg_build" no-pinshared shared zlib && \ |
| 76 | + make -j$(getconf _NPROCESSORS_ONLN) && \ |
| 77 | + # skip installing documentation |
| 78 | + make install_sw && \ |
| 79 | + cd .. && \ |
| 80 | + rm -rf ~/openssl_build ~/openssl_sources |
| 81 | + |
| 82 | + |
| 83 | +### NASM YASM exist in alpine |
| 84 | + |
| 85 | +### libvpx |
| 86 | +RUN mkdir ~/libvpx_sources && \ |
| 87 | + cd ~/libvpx_sources && \ |
| 88 | + git clone --depth 1 -b ${VPX_VERSION} https://chromium.googlesource.com/webm/libvpx.git && \ |
| 89 | + cd libvpx && \ |
| 90 | + ./configure --prefix="/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic --enable-shared && \ |
| 91 | + make -j$(getconf _NPROCESSORS_ONLN) && \ |
| 92 | + make install && \ |
| 93 | + cd .. && \ |
| 94 | + rm -rf ~/libvpx_sources |
| 95 | + |
| 96 | +### aom |
| 97 | +RUN mkdir ~/aom_sources && \ |
| 98 | + cd ~/aom_sources && \ |
| 99 | + git clone --depth 1 -b ${AOM_VERSION} https://aomedia.googlesource.com/aom && \ |
| 100 | + mkdir build && cd build && \ |
| 101 | + cmake -DCMAKE_C_COMPILER=$(dirname $(which g++))/gcc -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=ON -DENABLE_TESTS=OFF ../aom/ && \ |
| 102 | + make -j$(getconf _NPROCESSORS_ONLN) && \ |
| 103 | + make install && \ |
| 104 | + cd / && rm -rf ~/aom_sources |
| 105 | + |
| 106 | +### avif |
| 107 | +RUN mkdir ~/avif_sources && \ |
| 108 | + cd ~/avif_sources && \ |
| 109 | + git clone -b ${AVIF_VERSION} https://github.com/AOMediaCodec/libavif.git && \ |
| 110 | + mkdir build && cd build && \ |
| 111 | + cmake -DCMAKE_INSTALL_PREFIX=/usr -DAVIF_CODEC_AOM=SYSTEM -DAVIF_LIBYUV=LOCAL -DAVIF_BUILD_APPS=OFF ../libavif && \ |
| 112 | + make -j$(getconf _NPROCESSORS_ONLN) && \ |
| 113 | + make install && \ |
| 114 | + cd / && rm -rf ~/avif_sources |
| 115 | + |
| 116 | +### ffmpeg |
| 117 | +RUN mkdir ~/ffmpeg_sources && \ |
| 118 | + cd ~/ffmpeg_sources && \ |
| 119 | + curl -O -L https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.gz && \ |
| 120 | + tar -xf ffmpeg-${FFMPEG_VERSION}.tar.gz && \ |
| 121 | + cd ffmpeg-${FFMPEG_VERSION} && \ |
| 122 | + PATH=~/bin:$PATH && \ |
| 123 | + PKG_CONFIG_PATH="/ffmpeg_build/lib/pkgconfig" ./configure \ |
| 124 | + --prefix="/usr/local" \ |
| 125 | + --extra-cflags="-I/ffmpeg_build/include -Wno-error=array-bounds -Wno-error=unused-variable" \ |
| 126 | + --extra-ldflags="-L/ffmpeg_build/lib" \ |
| 127 | + --enable-openssl \ |
| 128 | + --enable-libvpx \ |
| 129 | + --enable-shared \ |
| 130 | + --enable-pic \ |
| 131 | + --bindir="$HOME/bin" && \ |
| 132 | + make -j$(getconf _NPROCESSORS_ONLN) && \ |
| 133 | + make install && \ |
| 134 | + echo "/ffmpeg_build/lib/" >> /etc/ld.so.conf && \ |
| 135 | + ldconfig && \ |
| 136 | + rm -rf ~/ffmpeg_sources |
| 137 | + |
| 138 | +### ccache |
| 139 | +RUN curl -O -L https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}.tar.gz && \ |
| 140 | + tar -xf ccache-${CCACHE_VERSION}.tar.gz && \ |
| 141 | + cd ccache-${CCACHE_VERSION} && \ |
| 142 | + ./configure && \ |
| 143 | + make -j$(getconf _NPROCESSORS_ONLN) && \ |
| 144 | + make install && \ |
| 145 | + cd .. && \ |
| 146 | + rm -rf ccache-${CCACHE_VERSION}.tar.gz |
| 147 | + |
| 148 | +# user`s UID is 1001 |
| 149 | +RUN adduser -D -u 1001 ci && mkdir /io && chown ci:ci /io && \ |
| 150 | + # This needs to find ffmpeg packages from ci user |
| 151 | + chown -R ci:ci /ffmpeg_build |
| 152 | + |
| 153 | +USER ci |
| 154 | +WORKDIR /io |
| 155 | + |
| 156 | +RUN git config --global --add safe.directory /io |
| 157 | +ENV PATH="/home/ci/bin:/ffmpeg_build/bin:$PATH" |
| 158 | +ENV LD_LIBRARY_PATH="/ffmpeg_build/lib:/usr/local/lib:$LD_LIBRARY_PATH" |
| 159 | +ENV PKG_CONFIG_PATH="/ffmpeg_build/lib/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" |
0 commit comments