File size: 3,037 Bytes
8a233a9
 
 
 
 
 
 
2881fd0
8a233a9
 
 
 
 
 
 
 
 
 
2881fd0
8a233a9
 
2881fd0
8a233a9
 
2881fd0
8a233a9
 
2881fd0
 
e0b27eb
8a233a9
2881fd0
 
 
 
fe40008
 
8a233a9
2881fd0
 
8a233a9
 
2881fd0
 
8a233a9
 
2881fd0
 
8a233a9
e0b27eb
2a723ad
 
e0b27eb
2881fd0
 
 
8a233a9
 
2881fd0
 
8a233a9
 
2881fd0
 
2a723ad
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
# 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 image processing: 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 \
    # 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' has been REMOVED.
# We will now rely 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"]