Spaces:
Running
Running
File size: 4,259 Bytes
db08d02 f9ce179 e1b7ad1 f9ce179 db08d02 f9ce179 3ea8097 f9ce179 db08d02 f9ce179 db08d02 f9ce179 de65e47 f9ce179 db08d02 f9ce179 db08d02 f9ce179 |
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# # Stage 1: Build stage
# FROM python:3.11-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.11-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", "api.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]
# Stage 1: Build stage
FROM python:3.11-slim as builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/root/.local/bin:$PATH"
# Install system dependencies (curl, ca-certificates, and libgomp)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
libgomp1 \
&& 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 and install pip
RUN uv venv /opt/venv
RUN /opt/venv/bin/python -m ensurepip
RUN /opt/venv/bin/python -m pip install --upgrade pip
# 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.11-slim
# Install libgomp in the runtime stage
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# 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
# Debugging step: Verify installed packages
RUN /opt/venv/bin/python -m pip list
# 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", "api.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"] |