Spaces:
Runtime error
Runtime error
File size: 4,118 Bytes
8a233a9 ad1707c 3cd967e 8a233a9 2881fd0 8a233a9 2881fd0 8a233a9 2881fd0 8a233a9 2881fd0 e0b27eb 8a233a9 2881fd0 fe40008 8a233a9 2881fd0 8a233a9 2881fd0 8a233a9 2881fd0 8a233a9 e0b27eb 3cd967e e0b27eb 2881fd0 8a233a9 2881fd0 8a233a9 2881fd0 70636e8 8a233a9 2881fd0 8a233a9 |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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
RUN apt-get update && \
# Attempt to modify the newer deb822-style sources file if it exists.
# This adds 'contrib' and 'non-free-firmware' to the 'Components' lines.
(if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
echo "Modifying /etc/apt/sources.list.d/debian.sources to include contrib and non-free-firmware" && \
sed -i -e 's/^Components: main$/Components: main contrib non-free-firmware/' \
-e 's/^Components: main\( .*\)$/Components: main contrib non-free-firmware\1/' \
/etc/apt/sources.list.d/debian.sources; \
else \
echo "/etc/apt/sources.list.d/debian.sources not found, checking /etc/apt/sources.list"; \
fi) && \
# Attempt to modify the traditional sources.list file (as a fallback or if it co-exists).
# Add '|| true' to prevent failure if the file doesn't exist or sed fails on it.
(if [ -f /etc/apt/sources.list ]; then \
echo "Modifying /etc/apt/sources.list to include contrib and non-free-firmware" && \
sed -i 's/main$/main contrib non-free-firmware/g' /etc/apt/sources.list; \
else \
echo "/etc/apt/sources.list not found."; \
fi || true) && \
# Rerun apt-get update with the (potentially) new sources
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 \
# Clean up apt caches to reduce image size
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
# Update font cache to make installed fonts available to applications like Pillow
&& fc-cache -f -v
# Set the working directory in the container for subsequent commands
WORKDIR /app
# Create a non-root user and group for better security.
# Using UID/GID 1000 is common for Hugging Face Spaces.
RUN groupadd -g 1000 appuser && useradd --no-log-init -u 1000 -g appuser appuser
# Create necessary application directories within /app.
# Then, set ownership of the entire /app directory (and its contents)
# to the 'appuser'. This ensures the application, running as 'appuser',
# has the necessary permissions, especially for /app/generated_images.
RUN mkdir -p ./app/templates ./app/generated_images && \
chown -R appuser:appuser ./app
# Copy the requirements file first to leverage Docker layer caching.
# Ensure 'appuser' owns this copied file.
COPY --chown=appuser:appuser requirements.txt .
# Install Python dependencies specified in requirements.txt.
# --no-cache-dir reduces image size by not storing the pip cache.
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application files into the container's /app directory.
# Ensure 'appuser' owns these copied files.
COPY --chown=appuser:appuser app.py .
# The line to copy 'arial.ttf' was previously REMOVED.
# We are relying on the system-installed Arial from 'ttf-mscorefonts-installer'.
# Copy the entire 'templates' directory (and its contents) from your repository root
# to /app/templates inside the container.
# This requires the 'templates' directory to exist in your repository root.
COPY --chown=appuser:appuser templates ./templates
# Switch to the non-root user 'appuser' for running the application.
# Subsequent commands (like CMD) will run as this user.
USER appuser
# Define an environment variable placeholder for the Telegram token.
# The actual token MUST be set in your Hugging Face Space's secrets settings.
ENV TELEGRAM_TOKEN="7229558358:AAH_btIdtnJvfGhh84O2uVa8wuH88ShUcy0"
# Command to run the application when the container launches.
# This executes 'python app.py' as the 'appuser'.
CMD ["python", "app.py"]
|