Samirbagda commited on
Commit
0dc8d87
·
verified ·
1 Parent(s): a4e9fe6

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +48 -0
Dockerfile ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a specific Python version
2
+ FROM python:3.11
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Install required system packages (ffmpeg is needed by yt-dlp for merging/conversion)
8
+ RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && \
9
+ apt-get clean && rm -rf /var/lib/apt/lists/*
10
+
11
+ # Create a non-root user for security
12
+ # Using uid 1000 which is common
13
+ RUN useradd -m -u 1000 appuser
14
+
15
+ # Copy requirements first to leverage Docker cache
16
+ COPY requirements.txt .
17
+
18
+ # Install Python dependencies
19
+ # Ensure requirements.txt contains:
20
+ # fastapi[all]
21
+ # yt-dlp
22
+ # requests
23
+ RUN pip install --pre --no-cache-dir -r requirements.txt
24
+
25
+ # Copy the rest of the application files
26
+ # Make sure main.py and www.youtube.com_cookies.txt (if used) are in the build context
27
+ COPY . .
28
+
29
+ # Set permissions:
30
+ # - Directories: read/execute for all, write for owner (755)
31
+ # - Files: read for all, write for owner (644)
32
+ # - Change ownership to the non-root user
33
+ # Note: Explicit chmod for cookie file might be redundant if COPY respects source permissions, but doesn't hurt.
34
+ RUN find /app -type d -exec chmod 755 {} \; && \
35
+ find /app -type f -exec chmod 644 {} \; && \
36
+ chown -R appuser:appuser /app
37
+
38
+ # Switch to the non-root user
39
+ USER appuser
40
+
41
+ # Expose the port the app will run on (common for HF Spaces)
42
+ EXPOSE 7860
43
+
44
+ # Command to run the application using uvicorn
45
+ # - main:app -> finds the 'app' instance in the 'main.py' file
46
+ # - --host 0.0.0.0 -> makes the server accessible from outside the container
47
+ # - --port 7860 -> matches the EXPOSE directive
48
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]