Spaces:
Runtime error
Runtime error
Create dockerfile
Browse files- dockerfile +57 -0
dockerfile
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use an official Python runtime as a parent image
|
2 |
+
FROM python:3.10-slim
|
3 |
+
|
4 |
+
# Set environment variables to prevent interactive prompts during apt-get install
|
5 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
6 |
+
|
7 |
+
# Install system dependencies
|
8 |
+
# - Essential for Pillow/OpenCV: libgl1-mesa-glx, libglib2.0-0
|
9 |
+
# - Font handling: fontconfig
|
10 |
+
# - Installs Microsoft Core Fonts (including Arial): ttf-mscorefonts-installer
|
11 |
+
RUN apt-get update && \
|
12 |
+
apt-get install -y --no-install-recommends \
|
13 |
+
libgl1-mesa-glx \
|
14 |
+
libglib2.0-0 \
|
15 |
+
fontconfig \
|
16 |
+
# Accept the EULA for ttf-mscorefonts-installer non-interactively
|
17 |
+
&& echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections \
|
18 |
+
&& apt-get install -y --no-install-recommends ttf-mscorefonts-installer \
|
19 |
+
&& apt-get clean \
|
20 |
+
&& rm -rf /var/lib/apt/lists/* \
|
21 |
+
# Update font cache to make installed fonts available
|
22 |
+
&& fc-cache -f -v
|
23 |
+
|
24 |
+
# Set the working directory in the container
|
25 |
+
WORKDIR /app
|
26 |
+
|
27 |
+
# Create a non-root user and group for better security
|
28 |
+
RUN groupadd -r appuser && useradd --no-log-init -r -g appuser appuser
|
29 |
+
|
30 |
+
# Create necessary application directories before copying and set ownership
|
31 |
+
# Ensures the user 'appuser' can write to generated_images
|
32 |
+
RUN mkdir -p /app/templates /app/generated_images && \
|
33 |
+
chown -R appuser:appuser /app
|
34 |
+
|
35 |
+
# Copy the requirements file first for layer caching
|
36 |
+
COPY --chown=appuser:appuser requirements.txt .
|
37 |
+
|
38 |
+
# Install Python dependencies specified in requirements.txt
|
39 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
40 |
+
|
41 |
+
# Copy the rest of the application files into the container
|
42 |
+
# Ensure 'app.py', 'arial.ttf', and the 'templates' directory exist in your repo root
|
43 |
+
COPY --chown=appuser:appuser app.py .
|
44 |
+
# If you include arial.ttf directly in your repo:
|
45 |
+
COPY --chown=appuser:appuser arial.ttf .
|
46 |
+
# Copy the entire templates directory
|
47 |
+
COPY --chown=appuser:appuser templates ./templates
|
48 |
+
|
49 |
+
# Switch to the non-root user
|
50 |
+
USER appuser
|
51 |
+
|
52 |
+
# Define environment variable placeholder (Hugging Face Secrets will override this)
|
53 |
+
# You MUST set TELEGRAM_TOKEN in your Space's secrets settings.
|
54 |
+
ENV TELEGRAM_TOKEN=""
|
55 |
+
|
56 |
+
# Command to run the application when the container launches
|
57 |
+
CMD ["python", "app.py"]
|