Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +19 -34
Dockerfile
CHANGED
@@ -4,45 +4,30 @@ FROM python:3.10-slim
|
|
4 |
# Set the working directory in the container
|
5 |
WORKDIR /app
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
COPY requirements.txt .
|
16 |
|
17 |
-
# Install
|
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
|
23 |
COPY . .
|
24 |
|
25 |
-
# Command to run
|
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.
|
|
|
4 |
# Set the working directory in the container
|
5 |
WORKDIR /app
|
6 |
|
7 |
+
# Define an argument for the data directory name (for flexibility)
|
8 |
+
ARG APP_TEMPLATE_DIR_NAME=app_template_storage
|
9 |
+
|
10 |
+
# Create the specific data directory for templates AND set permissions.
|
11 |
+
# The './' ensures it's relative to WORKDIR (/app).
|
12 |
+
# This command runs as root during the image build.
|
13 |
+
RUN mkdir -p ./${APP_TEMPLATE_DIR_NAME} && \
|
14 |
+
chmod -R 777 ./${APP_TEMPLATE_DIR_NAME}
|
15 |
+
# IMPORTANT on chmod 777:
|
16 |
+
# This gives read, write, and execute permissions to everyone (owner, group, others).
|
17 |
+
# While it solves permission issues, it's very open.
|
18 |
+
# For production, you'd ideally find the UID your app runs as on Hugging Face
|
19 |
+
# and chown the directory to that user, or use more restrictive permissions (e.g., 755, 775).
|
20 |
+
# However, for troubleshooting and typical Hugging Face Space usage, 777 is a common fix.
|
21 |
+
|
22 |
+
# Copy the requirements file into the container
|
23 |
COPY requirements.txt .
|
24 |
|
25 |
+
# Install Python dependencies
|
26 |
# --no-cache-dir reduces image size
|
|
|
27 |
RUN pip install --no-cache-dir -r requirements.txt
|
28 |
|
29 |
+
# Copy the rest of your application code (e.g., main.py) into the container
|
30 |
COPY . .
|
31 |
|
32 |
+
# Command to run your Python application
|
|
|
33 |
CMD ["python", "main.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|