Spaces:
Runtime error
Runtime error
Create Dockerfile.py
Browse files- Dockerfile.py +61 -0
Dockerfile.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
RUN apt-get update && \
|
| 9 |
+
(if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
|
| 10 |
+
echo "Modifying /etc/apt/sources.list.d/debian.sources to include contrib and non-free-firmware" && \
|
| 11 |
+
sed -i -e 's/^Components: main$/Components: main contrib non-free-firmware/' \
|
| 12 |
+
-e 's/^Components: main\( .*\)$/Components: main contrib non-free-firmware\1/' \
|
| 13 |
+
/etc/apt/sources.list.d/debian.sources; \
|
| 14 |
+
else \
|
| 15 |
+
echo "/etc/apt/sources.list.d/debian.sources not found, checking /etc/apt/sources.list"; \
|
| 16 |
+
fi) && \
|
| 17 |
+
(if [ -f /etc/apt/sources.list ]; then \
|
| 18 |
+
echo "Modifying /etc/apt/sources.list to include contrib and non-free-firmware" && \
|
| 19 |
+
sed -i 's/main$/main contrib non-free-firmware/g' /etc/apt/sources.list; \
|
| 20 |
+
else \
|
| 21 |
+
echo "/etc/apt/sources.list not found."; \
|
| 22 |
+
fi || true) && \
|
| 23 |
+
apt-get update && \
|
| 24 |
+
apt-get install -y --no-install-recommends \
|
| 25 |
+
libgl1-mesa-glx \
|
| 26 |
+
libglib2.0-0 \
|
| 27 |
+
fontconfig \
|
| 28 |
+
&& echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections \
|
| 29 |
+
&& apt-get install -y --no-install-recommends ttf-mscorefonts-installer \
|
| 30 |
+
&& apt-get clean \
|
| 31 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 32 |
+
&& fc-cache -f -v
|
| 33 |
+
|
| 34 |
+
# Set the working directory
|
| 35 |
+
WORKDIR /app
|
| 36 |
+
|
| 37 |
+
# Create a non-root user and group
|
| 38 |
+
RUN groupadd -g 1000 appuser && useradd --no-log-init -u 1000 -g appuser appuser
|
| 39 |
+
|
| 40 |
+
# Copy all application files from the repository root to /app
|
| 41 |
+
# This means 'templates' directory, 'arial.ttf' (if you use it), etc., MUST be in your repo root.
|
| 42 |
+
COPY . .
|
| 43 |
+
|
| 44 |
+
# Ensure necessary directories exist and set ownership for the entire /app directory.
|
| 45 |
+
# 'templates' should be copied by 'COPY . .'. 'generated_images' and session dir (which is /app) need to be writable.
|
| 46 |
+
RUN mkdir -p ./app/generated_images && \
|
| 47 |
+
chown -R appuser:appuser ./app
|
| 48 |
+
|
| 49 |
+
# Install Python dependencies
|
| 50 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 51 |
+
|
| 52 |
+
# Switch to the non-root user
|
| 53 |
+
USER appuser
|
| 54 |
+
|
| 55 |
+
# Environment variables for secrets (set these in Hugging Face Space settings)
|
| 56 |
+
ENV BOT_TOKEN=""
|
| 57 |
+
ENV API_ID=""
|
| 58 |
+
ENV API_HASH=""
|
| 59 |
+
|
| 60 |
+
# Command to run the application
|
| 61 |
+
CMD ["python", "main.py"]
|