-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (59 loc) · 2.69 KB
/
Copy pathDockerfile
File metadata and controls
70 lines (59 loc) · 2.69 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
ARG FINAL_IMAGE=scratch-final
# chef
FROM docker.io/library/rust:1.98.0-bookworm AS chef
RUN rustup target add x86_64-unknown-linux-musl && \
apt-get update && \
apt-get install -y --no-install-recommends musl-dev=1.2.3-1 && \
rm -rf /var/lib/apt/lists/*
RUN cargo install cargo-chef
WORKDIR /usr/src
# planner
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# Builder
FROM chef AS builder
COPY --from=planner /usr/src/recipe.json recipe.json
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
COPY . .
ARG CI_COMMIT_TAG
ARG CI_COMMIT_SHORT_SHA
RUN cargo build --release --target x86_64-unknown-linux-musl --bin ytars
# Build Python dependencies.
# NOTE: this interpreter version must match the one in the distroless
# python3-debian12 runtime below (currently CPython 3.11). Compiled extensions
# carry a cpython-3XX ABI tag, so a mismatch makes them silently unimportable
# (curl_cffi and brotli both fail this way) while yt-dlp degrades quietly.
FROM docker.io/library/python:3.11.16-slim-bookworm AS python-builder
WORKDIR /usr/src
COPY requirements.txt requirements.txt
# --target keeps pip/setuptools out of the copied tree, and --no-compile drops
# the __pycache__ trees (regenerated on first run).
RUN pip install --no-cache-dir --no-compile --target /site-packages -r requirements.txt && \
find /site-packages -name '__pycache__' -type d -prune -exec rm -rf {} +
# Deno dependency for yt-dlp
FROM docker.io/denoland/deno:bin-2.5.6 AS deno
# ffmpeg dependency for yt-dlp
FROM docker.io/library/alpine:3.23.4 AS ffmpeg
WORKDIR /
SHELL [ "/bin/ash", "-o", "pipefail", "-c" ]
RUN apk add --no-cache binutils=2.45.1-r0 && \
wget -q "https://github.com/eugeneware/ffmpeg-static/releases/download/b6.1.1/ffmpeg-linux-x64.gz" -O- | gunzip - > ffmpeg && \
strip --strip-all ./ffmpeg && \
chmod +x ./ffmpeg
# Distroless image to run Python
FROM gcr.io/distroless/python3-debian12@sha256:2fdb05402a2cf21cf78fdb3ba4c5db167241e9e498140f5bf689d7efb773731f AS python-final
COPY --from=builder /usr/src/target/x86_64-unknown-linux-musl/release/ytars /usr/bin/ytars
COPY --from=python-builder /site-packages /usr/local/lib/python3/site-packages
COPY --from=deno /deno /usr/bin/deno
COPY --from=ffmpeg /ffmpeg /usr/bin/ffmpeg
COPY download.py /usr/bin/download.py
ENV PYTHONPATH=/usr/local/lib/python3/site-packages
ENV ENABLE_YT_DLP=true
ENV YT_DLP_SCRIPT_PATH=/usr/bin/download.py
# Clean image
FROM scratch AS scratch-final
COPY --from=builder /usr/src/target/x86_64-unknown-linux-musl/release/ytars /usr/bin/ytars
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
FROM ${FINAL_IMAGE}
ENTRYPOINT [ "ytars" ]