File size: 871 Bytes
93f7b1e 54f9644 1658e5d 54f9644 93f7b1e 54f9644 93f7b1e 54f9644 93f7b1e 54f9644 93f7b1e | 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 | # Use a lightweight Python image
FROM python:3.9-slim
# Set environment variables
# PYTHONUNBUFFERED: Forces stdout/stderr to be flushed immediately (critical for logs)
# PYTHONDONTWRITEBYTECODE: Prevents Python from writing .pyc files
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PORT=7860
# Install pngquant, jpegoptim and zip
RUN apt-get update && \
apt-get install -y pngquant jpegoptim zip && \
rm -rf /var/lib/apt/lists/*
# Create a non-root user (Security Best Practice for HF Spaces)
RUN useradd -m -u 1000 user
# Set working directory
WORKDIR /app
# Copy application files with correct ownership
COPY --chown=user:user web_app.py .
COPY --chown=user:user index.html .
# Switch to the non-root user
USER user
# Expose the port (Hugging Face Spaces defaults to 7860)
EXPOSE 7860
# Start the application
CMD ["python", "web_app.py"]
|