From a9d7ff3a5a629d2b502160df5f43d0576e4463e1 Mon Sep 17 00:00:00 2001 From: Arcane Engine Date: Fri, 11 Oct 2024 16:15:26 +0000 Subject: [PATCH] Optimize Dockerfile using multi-stage build to reduce image size and improve deployment speed. --- Dockerfile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index d7611bc..a7b1624 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ -# Use the official Python image from the Docker Hub -FROM python:3.10-slim +# Use the official Python image from the Docker Hub for the build stage +FROM python:3.10-slim AS builder # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 - # Install system dependencies required for uWSGI compilation RUN apt-get update && apt-get install -y \ gcc \ @@ -30,6 +29,19 @@ RUN pip install --no-cache-dir poetry uvicorn \ # Copy project COPY . /code/ +# Final stage +FROM python:3.10-slim + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Set work directory +WORKDIR /code + +# Copy only the necessary files from the builder stage +COPY --from=builder /code /code + # Expose port 8000 for uwsgi EXPOSE 8000