2023-11-13 12:13:56 +03:00
|
|
|
# First stage: Build environment
|
|
|
|
FROM python:3.11-slim-bullseye as builder
|
2023-06-01 17:01:27 +03:00
|
|
|
|
2023-10-09 16:23:13 +03:00
|
|
|
ARG DEV_MODE
|
|
|
|
ENV DEV_MODE=$DEV_MODE
|
|
|
|
|
2023-11-13 12:13:56 +03:00
|
|
|
# Install GEOS library, Rust, and other build-time dependencies
|
2023-08-25 12:05:24 +03:00
|
|
|
RUN apt-get update && apt-get install -y \
|
|
|
|
libgeos-dev \
|
2023-09-14 12:56:59 +03:00
|
|
|
libcurl4-openssl-dev \
|
|
|
|
libssl-dev \
|
2023-08-25 12:05:24 +03:00
|
|
|
pandoc \
|
|
|
|
binutils \
|
|
|
|
curl \
|
2023-09-14 12:56:59 +03:00
|
|
|
git \
|
2023-08-25 12:05:24 +03:00
|
|
|
build-essential && \
|
|
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
|
2023-08-18 13:57:16 +03:00
|
|
|
rm -rf /var/lib/apt/lists/* && apt-get clean
|
2023-05-21 02:20:55 +03:00
|
|
|
|
2023-08-25 12:05:24 +03:00
|
|
|
# Add Rust binaries to the PATH
|
|
|
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
|
|
|
|
2023-11-13 12:13:56 +03:00
|
|
|
# Create a virtual environment and activate it
|
|
|
|
RUN python -m venv /venv
|
|
|
|
ENV PATH="/venv/bin:$PATH"
|
|
|
|
|
2023-05-21 02:20:55 +03:00
|
|
|
WORKDIR /code
|
|
|
|
|
2023-08-18 13:57:16 +03:00
|
|
|
# Copy just the requirements first
|
|
|
|
COPY ./requirements.txt .
|
2023-05-21 02:20:55 +03:00
|
|
|
|
2023-11-13 12:13:56 +03:00
|
|
|
# Upgrade pip and install requirements
|
|
|
|
RUN pip install --upgrade pip && \
|
|
|
|
pip install --no-cache-dir -r requirements.txt --timeout 200
|
2023-05-21 02:20:55 +03:00
|
|
|
|
2023-11-13 12:13:56 +03:00
|
|
|
# Install development tools if in DEV_MODE
|
2023-10-09 16:23:13 +03:00
|
|
|
RUN if [ "$DEV_MODE" = "true" ]; then pip install --no-cache debugpy --timeout 200; fi
|
|
|
|
|
2023-11-13 12:13:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
FROM python:3.11-slim-bullseye as runtime
|
|
|
|
|
|
|
|
ARG DEV_MODE
|
|
|
|
ENV DEV_MODE=$DEV_MODE
|
|
|
|
|
|
|
|
# Create and activate the virtual environment
|
|
|
|
ENV PATH="/venv/bin:$PATH"
|
|
|
|
|
|
|
|
# Install runtime dependencies
|
|
|
|
RUN apt-get update && apt-get install -y \
|
|
|
|
pandoc \
|
|
|
|
binutils && \
|
|
|
|
rm -rf /var/lib/apt/lists/* && apt-get clean
|
|
|
|
|
|
|
|
WORKDIR /code
|
|
|
|
|
|
|
|
# Copy the virtual environment from the builder stage
|
|
|
|
COPY --from=builder /venv /venv
|
|
|
|
|
2023-08-18 13:57:16 +03:00
|
|
|
# Copy the rest of the application
|
|
|
|
COPY . .
|
2023-05-21 02:20:55 +03:00
|
|
|
|
2023-09-17 23:36:42 +03:00
|
|
|
CMD ["uvicorn", "main:app", "--reload", "--host", "0.0.0.0", "--port", "5050", "--workers", "6"]
|