Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +35 -48
Dockerfile
CHANGED
|
@@ -1,61 +1,48 @@
|
|
| 1 |
# Use an official Python runtime as a parent image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
-
# Set
|
| 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
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
# This means 'templates' directory, 'arial.ttf' (if you use it), etc., MUST be in your repo root.
|
| 42 |
-
COPY . .
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
RUN mkdir -p ./app/generated_images && \
|
| 47 |
-
chown -R appuser:appuser ./app
|
| 48 |
|
| 49 |
-
# Install
|
|
|
|
|
|
|
| 50 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
|
| 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"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Use an official Python runtime as a parent image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# Set the working directory in the container
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Create the data directory for persistent template storage
|
| 8 |
+
# This ensures the directory exists when the application starts.
|
| 9 |
+
# Permissions are usually fine by default for the user running the app.
|
| 10 |
+
RUN mkdir -p ./app/data
|
| 11 |
|
| 12 |
+
chmod -R 777 ./app/data
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Copy the requirements file into the container at /app
|
| 15 |
+
COPY requirements.txt .
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Install any needed packages specified in requirements.txt
|
| 18 |
+
# --no-cache-dir reduces image size
|
| 19 |
+
# Ensure Hydrogram and any other dependencies are in requirements.txt
|
| 20 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
|
| 22 |
+
# Copy the rest of the application code (e.g., main.py) into the container at /app
|
| 23 |
+
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Command to run the application
|
| 26 |
+
# This will execute your main.py script when the container launches.
|
| 27 |
CMD ["python", "main.py"]
|
| 28 |
+
|
| 29 |
+
# --- Persistence Note for Docker (and similar platforms) ---
|
| 30 |
+
# The `RUN mkdir -p /app/data` line creates the directory INSIDE the container image.
|
| 31 |
+
# If the container is stopped and removed, and a new one is started from the image,
|
| 32 |
+
# this directory will be "fresh" (empty, or as it was when the image was built).
|
| 33 |
+
#
|
| 34 |
+
# To make the template content in `/app/data` truly persistent across container
|
| 35 |
+
# restarts and deployments (so you don't lose the template), you would use a Docker Volume.
|
| 36 |
+
# When running the container, you would mount a volume to `/app/data`:
|
| 37 |
+
#
|
| 38 |
+
# docker run -d -v my_template_data:/app/data <your_image_name>
|
| 39 |
+
#
|
| 40 |
+
# - `my_template_data` is the name of the Docker volume on the host.
|
| 41 |
+
# - `:/app/data` maps this volume to the `/app/data` directory inside the container.
|
| 42 |
+
#
|
| 43 |
+
# Hugging Face Spaces often handles some level of persistence for the main app directory,
|
| 44 |
+
# so the `data/` subfolder might persist. However, if you need guaranteed persistence
|
| 45 |
+
# that survives complete rebuilds or more complex scenarios, you'd look into the specific
|
| 46 |
+
# persistence options offered by the platform (which might abstract Docker volumes).
|
| 47 |
+
# For simple cases on HF Spaces, just creating the directory and writing to it usually works
|
| 48 |
+
# for persistence across restarts of the same deployment.
|