|
1 | | -# Dockerfile |
| 1 | +# Use Docker BuildKit syntax v1.3+ for multi‐arch args |
| 2 | +# syntax=docker/dockerfile:1.3 |
| 3 | + |
| 4 | +######################################## |
| 5 | +# 1. Builder stage: install deps & FFmpeg |
| 6 | +######################################## |
2 | 7 | FROM python:3.10-slim AS builder |
3 | 8 |
|
4 | | -# Install deps for ffmpeg extraction |
| 9 | +# Declare the build platform variable |
| 10 | +ARG TARGETPLATFORM |
| 11 | + |
| 12 | +# Install tools for download & extraction |
5 | 13 | RUN apt-get update \ |
6 | | - && apt-get install -y --no-install-recommends \ |
7 | | - curl xz-utils \ |
8 | | - && rm -rf /var/lib/apt/lists/* |
| 14 | + && apt-get install -y --no-install-recommends \ |
| 15 | + curl xz-utils ca-certificates \ |
| 16 | + && rm -rf /var/lib/apt/lists/* |
9 | 17 |
|
10 | | -# Pick up code |
11 | 18 | WORKDIR /home/ffapi/app |
12 | | -COPY requirements.txt ./ |
13 | | -RUN pip install --no-cache-dir -r requirements.txt |
| 19 | + |
| 20 | +# Python deps |
| 21 | +COPY requirements.txt . |
| 22 | +RUN python -m pip install --upgrade pip \ |
| 23 | + && pip install --no-cache-dir -r requirements.txt |
14 | 24 |
|
15 | 25 | COPY . . |
16 | 26 |
|
17 | | -# Download BtbN static FFmpeg build per architecture |
18 | | -# BuildKit will set TARGETPLATFORM, so we can choose the correct binary |
| 27 | +# Download & extract correct FFmpeg build |
19 | 28 | RUN set -eux; \ |
20 | 29 | case "${TARGETPLATFORM}" in \ |
21 | 30 | "linux/amd64") ARCH="amd64" ;; \ |
22 | 31 | "linux/arm64") ARCH="arm64" ;; \ |
23 | 32 | *) echo "Unsupported platform ${TARGETPLATFORM}" >&2; exit 1 ;; \ |
24 | 33 | esac; \ |
25 | | - FFBIN="ffmpeg-git-${ARCH}-static.tar.xz"; \ |
26 | | - echo "Downloading ${FFBIN}"; \ |
27 | | - curl -L \ |
28 | | - "https://github.com/BtbN/FFmpeg-Builds/releases/latest/download/${FFBIN}" \ |
29 | | - -o /tmp/${FFBIN}; \ |
30 | | - tar -xJf /tmp/${FFBIN} -C /usr/local/bin --strip-components=1; \ |
31 | | - rm /tmp/${FFBIN} |
32 | | - |
33 | | -# Runtime image |
| 34 | + URL="https://github.com/BtbN/FFmpeg-Builds/releases/latest/download/ffmpeg-git-${ARCH}-static.tar.xz"; \ |
| 35 | + echo "Downloading FFmpeg from ${URL}"; \ |
| 36 | + curl -fL "${URL}" -o /tmp/ffmpeg.tar.xz; \ |
| 37 | + mkdir -p /tmp/ffmpeg; \ |
| 38 | + tar -xJf /tmp/ffmpeg.tar.xz -C /tmp/ffmpeg --strip-components=1; \ |
| 39 | + install -m755 /tmp/ffmpeg/ffmpeg /usr/local/bin/ffmpeg; \ |
| 40 | + install -m755 /tmp/ffmpeg/ffprobe /usr/local/bin/ffprobe; \ |
| 41 | + install -m755 /tmp/ffmpeg/ffplay /usr/local/bin/ffplay; \ |
| 42 | + rm -rf /tmp/ffmpeg /tmp/ffmpeg.tar.xz |
| 43 | + |
| 44 | +######################################## |
| 45 | +# 2. Runtime stage |
| 46 | +######################################## |
34 | 47 | FROM python:3.10-slim |
35 | 48 |
|
36 | 49 | RUN useradd -m ffapi |
37 | 50 |
|
38 | 51 | WORKDIR /home/ffapi/app |
39 | 52 |
|
40 | | -# copy ffmpeg binaries + Python deps + app code |
41 | | -COPY --from=builder /usr/local/bin/ffmpeg /usr/local/bin/ffmpeg |
| 53 | +# Copy over static FFmpeg binaries |
| 54 | +COPY --from=builder /usr/local/bin/ffmpeg /usr/local/bin/ffmpeg |
42 | 55 | COPY --from=builder /usr/local/bin/ffprobe /usr/local/bin/ffprobe |
43 | | -COPY --from=builder /usr/local/bin/ffplay /usr/local/bin/ffplay |
44 | | -# (VMAF binary if needed—you can optionally download it similarly) |
| 56 | +COPY --from=builder /usr/local/bin/ffplay /usr/local/bin/ffplay |
| 57 | + |
| 58 | +# Copy Python packages |
45 | 59 | COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages |
46 | 60 |
|
| 61 | +# Copy application code |
47 | 62 | COPY . . |
48 | 63 |
|
49 | | -# Ensure our ffapi user owns everything |
50 | 64 | RUN chown -R ffapi:ffapi /home/ffapi/app |
51 | 65 |
|
52 | 66 | USER ffapi |
|
0 commit comments