sreepathi-ravikumar commited on
Commit
b5e16c8
·
verified ·
1 Parent(s): a9a000b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -30
Dockerfile CHANGED
@@ -1,10 +1,16 @@
1
- # Use a lightweight Python image
2
  FROM python:3.11-slim
3
 
4
- # Set working directory
 
 
 
 
 
 
5
  WORKDIR /app
6
 
7
- # Install system dependencies in one layer
 
8
  RUN apt-get update && apt-get install -y \
9
  ffmpeg \
10
  tesseract-ocr \
@@ -12,39 +18,18 @@ RUN apt-get update && apt-get install -y \
12
  fonts-liberation \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
- # Copy requirements.txt and install Python packages
16
- COPY requirements.txt .
17
- RUN pip install --no-cache-dir -r requirements.txt
18
-
19
- # Copy app files
20
- COPY app.py image_fetcher.py video.py video2.py ./
21
-
22
- # Create directories with full permissions
23
- # Inside Dockerfile
24
- # Create user and directory structure FIRST
25
- RUN useradd -m appuser && \
26
- mkdir -p /app/data && \
27
- chown -R appuser:appuser /app
28
-
29
- # Switch to appuser before installing Python packages
30
  USER appuser
31
 
32
- # Install Python packages (now as appuser)
33
  COPY --chown=appuser:appuser requirements.txt .
34
  RUN pip install --no-cache-dir -r requirements.txt
35
 
36
- # Copy app files (as appuser)
37
- COPY --chown=appuser:appuser . .
38
 
39
- # Set ENV variable for paths
40
- ENV BASE_DIR="/home/user/app/tmp"
41
 
42
- # Expose port
43
  EXPOSE 7860
44
-
45
- # Run as non-root user for safety
46
- RUN useradd -m appuser
47
- USER appuser
48
-
49
- # Start the app
50
  CMD ["python", "app.py"]
 
 
1
  FROM python:3.11-slim
2
 
3
+ # 1. First create user and directory structure
4
+ RUN useradd -m appuser && \
5
+ mkdir -p /app/data && \
6
+ chown -R appuser:appuser /app
7
+
8
+ # 2. Switch to appuser early
9
+ USER appuser
10
  WORKDIR /app
11
 
12
+ # 3. Temporary root access for system packages
13
+ USER root
14
  RUN apt-get update && apt-get install -y \
15
  ffmpeg \
16
  tesseract-ocr \
 
18
  fonts-liberation \
19
  && rm -rf /var/lib/apt/lists/*
20
 
21
+ # 4. Switch back to appuser for Python operations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  USER appuser
23
 
24
+ # 5. Install Python packages (first copy just requirements)
25
  COPY --chown=appuser:appuser requirements.txt .
26
  RUN pip install --no-cache-dir -r requirements.txt
27
 
28
+ # 6. Copy all application files
29
+ COPY --chown=appuser:appuser app.py image_fetcher.py video.py video2.py ./
30
 
31
+ # 7. Environment variables
32
+ ENV BASE_DIR="/app/data"
33
 
 
34
  EXPOSE 7860
 
 
 
 
 
 
35
  CMD ["python", "app.py"]