Spaces:
Runtime error
Runtime error
# Use an official Python runtime as a parent image | |
FROM python:3.10-slim | |
# Set the working directory in the container | |
WORKDIR /app | |
# Create the data directory for persistent template storage | |
# This ensures the directory exists when the application starts. | |
# Permissions are usually fine by default for the user running the app. | |
RUN mkdir -p ./app/data | |
chmod -R 777 ./app/data | |
# Copy the requirements file into the container at /app | |
COPY requirements.txt . | |
# Install any needed packages specified in requirements.txt | |
# --no-cache-dir reduces image size | |
# Ensure Hydrogram and any other dependencies are in requirements.txt | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy the rest of the application code (e.g., main.py) into the container at /app | |
COPY . . | |
# Command to run the application | |
# This will execute your main.py script when the container launches. | |
CMD ["python", "main.py"] | |
# --- Persistence Note for Docker (and similar platforms) --- | |
# The `RUN mkdir -p /app/data` line creates the directory INSIDE the container image. | |
# If the container is stopped and removed, and a new one is started from the image, | |
# this directory will be "fresh" (empty, or as it was when the image was built). | |
# | |
# To make the template content in `/app/data` truly persistent across container | |
# restarts and deployments (so you don't lose the template), you would use a Docker Volume. | |
# When running the container, you would mount a volume to `/app/data`: | |
# | |
# docker run -d -v my_template_data:/app/data <your_image_name> | |
# | |
# - `my_template_data` is the name of the Docker volume on the host. | |
# - `:/app/data` maps this volume to the `/app/data` directory inside the container. | |
# | |
# Hugging Face Spaces often handles some level of persistence for the main app directory, | |
# so the `data/` subfolder might persist. However, if you need guaranteed persistence | |
# that survives complete rebuilds or more complex scenarios, you'd look into the specific | |
# persistence options offered by the platform (which might abstract Docker volumes). | |
# For simple cases on HF Spaces, just creating the directory and writing to it usually works | |
# for persistence across restarts of the same deployment. | |