From e0214ba85867ca314da386e958020379b36e11dd Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:03:28 -0700 Subject: [PATCH] attempt to make the image smaller --- Dockerfile.cpu | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/Dockerfile.cpu b/Dockerfile.cpu index 92e902a..23bc564 100644 --- a/Dockerfile.cpu +++ b/Dockerfile.cpu @@ -1,23 +1,34 @@ -FROM python:3.11-slim-bullseye +# Stage 1: Build dependencies in a full-featured Python image +FROM python:3.11-alpine AS builder WORKDIR /subgen -ADD https://raw.githubusercontent.com/McCloudS/subgen/main/requirements.txt /subgen/requirements.txt +# Install dependencies required for building wheels +RUN apk add --no-cache \ + ffmpeg \ + git \ + build-base \ + python3-dev \ + libffi-dev -RUN apt-get update \ - && apt-get install -y \ - python3 \ - python3-pip \ - ffmpeg \ - git \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && pip install -r requirements.txt +# Copy and install Python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir --prefix=/install -r requirements.txt +# Stage 2: Create a minimal final image +FROM python:3.11-alpine + +WORKDIR /subgen + +# Install runtime dependencies (minimal set) +RUN apk add --no-cache ffmpeg git + +# Copy only the required files from the builder stage +COPY --from=builder /install /usr/local +COPY launcher.py subgen.py language_code.py /subgen/ + +# Set environment variable for cleaner output ENV PYTHONUNBUFFERED=1 -ADD https://raw.githubusercontent.com/McCloudS/subgen/main/launcher.py /subgen/launcher.py -ADD https://raw.githubusercontent.com/McCloudS/subgen/main/subgen.py /subgen/subgen.py -ADD https://raw.githubusercontent.com/McCloudS/subgen/main/language_code.py /subgen/language_code.py - -CMD [ "bash", "-c", "python3 -u launcher.py" ] +# Run the application +CMD ["python3", "-u", "launcher.py"]