From 820bca6308d9ee2f8e15666433acf6358ecbe015 Mon Sep 17 00:00:00 2001 From: rjshrjndrn Date: Thu, 13 Mar 2025 14:51:59 +0100 Subject: [PATCH] build(api): implement multi-stage Dockerfile - Use multi-stage build to reduce final image size - Move build dependencies to builder stage - Copy only necessary files to final stage - Use UV for faster Python package installation - Clean up duplicate operations --- api/Dockerfile | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/api/Dockerfile b/api/Dockerfile index 6ed123e4d..513494dca 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,8 +1,16 @@ -FROM python:3.12-alpine +FROM python:3.12-alpine AS builder LABEL maintainer="Rajesh Rajendran" LABEL maintainer="KRAIEM Taha Yassine" -RUN apk add --no-cache build-base=~1.2 tini=~0.19 +RUN apk add --no-cache build-base +WORKDIR /work +COPY requirements.txt ./requirements.txt +RUN pip install --no-cache-dir --upgrade uv && \ + export UV_SYSTEM_PYTHON=true && \ + uv pip install --no-cache-dir --upgrade pip setuptools wheel && \ + uv pip install --no-cache-dir --upgrade -r requirements.txt + +FROM python:3.12-alpine ARG GIT_SHA ARG envarg # Add Tini @@ -13,18 +21,11 @@ ENV SOURCE_MAP_VERSION=0.7.4 \ PRIVATE_ENDPOINTS=false \ ENTERPRISE_BUILD=${envarg} \ GIT_SHA=$GIT_SHA - +COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages +COPY --from=builder /usr/local/bin /usr/local/bin +RUN apk add --no-cache tini WORKDIR /work -COPY requirements.txt ./requirements.txt -RUN pip install --no-cache-dir --upgrade uv && \ - uv pip install --no-cache-dir --upgrade pip setuptools wheel --system && \ - uv pip install --no-cache-dir --upgrade -r requirements.txt --system - COPY . . -RUN mv env.default .env && \ - adduser -u 1001 openreplay -D -USER 1001 ENTRYPOINT ["/sbin/tini", "--"] CMD ["./entrypoint.sh"] -