Spaces:
Sleeping
Sleeping
File size: 1,028 Bytes
3a8b459 06d0d79 3a8b459 98c01b2 | 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 | ### Dockerfile for FastAPI app
FROM python:3.12-slim
# Environment
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PATH="/root/.local/bin:$PATH"
WORKDIR /app
# Install system deps that some packages may require at build time
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential libpq-dev git \
&& rm -rf /var/lib/apt/lists/*
# Install Python deps
COPY requirements.txt ./
RUN pip install --upgrade pip setuptools wheel \
&& pip install --no-cache-dir -r requirements.txt
# Copy source
COPY . .
# Use unprivileged user
RUN useradd -m appuser && chown -R appuser /app
USER appuser
EXPOSE 5001
# Simple healthcheck (checks docs page)
#HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
# CMD curl -f http://localhost:${PORT:-5001}/docs || exit 1
# Default command - respects platform provided PORT env var (e.g., Hugging Face Spaces)
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860} --workers 1"]
|