This repository was archived by the owner on Jun 14, 2026. It is now read-only.
forked from L4GSP1KE/Upload-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 139
Reduce Docker image size using multi-stage builds #1161
Open
mrz948
wants to merge
3
commits into
Audionut:master
Choose a base branch
from
mrz948:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| FROM python:3.12-alpine AS base | ||
|
|
||
| ENV PIP_VERSION=25.3 | ||
| ENV REQUESTS_VERSION=2.32.5 | ||
| ENV PYTHONUNBUFFERED=1 | ||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
|
|
||
| # Install system dependencies including mono | ||
| RUN apk add --no-cache \ | ||
| ca-certificates \ | ||
| curl \ | ||
| ffmpeg \ | ||
| gcompat \ | ||
| icu-libs \ | ||
| libgdiplus \ | ||
| mediainfo \ | ||
| mktorrent \ | ||
| mono \ | ||
| nano \ | ||
| && update-ca-certificates | ||
|
|
||
| # Setup venv | ||
| FROM base AS builder-venv | ||
|
|
||
| # Install build dependencies | ||
| RUN apk add --no-cache \ | ||
| cargo \ | ||
| gcc \ | ||
| git \ | ||
| g++ \ | ||
| linux-headers \ | ||
| musl-dev \ | ||
| python3-dev | ||
|
|
||
| COPY requirements.txt /tmp/requirements.txt | ||
|
|
||
| # Python venv setup | ||
| RUN python -m venv /venv | ||
| ENV PATH="/venv/bin:$PATH" | ||
|
|
||
| # Install requirements | ||
| RUN pip install --no-cache-dir --upgrade pip==${PIP_VERSION} && \ | ||
| pip install --no-cache-dir -r /tmp/requirements.txt | ||
|
|
||
| # Finalize app directory in seperate build stage | ||
| FROM base AS builder-app | ||
|
|
||
| # Copy virtual environment | ||
| COPY --from=builder-venv /venv /venv | ||
| ENV PATH="/venv/bin:$PATH" | ||
|
|
||
| # Install requests (for DVD MediaInfo download) | ||
| RUN pip install --upgrade requests==${REQUESTS_VERSION} | ||
|
|
||
| WORKDIR /Upload-Assistant | ||
|
|
||
| # Copy app into container | ||
| COPY . . | ||
|
|
||
| # Run DVD MediaInfo download script | ||
| RUN python3 bin/get_dvd_mediainfo_docker.py | ||
|
|
||
| # Download only the required mkbrr binary (requires full repo for src imports) | ||
| RUN python3 -c "from bin.get_mkbrr import MkbrrBinaryManager; MkbrrBinaryManager.download_mkbrr_for_docker()" | ||
|
|
||
| # Download bdinfo binary for the container architecture using the docker helper | ||
| RUN python3 bin/get_bdinfo_docker.py | ||
|
|
||
| RUN chown -R 1000:1000 /Upload-Assistant/bin/mkbrr \ | ||
| && chown -R 1000:1000 /Upload-Assistant/bin/MI \ | ||
| && chown -R 1000:1000 /Upload-Assistant/bin/bdinfo \ | ||
| && chmod -R +rx /Upload-Assistant/bin/mkbrr \ | ||
| && chmod -R +rx /Upload-Assistant/bin/MI \ | ||
| && chmod -R +rx /Upload-Assistant/bin/bdinfo | ||
|
|
||
| # Create tmp directory with appropriate permissions | ||
| RUN mkdir -p /Upload-Assistant/tmp && chmod 1777 /Upload-Assistant/tmp | ||
| ENV TMPDIR=/Upload-Assistant/tmp | ||
|
|
||
| # START BUILDING SLIM IMAGE | ||
| FROM base | ||
|
|
||
| # Copy venv | ||
| COPY --from=builder-venv /venv /venv | ||
| ENV PATH="/venv/bin:$PATH" | ||
|
|
||
| # Copy application | ||
| COPY --from=builder-app /Upload-Assistant /Upload-Assistant | ||
|
|
||
| WORKDIR /Upload-Assistant | ||
|
|
||
| EXPOSE 5000 | ||
|
|
||
| STOPSIGNAL SIGTERM | ||
|
|
||
| # Health check for WebUI mode — ignored when running CLI | ||
| HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ | ||
| CMD curl -sf http://localhost:5000/api/health || exit 1 | ||
|
|
||
| ENTRYPOINT ["python", "/Upload-Assistant/upload.py"] | ||
|
|
||
| # Default: show help when no arguments are provided | ||
| CMD ["-h"] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run the container as a non‑root user.
The final image defaults to root; this is a common security risk and flagged by Trivy. Create a dedicated user and switch to it after setting ownership.
✅ Suggested fix
🤖 Prompt for AI Agents