API / Dockerfile
Rox-Turbo's picture
Update Dockerfile
ce1b49c verified
raw
history blame
1.21 kB
FROM python:3.14-slim
WORKDIR /app
# Security and performance environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install security updates
RUN apt-get update && \
apt-get upgrade -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create non-root user with specific UID
RUN useradd -m -u 1000 -s /bin/bash user
# Install dependencies as root
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code and set ownership
COPY --chown=user:user . .
# Switch to non-root user
USER user
# Set PATH for user
ENV PATH="/home/user/.local/bin:$PATH" \
HOME="/home/user"
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python3 -c "import requests; requests.get('http://localhost:7860/health', timeout=5)"
# Expose port 7860 (Hugging Face Spaces default)
EXPOSE 7860
# Start server with production settings
CMD ["sh", "-c", "uvicorn server:app --host 0.0.0.0 --port ${PORT:-7860} --log-level ${LOG_LEVEL:-info} --no-access-log --workers ${WEB_CONCURRENCY:-2}"]