ishworrsubedii commited on
Commit
77e7008
·
1 Parent(s): 00e83a0

update: dockerfile imagemagic policy

Browse files
Files changed (1) hide show
  1. Dockerfile +37 -18
Dockerfile CHANGED
@@ -1,28 +1,47 @@
1
- # Use the official Python 3.9 slim image as the base
2
- FROM python:3.9-slim
3
 
4
- # Set the working directory inside the container
5
- WORKDIR /app
6
-
7
- # Install dependencies including ffmpeg and imagemagick
8
- RUN apt-get update && apt-get install -y --no-install-recommends \
9
  ffmpeg \
10
  imagemagick \
11
- libmagickwand-dev \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- # Copy the requirements file into the container
15
- COPY requirements.txt ./
16
 
17
- # Install Python dependencies from the requirements file
18
- RUN pip install --no-cache-dir -r requirements.txt
 
 
19
 
20
- # Copy all application files into the container
 
 
 
 
21
  COPY . .
22
 
23
- # Set permissions and run as a non-root user for security
24
- RUN chown -R nobody:nogroup /app && chmod 755 /app
25
- USER nobody
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- # Command to run the application using Uvicorn
28
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
+ FROM python:3.9
 
2
 
3
+ # Install system dependencies including ImageMagick
4
+ RUN apt-get update && apt-get install -y \
 
 
 
5
  ffmpeg \
6
  imagemagick \
 
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
+ # Configure ImageMagick policy to allow PDF operations
10
+ RUN sed -i 's/rights="none" pattern="@\*/rights="read|write" pattern="@\*/' /etc/ImageMagick-6/policy.xml
11
 
12
+ # Create necessary directories
13
+ WORKDIR /app
14
+ RUN mkdir -p /app/resources/temp_video
15
+ RUN chmod -R 777 /app/resources/temp_video
16
 
17
+ # Copy and install requirements
18
+ COPY requirements.txt .
19
+ RUN pip install -r requirements.txt
20
+
21
+ # Copy application code
22
  COPY . .
23
 
24
+ # Set permissions
25
+ RUN chown -R nobody:nogroup /app
26
+ RUN chmod -R 755 /app
27
+ RUN chmod -R 777 /tmp
28
+
29
+ # Update ImageMagick policy to allow operations
30
+ RUN mv /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.bak || true
31
+ RUN echo '<policymap> \
32
+ <policy domain="resource" name="memory" value="256MiB"/> \
33
+ <policy domain="resource" name="map" value="512MiB"/> \
34
+ <policy domain="resource" name="width" value="16KP"/> \
35
+ <policy domain="resource" name="height" value="16KP"/> \
36
+ <policy domain="resource" name="area" value="128MB"/> \
37
+ <policy domain="resource" name="disk" value="1GiB"/> \
38
+ <policy domain="delegate" rights="none" pattern="URL" /> \
39
+ <policy domain="delegate" rights="none" pattern="HTTPS" /> \
40
+ <policy domain="delegate" rights="none" pattern="HTTP" /> \
41
+ <policy domain="path" rights="none" pattern="@*" /> \
42
+ <policy domain="path" rights="read|write" pattern="@*"/> \
43
+ </policymap>' > /etc/ImageMagick-6/policy.xml
44
 
45
+ # Run the application
46
+ EXPOSE 8000
47
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]