Update Dockerfile
Browse files- Dockerfile +36 -35
Dockerfile
CHANGED
@@ -1,42 +1,46 @@
|
|
1 |
# Use an official Python runtime as a parent image
|
2 |
FROM python:3.10-slim-bullseye
|
3 |
|
4 |
-
# Set environment variables
|
5 |
ENV PYTHONUNBUFFERED 1
|
6 |
ENV PYTHONDONTWRITEBYTECODE 1
|
7 |
ENV PIP_NO_CACHE_DIR off
|
8 |
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
|
9 |
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
10 |
|
11 |
# Set the working directory in the container
|
12 |
WORKDIR /app
|
13 |
|
14 |
# Install system dependencies
|
15 |
# - ffmpeg for MoviePy audio/video processing
|
16 |
-
# - imagemagick for MoviePy TextClip and other image operations
|
17 |
-
# - git
|
18 |
-
# - fonts-dejavu-core
|
|
|
19 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
20 |
ffmpeg \
|
21 |
imagemagick \
|
22 |
git \
|
23 |
fonts-dejavu-core \
|
24 |
fonts-liberation \
|
25 |
-
|
|
|
26 |
&& rm -rf /var/lib/apt/lists/*
|
27 |
|
28 |
# Modify ImageMagick policy.xml to allow operations needed by MoviePy
|
29 |
# This is critical for TextClip and other ImageMagick-dependent features in MoviePy
|
30 |
-
# It attempts to find policy.xml for ImageMagick v6 or v7 and comments out restrictive lines.
|
31 |
RUN if [ -f /etc/ImageMagick-6/policy.xml ]; then \
|
32 |
XML_FILE="/etc/ImageMagick-6/policy.xml"; \
|
33 |
-
|
34 |
elif [ -f /etc/ImageMagick-7/policy.xml ]; then \
|
35 |
XML_FILE="/etc/ImageMagick-7/policy.xml"; \
|
36 |
-
|
37 |
else \
|
38 |
XML_FILE=""; \
|
39 |
-
|
40 |
fi && \
|
41 |
if [ -n "$XML_FILE" ] && [ -f "$XML_FILE" ]; then \
|
42 |
sed -i 's/<policy domain="path" rights="none" pattern="@\*"\/>/<!-- <policy domain="path" rights="none" pattern="@\*" \/> -->/' "$XML_FILE" && \
|
@@ -46,42 +50,39 @@ RUN if [ -f /etc/ImageMagick-6/policy.xml ]; then \
|
|
46 |
sed -i 's/<policy domain="coder" rights="none" pattern="MSL"\/>/<!-- <policy domain="coder" rights="none" pattern="MSL" \/> -->/' "$XML_FILE" && \
|
47 |
sed -i 's/<policy domain="coder" rights="none" pattern="HTTPS"\/>/<!-- <policy domain="coder" rights="none" pattern="HTTPS" \/> -->/' "$XML_FILE" && \
|
48 |
sed -i 's/<policy domain="coder" rights="none" pattern="HTTP"\/>/<!-- <policy domain="coder" rights="none" pattern="HTTP" \/> -->/' "$XML_FILE" && \
|
49 |
-
|
50 |
fi
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
# Copy the requirements file first to leverage Docker cache
|
53 |
-
COPY requirements.txt .
|
54 |
|
55 |
-
# Install Python dependencies
|
56 |
-
|
57 |
-
|
|
|
58 |
|
59 |
# Copy the rest of the application code into the container
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
# This assumes your 'arial.ttf' (or other custom fonts) are in 'assets/fonts/' in your project
|
64 |
-
# Adjust the source path ('assets/fonts/arial.ttf') if your font is located elsewhere.
|
65 |
-
RUN mkdir -p /usr/local/share/fonts/truetype/mycustomfonts && \
|
66 |
-
if [ -f assets/fonts/arial.ttf ]; then \
|
67 |
-
cp assets/fonts/arial.ttf /usr/local/share/fonts/truetype/mycustomfonts/arial.ttf && \
|
68 |
-
echo "INFO: Copied arial.ttf to custom font directory." ; \
|
69 |
-
else \
|
70 |
-
echo "WARNING: assets/fonts/arial.ttf not found. Ensure fonts are available for Pillow/MoviePy." ; \
|
71 |
-
fi && \
|
72 |
-
fc-cache -fv # Update the system font cache
|
73 |
|
74 |
-
# Create the output directory for media and ensure it's writable
|
75 |
-
#
|
76 |
-
RUN mkdir -p /app/temp_cinegen_media
|
77 |
-
#
|
78 |
-
|
79 |
|
80 |
# Expose the port Streamlit runs on
|
81 |
EXPOSE 8501
|
82 |
|
83 |
# Define the command to run the application
|
84 |
# Use 0.0.0.0 to make the app accessible from outside the container
|
85 |
-
|
86 |
-
# For local Docker runs, this will be used.
|
87 |
-
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
1 |
# Use an official Python runtime as a parent image
|
2 |
FROM python:3.10-slim-bullseye
|
3 |
|
4 |
+
# Set environment variables for Python, pip, and locale
|
5 |
ENV PYTHONUNBUFFERED 1
|
6 |
ENV PYTHONDONTWRITEBYTECODE 1
|
7 |
ENV PIP_NO_CACHE_DIR off
|
8 |
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
|
9 |
ENV DEBIAN_FRONTEND=noninteractive
|
10 |
+
# Set a UTF-8 locale to prevent potential encoding issues with filenames or text processing
|
11 |
+
ENV LANG C.UTF-8
|
12 |
+
ENV LC_ALL C.UTF-8
|
13 |
|
14 |
# Set the working directory in the container
|
15 |
WORKDIR /app
|
16 |
|
17 |
# Install system dependencies
|
18 |
# - ffmpeg for MoviePy audio/video processing
|
19 |
+
# - imagemagick for MoviePy TextClip and other image operations (ensure it's v6 or v7 compatible with policy fix)
|
20 |
+
# - git for pip requirements from git
|
21 |
+
# - fonts-dejavu-core, fonts-liberation for general font availability
|
22 |
+
# - libgl1-mesa-glx, libglib2.0-0 often needed for CV/GUI libraries, though maybe not strictly for this app yet
|
23 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
24 |
ffmpeg \
|
25 |
imagemagick \
|
26 |
git \
|
27 |
fonts-dejavu-core \
|
28 |
fonts-liberation \
|
29 |
+
libgl1-mesa-glx \
|
30 |
+
libglib2.0-0 \
|
31 |
&& rm -rf /var/lib/apt/lists/*
|
32 |
|
33 |
# Modify ImageMagick policy.xml to allow operations needed by MoviePy
|
34 |
# This is critical for TextClip and other ImageMagick-dependent features in MoviePy
|
|
|
35 |
RUN if [ -f /etc/ImageMagick-6/policy.xml ]; then \
|
36 |
XML_FILE="/etc/ImageMagick-6/policy.xml"; \
|
37 |
+
logger -s "INFO: Modifying ImageMagick policy at $XML_FILE (v6) for MoviePy compatibility." ; \
|
38 |
elif [ -f /etc/ImageMagick-7/policy.xml ]; then \
|
39 |
XML_FILE="/etc/ImageMagick-7/policy.xml"; \
|
40 |
+
logger -s "INFO: Modifying ImageMagick policy at $XML_FILE (v7) for MoviePy compatibility." ; \
|
41 |
else \
|
42 |
XML_FILE=""; \
|
43 |
+
logger -s "WARNING: ImageMagick policy.xml not found in /etc/ImageMagick-[67]/. MoviePy TextClip might fail." ; \
|
44 |
fi && \
|
45 |
if [ -n "$XML_FILE" ] && [ -f "$XML_FILE" ]; then \
|
46 |
sed -i 's/<policy domain="path" rights="none" pattern="@\*"\/>/<!-- <policy domain="path" rights="none" pattern="@\*" \/> -->/' "$XML_FILE" && \
|
|
|
50 |
sed -i 's/<policy domain="coder" rights="none" pattern="MSL"\/>/<!-- <policy domain="coder" rights="none" pattern="MSL" \/> -->/' "$XML_FILE" && \
|
51 |
sed -i 's/<policy domain="coder" rights="none" pattern="HTTPS"\/>/<!-- <policy domain="coder" rights="none" pattern="HTTPS" \/> -->/' "$XML_FILE" && \
|
52 |
sed -i 's/<policy domain="coder" rights="none" pattern="HTTP"\/>/<!-- <policy domain="coder" rights="none" pattern="HTTP" \/> -->/' "$XML_FILE" && \
|
53 |
+
logger -s "INFO: ImageMagick policy modifications applied to $XML_FILE." ; \
|
54 |
fi
|
55 |
|
56 |
+
# Create a non-root user and group
|
57 |
+
RUN groupadd -r appgroup && useradd --no-log-init -r -g appgroup -u 1000 appuser
|
58 |
+
RUN mkdir -p /home/appuser/.cache && chown -R appuser:appgroup /home/appuser
|
59 |
+
|
60 |
+
# Set Streamlit home directory to be writable by appuser
|
61 |
+
ENV STREAMLIT_HOME=/home/appuser/.streamlit
|
62 |
+
RUN mkdir -p $STREAMLIT_HOME && chown -R appuser:appgroup $STREAMLIT_HOME
|
63 |
+
|
64 |
# Copy the requirements file first to leverage Docker cache
|
65 |
+
COPY --chown=appuser:appgroup requirements.txt .
|
66 |
|
67 |
+
# Install Python dependencies as the non-root user
|
68 |
+
USER appuser
|
69 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
70 |
+
pip install --no-cache-dir -r requirements.txt
|
71 |
|
72 |
# Copy the rest of the application code into the container
|
73 |
+
USER root # Switch back to root to copy to /app, then chown
|
74 |
+
COPY --chown=appuser:appgroup . .
|
75 |
+
USER appuser # Switch back to appuser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
# Create the output directory for media and ensure it's writable by appuser
|
78 |
+
# This should already be under /app which is owned by appuser now.
|
79 |
+
RUN mkdir -p /app/temp_cinegen_media
|
80 |
+
# The assets directory also needs to be accessible
|
81 |
+
RUN mkdir -p /app/assets/fonts
|
82 |
|
83 |
# Expose the port Streamlit runs on
|
84 |
EXPOSE 8501
|
85 |
|
86 |
# Define the command to run the application
|
87 |
# Use 0.0.0.0 to make the app accessible from outside the container
|
88 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--global.sharingMode=off", "--client.gatherUsageStats=false"]
|
|
|
|