mgbam commited on
Commit
262b6c2
·
verified ·
1 Parent(s): 6db1678

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +31 -12
Dockerfile CHANGED
@@ -24,7 +24,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
24
  libglib2.0-0 \
25
  && rm -rf /var/lib/apt/lists/*
26
 
27
- # Modify ImageMagick policy.xml to allow operations needed by MoviePy
28
  RUN if [ -f /etc/ImageMagick-6/policy.xml ]; then \
29
  XML_FILE="/etc/ImageMagick-6/policy.xml"; \
30
  echo "INFO: Modifying ImageMagick policy at $XML_FILE (v6) for MoviePy compatibility." ; \
@@ -48,13 +48,18 @@ RUN if [ -f /etc/ImageMagick-6/policy.xml ]; then \
48
 
49
  # Create a non-root user and group
50
  RUN groupadd -r appgroup && useradd --no-log-init -r -g appgroup -u 1000 appuser
51
- RUN mkdir -p /home/appuser/.cache && chown -R appuser:appgroup /home/appuser
 
52
 
53
  # Set Streamlit home directory to be writable by appuser
54
- ENV STREAMLIT_HOME=/home/appuser/.streamlit
 
 
 
 
55
  RUN mkdir -p $STREAMLIT_HOME && chown -R appuser:appgroup $STREAMLIT_HOME
56
 
57
- # Copy the requirements file first to leverage Docker cache
58
  COPY --chown=appuser:appgroup requirements.txt .
59
 
60
  # Install Python dependencies as the non-root user
@@ -62,15 +67,29 @@ USER appuser
62
  RUN pip install --no-cache-dir --upgrade pip && \
63
  pip install --no-cache-dir -r requirements.txt
64
 
65
- # Copy the rest of the application code into the container
66
- USER root # Switch back to root to copy to /app, then chown
67
- COPY --chown=appuser:appgroup . .
68
- USER appuser # Switch back to appuser
69
 
70
- # Create the output directory for media and ensure it's writable by appuser
71
- RUN mkdir -p /app/temp_cinegen_media
72
- # The assets directory also needs to be accessible
73
- RUN mkdir -p /app/assets/fonts
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  # Expose the port Streamlit runs on
76
  EXPOSE 8501
 
24
  libglib2.0-0 \
25
  && rm -rf /var/lib/apt/lists/*
26
 
27
+ # Modify ImageMagick policy.xml
28
  RUN if [ -f /etc/ImageMagick-6/policy.xml ]; then \
29
  XML_FILE="/etc/ImageMagick-6/policy.xml"; \
30
  echo "INFO: Modifying ImageMagick policy at $XML_FILE (v6) for MoviePy compatibility." ; \
 
48
 
49
  # Create a non-root user and group
50
  RUN groupadd -r appgroup && useradd --no-log-init -r -g appgroup -u 1000 appuser
51
+ # Create home directory structure for appuser, including .cache for pip
52
+ RUN mkdir -p /home/appuser/.cache/pip && chown -R appuser:appgroup /home/appuser
53
 
54
  # Set Streamlit home directory to be writable by appuser
55
+ # This directory will be created within /home/appuser, so appuser will own it.
56
+ ENV STREAMLIT_HOME=/home/appuser/.streamlit
57
+ # No need to mkdir/chown STREAMLIT_HOME here if appuser creates it at runtime,
58
+ # or if we ensure /home/appuser is writable by appuser.
59
+ # However, to be safe, especially if Streamlit tries to create it very early:
60
  RUN mkdir -p $STREAMLIT_HOME && chown -R appuser:appgroup $STREAMLIT_HOME
61
 
62
+ # Copy the requirements file first
63
  COPY --chown=appuser:appgroup requirements.txt .
64
 
65
  # Install Python dependencies as the non-root user
 
67
  RUN pip install --no-cache-dir --upgrade pip && \
68
  pip install --no-cache-dir -r requirements.txt
69
 
70
+ # Switch back to root temporarily for copying application files and setting permissions
71
+ USER root
72
+ COPY . .
73
+ RUN chown -R appuser:appgroup /app
74
 
75
+ # Create runtime directories as root, then chown to appuser
76
+ RUN mkdir -p /app/temp_cinegen_media && chown -R appuser:appgroup /app/temp_cinegen_media
77
+ RUN mkdir -p /app/assets/fonts && chown -R appuser:appgroup /app/assets/fonts
78
+ # Ensure custom fonts copied in assets/fonts are usable system-wide if needed by MoviePy's TextClip
79
+ # This assumes your 'arial.ttf' (or other custom fonts) are in 'assets/fonts/' in your project.
80
+ # If they are, copy them to a system font directory and update the font cache.
81
+ # The VisualEngine also tries to load from 'assets/fonts/' directly via Pillow.
82
+ RUN if [ -d "/app/assets/fonts" ] && [ "$(ls -A /app/assets/fonts)" ]; then \
83
+ mkdir -p /usr/local/share/fonts/truetype/cinegen_custom && \
84
+ cp /app/assets/fonts/*.*tf /usr/local/share/fonts/truetype/cinegen_custom/ 2>/dev/null || true && \
85
+ fc-cache -fv && \
86
+ echo "INFO: Copied custom fonts and refreshed font cache."; \
87
+ else \
88
+ echo "INFO: No custom fonts found in /app/assets/fonts to copy system-wide." ; \
89
+ fi
90
+
91
+ # Switch to the non-root user for running the application
92
+ USER appuser
93
 
94
  # Expose the port Streamlit runs on
95
  EXPOSE 8501