From 761413151195f26c2304f4b326d2e82df5886c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Guti=C3=A9rrez=20de=20Quevedo=20P=C3=A9?= =?UTF-8?q?rez?= Date: Fri, 21 Nov 2025 18:49:15 +0100 Subject: [PATCH] build: optimize Dockerfile for better layer caching and smaller image size - Combined apt-get commands into a single RUN layer - Added --no-install-recommends flag to avoid unnecessary packages - Cleaned up apt cache and removed package lists after installation - Reordered COPY commands to copy requirements.txt first for better Docker layer caching - Separated COPY of requirements.txt from the rest of the application code --- Dockerfile | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index cdec76b..7fadb96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,25 @@ FROM python:3-bookworm # Set working directory WORKDIR /app -# Install runtime dependencies (minimal) -RUN apt update && apt install cvs rsh-client cvsps +# Install runtime dependencies in a single layer and clean up apt cache +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + cvs \ + rsh-client \ + cvsps && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* -COPY . . +# Copy requirements first for better layer caching +COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application +COPY . . + +# Install the package RUN pip install --no-cache-dir -e . # Set environment variables for configuration (with defaults) @@ -26,4 +38,4 @@ ENV CVS_URL="" \ EXPOSE 5000 # Set the entrypoint to run the application with environment variables as command-line arguments -ENTRYPOINT ["sh", "-c", "python -m cvs_proxy.app --cvs-url \"$CVS_URL\" --repo-checkouts \"$REPO_CHECKOUTS\" ${CVS_MODULE:+--cvs-module \"$CVS_MODULE\"} ${BASEPATH:+--basepath \"$BASEPATH\"} --host \"$FLASK_HOST\" --port \"$FLASK_PORT\" ${FLASK_DEBUG:+--debug}"] +ENTRYPOINT ["sh", "-c", "python -m cvs_proxy.app --cvs-url \"$CVS_URL\" --repo-checkouts \"$REPO_CHECKOUTS\" ${CVS_MODULE:+--cvs-module \"$CVS_MODULE\"} ${BASEPATH:+--basepath \"$BASEPATH\"} --host \"$FLASK_HOST\" --port \"$FLASK_PORT\" ${FLASK_DEBUG:+--debug}"] \ No newline at end of file