diff --git a/Dockerfile b/Dockerfile index 81edfc5e5..403f5094c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,149 +1,186 @@ ARG BUILD_FROM -FROM ${BUILD_FROM} - -ARG \ - BUILD_ARCH \ - QEMU_CPU \ - SSOCR_VERSION \ - LIBCEC_VERSION \ - PICOTTS_HASH \ - TELLDUS_COMMIT - -## -# Install component packages +#### +## Builder stage for ssocr, installs to /opt/ssocr +FROM ${BUILD_FROM} AS ssocr-builder +ARG SSOCR_VERSION +ARG BUILD_FROM +WORKDIR /tmp/ +SHELL ["/bin/ash", "-o", "pipefail", "-c"] RUN \ - apk add --no-cache \ - bluez \ - bluez-deprecated \ - bluez-libs \ - curl \ - eudev-libs \ - ffmpeg \ - iperf3 \ - git \ - grep \ - hwdata-usb \ - libgpiod \ - libturbojpeg \ - libpulse \ - libzbar \ - mariadb-connector-c \ - net-tools \ - nmap \ - openssh-client \ - pianobar \ - pulseaudio-alsa \ - socat + --mount=type=cache,target=/etc/apk/cache,sharing=locked,id=apk-cache-${BUILD_FROM} \ + apk add \ + build-base \ + imlib2-dev +RUN mkdir /opt/ssocr /tmp/ssocr \ + && curl --silent --fail --location "https://github.com/auerswal/ssocr/archive/refs/tags/v${SSOCR_VERSION}.tar.gz" \ + | tar zxv -C /tmp/ssocr --strip-components 1 \ + && cd /tmp/ssocr \ + && make -j"$(nproc)" \ + && make PREFIX=/opt/ssocr install \ + && rm -rf /tmp/ssocr + #### -## Install pip module for component/homeassistant -COPY requirements.txt /usr/src/ +## Install pip module for component/homeassistant. Installs to /root/.local +FROM ${BUILD_FROM} AS pip-install-builder +ARG BUILD_FROM +WORKDIR /tmp/ +COPY requirements.txt /tmp/requirements.txt RUN \ - pip3 install --only-binary=:all: \ - -r /usr/src/requirements.txt \ - && rm -f /usr/src/requirements.txt + --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-builder-${BUILD_FROM} \ + pip3 install --user --only-binary=:all: \ + -r /tmp/requirements.txt -#### -## Build library -WORKDIR /usr/src/ -# ssocr +#### +## Builder stage for libcec, installs to /opt/libcec +FROM ${BUILD_FROM} AS libcec-builder +ARG LIBCEC_VERSION +ARG BUILD_FROM +WORKDIR /tmp/ +COPY patches/libcec-fix-null-return.patch /tmp/ +COPY patches/libcec-python313.patch /tmp/ RUN \ - apk add --no-cache \ - imlib2 \ - && apk add --no-cache --virtual .build-dependencies \ - build-base \ - imlib2-dev \ - && git clone --depth 1 -b "v${SSOCR_VERSION}" https://github.com/auerswal/ssocr \ - && cd ssocr \ - && make -j"$(nproc)" \ - && make install \ - && apk del .build-dependencies \ - && rm -rf /usr/src/ssocr - -# libcec -COPY patches/libcec-fix-null-return.patch /usr/src/ -COPY patches/libcec-python313.patch /usr/src/ -RUN apk add --no-cache \ - eudev-libs \ - p8-platform \ - && apk add --no-cache --virtual .build-dependencies \ + --mount=type=cache,target=/etc/apk/cache,sharing=locked,id=apk-cache-${BUILD_FROM} \ + apk add \ build-base \ cmake \ eudev-dev \ - swig \ - p8-platform-dev \ + git \ linux-headers \ + p8-platform-dev \ + swig +RUN python_version=$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") \ && git clone --depth 1 -b "libcec-${LIBCEC_VERSION}" https://github.com/Pulse-Eight/libcec \ && cd libcec \ && git apply ../libcec-fix-null-return.patch \ && git apply ../libcec-python313.patch \ && mkdir build \ && cd build \ - && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local \ - -DPYTHON_LIBRARY="/usr/local/lib/libpython3.13.so" \ - -DPYTHON_INCLUDE_DIR="/usr/local/include/python3.13" \ + && cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/libcec \ + -DPYTHON_LIBRARY="/usr/local/lib/libpython${python_version}.so" \ + -DPYTHON_INCLUDE_DIR="/usr/local/include/python${python_version}" \ -DHAVE_LINUX_API=1 \ .. \ && make -j"$(nproc)" \ - && make install \ - && echo "cec" > "/usr/local/lib/python3.13/site-packages/cec.pth" \ - && apk del .build-dependencies \ - && rm -rf \ - /usr/src/libcec \ - /usr/src/libcec-fix-null-return.patch \ - /usr/src/libcec-python313.patch + && make install + +# Build stage for PicoTTS, installs to /opt/picotts # PicoTTS - it has no specific version - commit should be taken from build.json -RUN apk add --no-cache \ - popt \ - && apk add --no-cache --virtual .build-dependencies \ - automake \ +FROM ${BUILD_FROM} AS picotts-builder +ARG PICOTTS_HASH +ARG BUILD_FROM +WORKDIR /tmp/ +RUN \ + --mount=type=cache,target=/etc/apk/cache,sharing=locked,id=apk-cache-${BUILD_FROM} \ + apk add \ autoconf \ - libtool \ - popt-dev \ + automake \ build-base \ - && git clone https://github.com/naggety/picotts.git pico \ + git \ + libtool \ + popt-dev +RUN git clone https://github.com/naggety/picotts.git pico \ && cd pico/pico \ && git reset --hard "${PICOTTS_HASH}" \ && ./autogen.sh \ + && mkdir /opt/picotts \ && ./configure \ --disable-static \ + --prefix=/opt/picotts \ && make \ - && make install \ - && apk del .build-dependencies \ - && rm -rf /usr/src/pico + && make install -# Telldus -COPY patches/telldus-fix-gcc-11-issues.patch /usr/src/ -COPY patches/telldus-fix-alpine-3-17-issues.patch /usr/src/ + +# Build stage for Telldus, installs to /opt/telldus +FROM ${BUILD_FROM} AS telldus-builder +ARG TELLDUS_COMMIT +ARG BUILD_FROM +WORKDIR /tmp/ +COPY patches/telldus-fix-gcc-11-issues.patch /tmp/ +COPY patches/telldus-fix-alpine-3-17-issues.patch /tmp/ RUN \ - apk add --no-cache \ - confuse \ - libftdi1 \ - && apk add --no-cache --virtual .build-dependencies \ + --mount=type=cache,target=/etc/apk/cache,sharing=locked,id=apk-cache-${BUILD_FROM} \ + apk add \ argp-standalone \ build-base \ cmake \ confuse-dev \ doxygen \ - libftdi1-dev \ - && git clone https://github.com/telldus/telldus \ + git \ + libftdi1-dev +RUN git clone https://github.com/telldus/telldus \ && cd telldus \ && git reset --hard "${TELLDUS_COMMIT}" \ && git apply ../telldus-fix-gcc-11-issues.patch \ && git apply ../telldus-fix-alpine-3-17-issues.patch \ && cd telldus-core \ + && mkdir /opt/telldus \ && cmake . -DBUILD_LIBTELLDUS-CORE=ON \ -DBUILD_TDADMIN=OFF -DBUILD_TDTOOL=OFF -DGENERATE_MAN=OFF \ -DFORCE_COMPILE_FROM_TRUNK=ON \ + -DCMAKE_INSTALL_PREFIX:PATH=/opt/telldus \ && make -j"$(nproc)" \ - && make install \ - && apk del .build-dependencies \ - && rm -rf \ - /usr/src/telldus \ - /usr/src/telldus-fix-gcc-11-issues.patch \ - /usr/src/telldus-fix-alpine-3-17-issues.patch + && make install + + +FROM ${BUILD_FROM} + +ARG BUILD_ARCH +ARG QEMU_CPU +ARG BUILD_FROM + +## +# Install component packages +RUN \ + --mount=type=cache,target=/etc/apk/cache,sharing=locked,id=apk-cache-${BUILD_FROM} \ + apk add \ + bluez \ + bluez-deprecated \ + bluez-libs \ + confuse \ + curl \ + eudev-libs \ + ffmpeg \ + grep \ + hwdata-usb \ + imlib2 \ + iperf3 \ + libftdi1 \ + libgpiod \ + libpulse \ + libturbojpeg \ + libzbar \ + mariadb-connector-c \ + net-tools \ + nmap \ + openssh-client \ + p8-platform \ + pianobar \ + popt \ + pulseaudio-alsa \ + socat + +WORKDIR /usr/src/ + +#### +## Copy from pip builder +COPY --link --from=pip-install-builder /root/.local/ /root/.local/ + +# Copy from ssocr builder +COPY --link --from=ssocr-builder /opt/ssocr/ /usr/local/ + +# Copy from libcec builder +COPY --link --from=libcec-builder /opt/libcec/ /usr/local/ +RUN python_version=$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") \ + && echo "cec" > "/usr/local/lib/python${python_version}/site-packages/cec.pth" + +# Copy from picotts builder +COPY --link --from=picotts-builder /opt/picotts/ /usr/local/ + +# Copy from Telldus builder +COPY --link --from=telldus-builder /opt/telldus/ /usr/local/ ### # Base S6-Overlay