Update Dockerfile
Browse files- Dockerfile +74 -51
Dockerfile
CHANGED
|
@@ -1,64 +1,87 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
ffmpeg \
|
| 9 |
-
libsm6 \
|
| 10 |
-
libxext6 \
|
| 11 |
-
fontconfig \
|
| 12 |
-
imagemagick \
|
| 13 |
-
ghostscript && \
|
| 14 |
-
( \
|
| 15 |
-
POLICY_FILE=$(find /etc/ImageMagick* -name policy.xml -print -quit 2>/dev/null) && \
|
| 16 |
-
if [ -n "$POLICY_FILE" ] && [ -f "$POLICY_FILE" ]; then \
|
| 17 |
-
echo "INFO: Modifying ImageMagick policy file: $POLICY_FILE"; \
|
| 18 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="PS" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
| 19 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="EPS" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
| 20 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
| 21 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="TEXT" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
| 22 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="LABEL" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
| 23 |
-
sed -i 's/<policy domain="path" rights="none" pattern="@*" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
| 24 |
-
echo "INFO: ImageMagick policy potentially updated."; \
|
| 25 |
-
else \
|
| 26 |
-
echo "WARNING: ImageMagick policy.xml not found. TextClip might fail."; \
|
| 27 |
-
fi \
|
| 28 |
-
) && \
|
| 29 |
-
apt-get clean && \
|
| 30 |
-
rm -rf /var/lib/apt/lists/*
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
RUN groupadd --gid $APP_USER_GID appgroup && \
|
| 40 |
-
useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
# Copy
|
| 46 |
-
COPY requirements.txt ./
|
| 47 |
-
RUN python -m pip install --no-cache-dir --upgrade pip && \
|
| 48 |
-
python -m pip install --no-cache-dir -r requirements.txt
|
| 49 |
-
|
| 50 |
-
# Copy all application code
|
| 51 |
COPY . .
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
| 62 |
|
|
|
|
| 63 |
EXPOSE 8501
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 in case requirements.txt pulls from git repositories
|
| 18 |
+
# - fonts-dejavu-core and fonts-liberation for general font availability
|
| 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 |
+
# Add any other system-level packages your app might need (e.g., build-essential if compiling C extensions)
|
| 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 |
+
echo "INFO: Modifying ImageMagick policy at $XML_FILE (v6) for MoviePy compatibility." ; \
|
| 34 |
+
elif [ -f /etc/ImageMagick-7/policy.xml ]; then \
|
| 35 |
+
XML_FILE="/etc/ImageMagick-7/policy.xml"; \
|
| 36 |
+
echo "INFO: Modifying ImageMagick policy at $XML_FILE (v7) for MoviePy compatibility." ; \
|
| 37 |
+
else \
|
| 38 |
+
XML_FILE=""; \
|
| 39 |
+
echo "WARNING: ImageMagick policy.xml not found in expected /etc/ImageMagick-[67]/ locations. MoviePy TextClip might fail." ; \
|
| 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" && \
|
| 43 |
+
sed -i 's/<policy domain="coder" rights="none" pattern="TEXT"\/>/<!-- <policy domain="coder" rights="none" pattern="TEXT" \/> -->/' "$XML_FILE" && \
|
| 44 |
+
sed -i 's/<policy domain="coder" rights="none" pattern="LABEL"\/>/<!-- <policy domain="coder" rights="none" pattern="LABEL" \/> -->/' "$XML_FILE" && \
|
| 45 |
+
sed -i 's/<policy domain="coder" rights="none" pattern="MVG"\/>/<!-- <policy domain="coder" rights="none" pattern="MVG" \/> -->/' "$XML_FILE" && \
|
| 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 |
+
echo "INFO: ImageMagick policy modifications attempted." ; \
|
| 50 |
+
fi
|
| 51 |
|
| 52 |
+
# Copy the requirements file first to leverage Docker cache
|
| 53 |
+
COPY requirements.txt .
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
# Install Python dependencies
|
| 56 |
+
RUN pip install --upgrade pip && \
|
| 57 |
+
pip install -r requirements.txt
|
| 58 |
|
| 59 |
+
# Copy the rest of the application code into the container
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
COPY . .
|
| 61 |
|
| 62 |
+
# Create a directory for fonts if it doesn't exist and copy custom fonts
|
| 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 |
+
# The Hugging Face Spaces environment usually runs as 'appuser' (UID 1000)
|
| 76 |
+
RUN mkdir -p /app/temp_cinegen_media && chown -R 1000:1000 /app/temp_cinegen_media
|
| 77 |
+
# If running locally as root, this chown might not be strictly necessary,
|
| 78 |
+
# but it's good practice for environments that use a non-root user.
|
| 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 |
+
# The Hugging Face Spaces environment might override this CMD or provide its own startup script.
|
| 86 |
+
# For local Docker runs, this will be used.
|
| 87 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|