Spaces:
Sleeping
Sleeping
File size: 1,244 Bytes
ea9e2cb |
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 |
FROM python:3.12.3-slim as builder
WORKDIR /app
# Install system dependencies required for building
RUN apt-get update && apt-get install -y \
protobuf-compiler \
gcc \
g++ \
cmake \
pkg-config \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install poetry
RUN pip install poetry
# Copy dependency files
COPY pyproject.toml poetry.lock ./
# Configure poetry and install dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root
# Second stage
FROM python:3.12.3-slim
WORKDIR /app
# Copy installed dependencies from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages/ /usr/local/lib/python3.12/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/
# Install runtime system dependencies
RUN apt-get update && apt-get install -y \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
# Copy application code
COPY . .
# Create non-root user
RUN useradd -m appuser && \
chown -R appuser:appuser /app
USER appuser
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
CMD ["poetry", "run", "python", "app.py"] |