generated from jim60105/Containerfile-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rewrite Dockerfiles and update README.md for efficiency
- Removed the compress stage from Dockerfile and instead utilized a pre-compressed ffmpeg package from ghcr.io repository. - Updated various Dockerfiles to use yt-dlp version 2024.04.09 from the previous version. - Switched all Dockerfiles to `ghcr.io/jim60105/static-ffmpeg-upx:7.0-1` for `ffmpeg`, `ffprobe`, and `dumb-init`, previously it used `mwader/static-ffmpeg`. - Reordered some sections in `README.md`. - Added image description and metadata labels to Dockerfiles. - In Dockerfiles, added more cleanup steps after installing packages using pip to reduce the image size. - Changed directory permissions in Dockerfiles and added `/licenses` for license files. - In Dockerfiles, replaced binary files effective permissions to 775 from 774. Signed-off-by: 陳鈞 <[email protected]>
- Loading branch information
Showing
5 changed files
with
191 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,94 @@ | ||
# syntax=docker/dockerfile:1 | ||
ARG UID=1001 | ||
ARG BUILD_VERSION=2023.12.30 | ||
ARG VERSION=2024.04.09 | ||
ARG RELEASE=0 | ||
|
||
######################################## | ||
# Build stage | ||
######################################## | ||
FROM python:3.12-alpine as build | ||
|
||
# RUN mount cache for multi-arch: https://github.com/docker/buildx/issues/549#issuecomment-1788297892 | ||
ARG TARGETARCH | ||
ARG TARGETVARIANT | ||
|
||
ARG BUILD_VERSION | ||
|
||
WORKDIR /app | ||
|
||
# Install under /root/.local | ||
ENV PIP_USER="true" | ||
ARG PIP_NO_WARN_SCRIPT_LOCATION=0 | ||
ARG PIP_ROOT_USER_ACTION="ignore" | ||
ARG PIP_NO_COMPILE="true" | ||
ARG PIP_DISABLE_PIP_VERSION_CHECK="true" | ||
|
||
ARG VERSION | ||
RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/pip \ | ||
pip3.12 install yt-dlp==$BUILD_VERSION && \ | ||
pip3.12 install -U --force-reinstall pip setuptools wheel && \ | ||
pip3.12 install yt-dlp==$VERSION && \ | ||
# Cleanup | ||
find "/root/.local" -name '*.pyc' -print0 | xargs -0 rm -f || true ; \ | ||
find "/root/.local" -type d -name '__pycache__' -print0 | xargs -0 rm -rf || true ; | ||
|
||
######################################## | ||
# Final stage | ||
######################################## | ||
FROM python:3.12-alpine as final | ||
|
||
ARG UID | ||
|
||
RUN pip3.12 uninstall -y setuptools pip wheel && \ | ||
rm -rf /root/.cache/pip | ||
|
||
# Use dumb-init to handle signals | ||
RUN apk add -u --no-cache dumb-init | ||
# Create user | ||
ARG UID | ||
RUN adduser -H -g "" -D $UID -u $UID -G root | ||
|
||
# ffmpeg (6.1 is broken, so override it) | ||
COPY --link --from=mwader/static-ffmpeg:6.1.1 /ffmpeg /usr/bin/ | ||
COPY --link --from=mwader/static-ffmpeg:6.1.1 /ffprobe /usr/bin/ | ||
# Create directories with correct permissions | ||
RUN install -d -m 775 -o $UID -g 0 /download && \ | ||
install -d -m 775 -o $UID -g 0 /licenses | ||
|
||
# Create user | ||
RUN addgroup -g $UID $UID && \ | ||
adduser -g "" -D $UID -u $UID -G $UID | ||
# ffmpeg | ||
COPY --link --from=ghcr.io/jim60105/static-ffmpeg-upx:7.0-1 /ffmpeg /usr/bin/ | ||
COPY --link --from=ghcr.io/jim60105/static-ffmpeg-upx:7.0-1 /ffprobe /usr/bin/ | ||
|
||
# dumb-init | ||
COPY --link --from=ghcr.io/jim60105/static-ffmpeg-upx:7.0-1 /dumb-init /usr/bin/ | ||
|
||
# Copy licenses (OpenShift Policy) | ||
COPY --link --chown=$UID:0 --chmod=775 LICENSE /licenses/Dockerfile.LICENSE | ||
COPY --link --chown=$UID:0 --chmod=775 yt-dlp/LICENSE /licenses/yt-dlp.LICENSE | ||
|
||
# Copy dist and support arbitrary user ids (OpenShift best practice) | ||
# https://docs.openshift.com/container-platform/4.14/openshift_images/create-images.html#use-uid_create-images | ||
COPY --chown=$UID:0 --chmod=774 \ | ||
--from=build /root/.local /home/$UID/.local | ||
COPY --link --chown=$UID:0 --chmod=775 --from=build /root/.local /home/$UID/.local | ||
|
||
ENV PATH="/home/$UID/.local/bin:$PATH" | ||
|
||
# Remove these to prevent the container from executing arbitrary commands | ||
RUN rm /bin/echo /bin/ln /bin/rm /bin/sh | ||
|
||
# Run as non-root user | ||
USER $UID | ||
WORKDIR /download | ||
|
||
VOLUME [ "/download" ] | ||
|
||
USER $UID | ||
|
||
STOPSIGNAL SIGINT | ||
|
||
# Use dumb-init as PID 1 to handle signals properly | ||
ENTRYPOINT [ "dumb-init", "--", "yt-dlp", "--no-cache-dir" ] | ||
CMD ["--help"] | ||
CMD ["--help"] | ||
|
||
ARG VERSION | ||
ARG RELEASE | ||
LABEL name="jim60105/docker-yt-dlp" \ | ||
# Authors for yt-dlp | ||
vendor="yt-dlp" \ | ||
# Maintainer for this docker image | ||
maintainer="jim60105" \ | ||
# Dockerfile source repository | ||
url="https://github.com/jim60105/docker-yt-dlp" \ | ||
version=${VERSION} \ | ||
# This should be a number, incremented with each change | ||
release=${RELEASE} \ | ||
io.k8s.display-name="yt-dlp" \ | ||
summary="yt-dlp: A feature-rich command-line audio/video downloader." \ | ||
description="yt-dlp is a feature-rich command-line audio/video downloader with support for thousands of sites. The project is a fork of youtube-dl based on the now inactive youtube-dlc. For more information about this tool, please visit the following website: https://github.com/yt-dlp/yt-dlp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,88 @@ | ||
# syntax=docker/dockerfile:1 | ||
ARG BUILD_VERSION=2023.12.30 | ||
ARG VERSION=2024.04.09 | ||
ARG RELEASE=0 | ||
|
||
######################################## | ||
# Build stage | ||
######################################## | ||
FROM python:3.12-bookworm as build | ||
|
||
# RUN mount cache for multi-arch: https://github.com/docker/buildx/issues/549#issuecomment-1788297892 | ||
ARG TARGETARCH | ||
ARG TARGETVARIANT | ||
|
||
ARG BUILD_VERSION | ||
|
||
WORKDIR /app | ||
|
||
# Install under /root/.local | ||
ENV PIP_USER="true" | ||
ARG PIP_NO_WARN_SCRIPT_LOCATION=0 | ||
ARG PIP_ROOT_USER_ACTION="ignore" | ||
ARG PIP_NO_COMPILE="true" | ||
ARG PIP_DISABLE_PIP_VERSION_CHECK="true" | ||
|
||
ARG VERSION | ||
RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/pip \ | ||
pip3.12 install dumb-init yt-dlp==$BUILD_VERSION && \ | ||
pip install -U --force-reinstall pip setuptools wheel && \ | ||
pip install yt-dlp==$VERSION && \ | ||
# Cleanup | ||
find "/root/.local" -name '*.pyc' -print0 | xargs -0 rm -f || true ; \ | ||
find "/root/.local" -type d -name '__pycache__' -print0 | xargs -0 rm -rf || true ; | ||
find "/root/.local" -type d -name '__pycache__' -print0 | xargs -0 rm -rf || true ; \ | ||
# Make an empty directory for final stage | ||
mkdir -p /newdir | ||
|
||
######################################## | ||
# Final stage | ||
# Distroless image use monty(1000) for non-root user | ||
######################################## | ||
FROM al3xos/python-distroless:3.12-debian12 as final | ||
|
||
ARG UID=1000 | ||
|
||
# Create directories with correct permissions | ||
COPY --link --chown=$UID:0 --chmod=775 --from=build /newdir /download | ||
COPY --link --chown=$UID:0 --chmod=775 --from=build /newdir /licenses | ||
|
||
# ffmpeg | ||
COPY --link --from=mwader/static-ffmpeg:6.1.1 /ffmpeg /usr/bin/ | ||
COPY --link --from=mwader/static-ffmpeg:6.1.1 /ffprobe /usr/bin/ | ||
COPY --link --from=ghcr.io/jim60105/static-ffmpeg-upx:7.0-1 /ffmpeg /usr/bin/ | ||
COPY --link --from=ghcr.io/jim60105/static-ffmpeg-upx:7.0-1 /ffprobe /usr/bin/ | ||
|
||
# dumb-init | ||
COPY --link --from=ghcr.io/jim60105/static-ffmpeg-upx:7.0-1 /dumb-init /usr/bin/ | ||
|
||
# Copy licenses (OpenShift Policy) | ||
COPY --link --chown=$UID:0 --chmod=775 LICENSE /licenses/Dockerfile.LICENSE | ||
COPY --link --chown=$UID:0 --chmod=775 yt-dlp/LICENSE /licenses/yt-dlp.LICENSE | ||
|
||
# Copy dist and support arbitrary user ids (OpenShift best practice) | ||
# https://docs.openshift.com/container-platform/4.14/openshift_images/create-images.html#use-uid_create-images | ||
COPY --chown=1000:0 --chmod=774 \ | ||
--from=build /root/.local /home/monty/.local | ||
COPY --link --chown=$UID:0 --chmod=775 --from=build /root/.local /home/monty/.local | ||
|
||
ENV PATH="/home/monty/.local/bin:$PATH" | ||
|
||
WORKDIR /download | ||
|
||
VOLUME [ "/download" ] | ||
|
||
USER $UID | ||
|
||
STOPSIGNAL SIGINT | ||
|
||
# Use dumb-init as PID 1 to handle signals properly | ||
ENTRYPOINT [ "dumb-init", "--", "yt-dlp", "--no-cache-dir" ] | ||
CMD ["--help"] | ||
CMD ["--help"] | ||
|
||
ARG VERSION | ||
ARG RELEASE | ||
LABEL name="jim60105/docker-yt-dlp" \ | ||
# Authors for yt-dlp | ||
vendor="yt-dlp" \ | ||
# Maintainer for this docker image | ||
maintainer="jim60105" \ | ||
# Dockerfile source repository | ||
url="https://github.com/jim60105/docker-yt-dlp" \ | ||
version=${VERSION} \ | ||
# This should be a number, incremented with each change | ||
release=${RELEASE} \ | ||
io.k8s.display-name="yt-dlp" \ | ||
summary="yt-dlp: A feature-rich command-line audio/video downloader." \ | ||
description="yt-dlp is a feature-rich command-line audio/video downloader with support for thousands of sites. The project is a fork of youtube-dl based on the now inactive youtube-dlc. For more information about this tool, please visit the following website: https://github.com/yt-dlp/yt-dlp" |
Oops, something went wrong.