Spaces:
Running
Running
File size: 1,901 Bytes
2cb9dec 20998ce a4faf54 20998ce 2cb9dec a4faf54 2cb9dec c50b85f a4faf54 2cb9dec c50b85f 20998ce 2cb9dec 20998ce c50b85f 20998ce 2cb9dec c50b85f 20998ce 2cb9dec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# Stage 1: Build stage
FROM python:3.12-slim as builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/root/.local/bin:$PATH"
# Install system dependencies (curl and ca-certificates for uv installer)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install uv using the official installer
RUN curl -sSfL https://astral.sh/uv/install.sh | sh
# Verify uv is installed and available
RUN uv --version
# Create a non-root user
RUN useradd -m -u 1000 user
# Set the working directory
WORKDIR /app
# Create a virtual environment
RUN uv venv /opt/venv
# Update PATH to include the virtual environment's bin directory
ENV PATH="/opt/venv/bin:$PATH"
# Copy only the requirements file first to leverage Docker cache
COPY --chown=user ./requirements.txt /app/requirements.txt
# Install dependencies into the virtual environment using uv
RUN uv pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code
COPY --chown=user . /app
# Stage 2: Runtime stage
FROM python:3.12-slim
# Create a non-root user
RUN useradd -m -u 1000 user
USER user
# Set environment variables
ENV PATH="/opt/venv/bin:$PATH" \
PYTHONUNBUFFERED=1
# Set the working directory
WORKDIR /app
# Copy the virtual environment from the builder stage
COPY --from=builder --chown=user /opt/venv /opt/venv
# Copy only the necessary files from the builder stage
COPY --from=builder --chown=user /app /app
# Expose the port the app runs on
EXPOSE 7860
# Health check to ensure the application is running
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Command to run the application with hot reloading
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"] |