From c5f94ac55dfaf016896d1b423fe7c96930263320 Mon Sep 17 00:00:00 2001 From: Ali Maktabi Date: Mon, 16 Sep 2024 18:50:56 +0330 Subject: [PATCH] optimized build on docker --- Dockerfile | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 858f6e7..e6f8008 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,30 @@ -FROM pypy:3.10 - +# Builder stage +FROM pypy:3.10 AS builder +# Install dependencies for Rust and Python build requirements RUN apt-get update && apt-get install -y \ curl \ build-essential \ libssl-dev \ pkg-config \ + gcc \ && rm -rf /var/lib/apt/lists/* +# Install Rust and Cargo RUN curl https://sh.rustup.rs -sSf | sh -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" RUN rustc --version && cargo --version +# Set work directory +WORKDIR /usr/src/app + +# Upgrade pip and install Python dependencies into a virtual environment +RUN pip install --upgrade pip +COPY ./requirements.txt . +RUN pip install -r requirements.txt + +# Final stage (runtime) +FROM pypy:3.10 # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 @@ -20,31 +33,18 @@ ENV PYTHONUNBUFFERED 1 # Set work directory WORKDIR /usr/src/app -RUN apt update && apt install gcc - - -# RUN apt-get update && \ -# apt-get install -y --no-install-recommends \ -# build-essential \ -# gcc \ -# libpq-dev \ -# libc-dev \ -# netcat-traditional \ -# && apt-get clean && \ -# rm -rf /var/lib/apt/lists/* +# Install GCC +RUN apt update && apt install -y gcc +# Copy installed Python packages from builder stage +COPY --from=builder /opt/pypy/lib/pypy3.10/site-packages /opt/pypy/lib/pypy3.10/site-packages -RUN pip install --upgrade pip -COPY ./requirements.txt . -RUN pip install -r requirements.txt - +# Link pypy3 to python RUN ln -s /usr/local/bin/pypy3 /usr/local/bin/python - -# Copy project +# Copy project files COPY ./src . COPY ./start.sh . COPY ./celery.sh . - # RUN pypy3 manage.py collectstatic --noinput