Spaces:
Runtime error
Runtime error
# Use an official Python runtime as a parent image | |
FROM python:3.10-slim | |
# Set environment variables to prevent interactive prompts during apt-get install | |
ENV DEBIAN_FRONTEND=noninteractive | |
# Install system dependencies | |
# - Essential for Pillow/OpenCV: libgl1-mesa-glx, libglib2.0-0 | |
# - Font handling: fontconfig | |
# - Installs Microsoft Core Fonts (including Arial): ttf-mscorefonts-installer | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends \ | |
libgl1-mesa-glx \ | |
libglib2.0-0 \ | |
fontconfig \ | |
# Accept the EULA for ttf-mscorefonts-installer non-interactively | |
&& echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections \ | |
&& apt-get install -y --no-install-recommends ttf-mscorefonts-installer \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* \ | |
# Update font cache to make installed fonts available | |
&& fc-cache -f -v | |
# Set the working directory in the container | |
WORKDIR /app | |
# Create a non-root user and group for better security | |
RUN groupadd -r appuser && useradd --no-log-init -r -g appuser appuser | |
# Create necessary application directories before copying and set ownership | |
# Ensures the user 'appuser' can write to generated_images | |
RUN mkdir -p /app/templates /app/generated_images && \ | |
chown -R appuser:appuser /app | |
# Copy the requirements file first for layer caching | |
COPY --chown=appuser:appuser requirements.txt . | |
# Install Python dependencies specified in requirements.txt | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy the rest of the application files into the container | |
# Ensure 'app.py', 'arial.ttf', and the 'templates' directory exist in your repo root | |
COPY --chown=appuser:appuser app.py . | |
# If you include arial.ttf directly in your repo: | |
COPY --chown=appuser:appuser arial.ttf . | |
# Copy the entire templates directory | |
COPY --chown=appuser:appuser templates ./templates | |
# Switch to the non-root user | |
USER appuser | |
# Define environment variable placeholder (Hugging Face Secrets will override this) | |
# You MUST set TELEGRAM_TOKEN in your Space's secrets settings. | |
ENV TELEGRAM_TOKEN="" | |
# Command to run the application when the container launches | |
CMD ["python", "app.py"] | |