Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
146 lines (132 loc) · 8.29 KB
/
Copy pathDockerfile
File metadata and controls
146 lines (132 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Fully-static, audio-focused FFmpeg built from pinned upstream source.
#
# A fully-static binary (no ELF interpreter) runs on BOTH musl (Alpine) and
# glibc (Debian/Ubuntu) — which is what our consumers need (hotio/lidarr and
# beatscheck are Alpine/musl). Everything is compiled from official source at
# pinned versions with SHA-256-verified tarballs, so the trust boundary is
# upstream source + this script only — no third-party binaries.
#
# LGPL: only LGPL/BSD audio libraries are linked (no --enable-gpl, no x264/x265),
# so the result is LGPL-3.0-or-later.
# Pinned by digest (multi-arch manifest) so a moved 'alpine:3.21' tag can't
# inject anything. Renovate keeps the digest current.
FROM alpine:3.24@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf AS build
# Pinned upstream versions.
ARG FFMPEG_TAG=n8.1.2
# Optional integrity guard: the commit FFMPEG_COMMIT is the one FFMPEG_COMMIT_TAG
# resolves to. The check below only enforces it when building that exact tag, so
# mirror.yml's resolve job (or Renovate) can bump FFMPEG_TAG to ANY newer release
# and the build proceeds — auto-updates above n8.1.2 keep flowing.
ARG FFMPEG_COMMIT=38b88335f99e76ed89ff3c93f877fdefce736c13
ARG FFMPEG_COMMIT_TAG=n8.1.2
# Renovate bumps these; codec-checksums.yml then rewrites the matching *_SHA256 below.
# renovate: datasource=repology depName=alpine_edge/lame versioning=loose extractVersion=^(?<version>[^-]+)
ARG LAME_VERSION=3.100
# renovate: datasource=github-tags depName=xiph/ogg extractVersion=^v(?<version>\d+\.\d+(?:\.\d+)?)$
ARG OGG_VERSION=1.3.6
# renovate: datasource=github-tags depName=xiph/vorbis extractVersion=^v(?<version>\d+\.\d+(?:\.\d+)?)$
ARG VORBIS_VERSION=1.3.7
# renovate: datasource=github-tags depName=xiph/opus extractVersion=^v(?<version>\d+\.\d+(?:\.\d+)?)$
ARG OPUS_VERSION=1.6.1
# renovate: datasource=repology depName=alpine_edge/opencore-amr versioning=loose extractVersion=^(?<version>[^-]+)
ARG OPENCORE_AMR_VERSION=0.1.6
# SHA-256 of each source tarball (verified before building).
ARG LAME_SHA256=ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e
ARG OGG_SHA256=5c8253428e181840cd20d41f3ca16557a9cc04bad4a3d04cce84808677fa1061
ARG VORBIS_SHA256=b33cc4934322bcbf6efcbacf49e3ca01aadbea4114ec9589d1b1e9d20f72954b
ARG OPUS_SHA256=6ffcb593207be92584df15b32466ed64bbec99109f007c82205f0194572411a1
ARG OPENCORE_AMR_SHA256=483eb4061088e2b34b358e47540b5d495a96cd468e361050fae615b1809dc4a1
RUN apk add --no-cache \
build-base cmake nasm yasm pkgconf git curl tar xz \
autoconf automake libtool
ENV PREFIX=/opt/ffbuild
ENV PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
WORKDIR /src
# Helper: download a tarball, verify its SHA-256, extract it.
# Usage handled inline per-library below.
# --- libmp3lame (LGPL) — MP3 encoding ---
RUN curl -fsSL --retry 5 --retry-delay 2 --retry-all-errors "https://downloads.sourceforge.net/project/lame/lame/${LAME_VERSION}/lame-${LAME_VERSION}.tar.gz" -o lame.tar.gz \
&& echo "${LAME_SHA256} lame.tar.gz" | sha256sum -c - \
&& tar xf lame.tar.gz && cd "lame-${LAME_VERSION}" \
&& ./configure --prefix="${PREFIX}" --enable-static --disable-shared --disable-frontend \
&& make -j"$(nproc)" && make install
# --- libogg (BSD) — container for Vorbis ---
RUN curl -fsSL --retry 5 --retry-delay 2 --retry-all-errors "https://downloads.xiph.org/releases/ogg/libogg-${OGG_VERSION}.tar.xz" -o ogg.tar.xz \
&& echo "${OGG_SHA256} ogg.tar.xz" | sha256sum -c - \
&& tar xf ogg.tar.xz && cd "libogg-${OGG_VERSION}" \
&& ./configure --prefix="${PREFIX}" --enable-static --disable-shared \
&& make -j"$(nproc)" && make install
# --- libvorbis (BSD) — Vorbis encoding ---
RUN curl -fsSL --retry 5 --retry-delay 2 --retry-all-errors "https://downloads.xiph.org/releases/vorbis/libvorbis-${VORBIS_VERSION}.tar.xz" -o vorbis.tar.xz \
&& echo "${VORBIS_SHA256} vorbis.tar.xz" | sha256sum -c - \
&& tar xf vorbis.tar.xz && cd "libvorbis-${VORBIS_VERSION}" \
&& ./configure --prefix="${PREFIX}" --enable-static --disable-shared \
&& make -j"$(nproc)" && make install
# --- libopus (BSD) — Opus encoding/decoding ---
RUN curl -fsSL --retry 5 --retry-delay 2 --retry-all-errors "https://downloads.xiph.org/releases/opus/opus-${OPUS_VERSION}.tar.gz" -o opus.tar.gz \
&& echo "${OPUS_SHA256} opus.tar.gz" | sha256sum -c - \
&& tar xf opus.tar.gz && cd "opus-${OPUS_VERSION}" \
&& ./configure --prefix="${PREFIX}" --enable-static --disable-shared \
&& make -j"$(nproc)" && make install
# --- opencore-amr (Apache-2.0) — AMR-NB encoding (Sleezer AMR target) ---
RUN curl -fsSL --retry 5 --retry-delay 2 --retry-all-errors "https://downloads.sourceforge.net/opencore-amr/opencore-amr-${OPENCORE_AMR_VERSION}.tar.gz" -o amr.tar.gz \
&& echo "${OPENCORE_AMR_SHA256} amr.tar.gz" | sha256sum -c - \
&& tar xf amr.tar.gz && cd "opencore-amr-${OPENCORE_AMR_VERSION}" \
&& ./configure --prefix="${PREFIX}" --enable-static --disable-shared \
&& make -j"$(nproc)" && make install
# --- FFmpeg (LGPL) — pinned release tag from the official repo ---
RUN git clone --depth 1 --branch "${FFMPEG_TAG}" https://github.com/FFmpeg/FFmpeg.git ffmpeg \
&& cd ffmpeg \
&& if [ -n "${FFMPEG_COMMIT}" ] && [ "${FFMPEG_TAG}" = "${FFMPEG_COMMIT_TAG}" ]; then \
got="$(git rev-parse HEAD)"; \
[ "$got" = "${FFMPEG_COMMIT}" ] \
|| { echo "FFmpeg tag ${FFMPEG_TAG} resolved to $got, expected ${FFMPEG_COMMIT}" >&2; exit 1; }; \
fi \
&& ./configure \
--prefix="${PREFIX}" \
--pkg-config-flags=--static \
--extra-cflags="-I${PREFIX}/include" \
--extra-ldflags="-L${PREFIX}/lib -static" \
--extra-libs="-lm" \
--enable-static --disable-shared \
--disable-debug --disable-doc --disable-ffplay \
--enable-version3 \
--enable-libmp3lame --enable-libopus --enable-libvorbis \
--enable-libopencore-amrnb --enable-libopencore-amrwb \
&& make -j"$(nproc)" \
&& make install \
&& strip "${PREFIX}/bin/ffmpeg" "${PREFIX}/bin/ffprobe"
# --- Self-test on a CLEAN Alpine (musl, no build deps): proves the binary is
# fully static and actually runs with nothing else installed. ---
FROM alpine:3.24@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf AS test
# The digest-pinned base lags Alpine's package fixes, and mirror.yml gates the
# release on a scan of this image. Test stage only — nothing here ships.
RUN apk upgrade --no-cache
COPY --from=build /opt/ffbuild/bin/ffmpeg /opt/ffbuild/bin/ffprobe /usr/local/bin/
# Portability is asserted structurally rather than through file(1)'s wording: a
# binary that needs no loader has no INTERP segment and no NEEDED entries. A
# static-pie build keeps a PT_DYNAMIC segment to relocate itself, so NEEDED — not
# the mere presence of a dynamic section — is what separates it from a dynamic
# build. Capturing readelf's output means a readelf failure aborts under set -e
# instead of reading as "nothing found, must be static".
RUN set -eux; \
apk add --no-cache binutils >/dev/null; \
for b in /usr/local/bin/ffmpeg /usr/local/bin/ffprobe; do \
hdr=$(readelf -lW "$b"); \
case "$hdr" in *INTERP*) echo "$b needs a dynamic loader"; exit 1;; esac; \
dyn=$(readelf -dW "$b"); \
case "$dyn" in *NEEDED*) echo "$b has dynamic dependencies"; exit 1;; esac; \
done; \
ffmpeg -hide_banner -version | head -1; \
ffprobe -hide_banner -version | head -1; \
ffmpeg -hide_banner -f lavfi -i "sine=frequency=440:duration=1" -c:a libopus /tmp/o.opus -y >/dev/null 2>&1; \
ffmpeg -hide_banner -f lavfi -i "sine=frequency=440:duration=1" -c:a libmp3lame /tmp/o.mp3 -y >/dev/null 2>&1; \
ffmpeg -hide_banner -f lavfi -i "sine=frequency=440:duration=1" -c:a flac /tmp/o.flac -y >/dev/null 2>&1; \
ffmpeg -hide_banner -f lavfi -i "sine=frequency=440:duration=1" -c:a alac /tmp/o.m4a -y >/dev/null 2>&1; \
ffmpeg -hide_banner -f lavfi -i "sine=frequency=440:duration=1" -c:a aac /tmp/o.aac -y >/dev/null 2>&1; \
ffmpeg -hide_banner -f lavfi -i "sine=frequency=440:duration=1" -ar 8000 -ac 1 -c:a libopencore_amrnb -b:a 12.2k /tmp/o.amr -y >/dev/null 2>&1; \
ffmpeg -v error -xerror -nostdin -i /tmp/o.flac -map 0:a -f null -; \
echo "STATIC + RUNS-ON-MUSL + ENCODE(opus/mp3/flac/alac/aac/amrnb)/DECODE OK"
# --- Export stage: raw binaries only, for `--output type=local`. ---
FROM scratch AS export
COPY --from=build /opt/ffbuild/bin/ffmpeg /opt/ffbuild/bin/ffprobe /