From 1085b42e54dfe7b64a37dfbe96287f0ca7bd0345 Mon Sep 17 00:00:00 2001 From: jose-rZM <100773386+jose-rZM@users.noreply.github.com> Date: Mon, 15 Dec 2025 13:49:46 +0100 Subject: [PATCH] Improve backend docker image size --- backend/Dockerfile | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 81d0827..bd6c2c7 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,10 +1,22 @@ -FROM python:3.11-slim AS base +FROM python:3.11-slim AS builder +WORKDIR /build + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt . +RUN pip wheel --no-cache-dir --no-deps -r requirements.txt -w /build/wheels + + +FROM python:3.11-slim +WORKDIR /app # ---- Build args (desde Jenkins) ---- ARG APP_VERSION=dev ARG GIT_COMMIT=local ARG COMMIT_AUTHOR=local -ARG BUILD_NUMBER=— +ARG BUILD_NUMBER=local # ---- Runtime env ---- ENV APP_VERSION=${APP_VERSION} \ @@ -21,18 +33,10 @@ LABEL app.version="${APP_VERSION}" \ git.author="${COMMIT_AUTHOR}" \ build.number="${BUILD_NUMBER}" - -WORKDIR /app - -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential curl \ - && rm -rf /var/lib/apt/lists/* - -COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +COPY --from=builder /build/wheels /wheels +RUN pip install --no-cache-dir /wheels/* && rm -rf /wheels COPY app ./app EXPOSE 8000 - CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]