Update Dockerfile
Browse files- Dockerfile +19 -21
Dockerfile
CHANGED
@@ -11,55 +11,53 @@ RUN apt-get update && \
|
|
11 |
fontconfig \
|
12 |
imagemagick \
|
13 |
ghostscript && \
|
14 |
-
# Modify ImageMagick policy to be less restrictive for TextClip
|
15 |
-
# This entire block is a single shell command executed by RUN
|
16 |
-
# The semicolon after the fi is important for shell syntax if followed by &&
|
17 |
-
# We ensure the subshell commands are properly chained with && inside the subshell
|
18 |
-
# and the whole subshell is one command in the RUN sequence.
|
19 |
( \
|
20 |
POLICY_FILE=$(find /etc/ImageMagick* -name policy.xml -print -quit 2>/dev/null) && \
|
21 |
if [ -n "$POLICY_FILE" ] && [ -f "$POLICY_FILE" ]; then \
|
22 |
echo "INFO: Modifying ImageMagick policy file: $POLICY_FILE"; \
|
23 |
sed -i 's/<policy domain="coder" rights="none" pattern="PS" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
24 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="PS2" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
25 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="PS3" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
26 |
sed -i 's/<policy domain="coder" rights="none" pattern="EPS" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
27 |
sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
28 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="XPS" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
29 |
-
sed -i 's/<policy domain="coder" rights="none" pattern="LABEL" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
30 |
sed -i 's/<policy domain="coder" rights="none" pattern="TEXT" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
|
|
31 |
sed -i 's/<policy domain="path" rights="none" pattern="@*" \/>/<!-- & -->/' "$POLICY_FILE" && \
|
32 |
echo "INFO: ImageMagick policy potentially updated."; \
|
33 |
else \
|
34 |
-
echo "WARNING: ImageMagick policy.xml not found
|
35 |
fi \
|
36 |
) && \
|
37 |
apt-get clean && \
|
38 |
rm -rf /var/lib/apt/lists/*
|
39 |
|
40 |
-
# Create directory for custom fonts and copy your font file(s)
|
41 |
RUN mkdir -p /usr/local/share/fonts/truetype/mycustomfonts
|
42 |
COPY assets/fonts/arial.ttf /usr/local/share/fonts/truetype/mycustomfonts/arial.ttf
|
43 |
-
|
44 |
-
# Rebuild font cache AFTER copying fonts
|
45 |
RUN fc-cache -f -s -v
|
46 |
|
47 |
-
# Create a non-root user and group
|
48 |
ARG APP_USER_UID=1000
|
49 |
ARG APP_USER_GID=1000
|
50 |
RUN groupadd --gid $APP_USER_GID appgroup && \
|
51 |
useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser
|
52 |
|
53 |
-
WORKDIR /home/appuser/app
|
54 |
-
COPY --chown=appuser:appgroup requirements.txt ./
|
55 |
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
|
|
|
|
63 |
|
64 |
EXPOSE 8501
|
65 |
CMD ["streamlit", "run", "app.py", "--server.headless=true", "--server.port=8501", "--server.fileWatcherType=none"]
|
|
|
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 |
RUN mkdir -p /usr/local/share/fonts/truetype/mycustomfonts
|
33 |
COPY assets/fonts/arial.ttf /usr/local/share/fonts/truetype/mycustomfonts/arial.ttf
|
|
|
|
|
34 |
RUN fc-cache -f -s -v
|
35 |
|
|
|
36 |
ARG APP_USER_UID=1000
|
37 |
ARG APP_USER_GID=1000
|
38 |
RUN groupadd --gid $APP_USER_GID appgroup && \
|
39 |
useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser
|
40 |
|
41 |
+
WORKDIR /home/appuser/app # Set WORKDIR for appuser's home/app space
|
|
|
42 |
|
43 |
+
# Copy requirements first (as root or default builder user)
|
44 |
+
COPY requirements.txt ./
|
45 |
+
RUN python -m pip install --no-cache-dir --upgrade pip && \
|
46 |
+
python -m pip install --no-cache-dir -r requirements.txt
|
47 |
+
|
48 |
+
# Copy all application code
|
49 |
+
COPY . .
|
50 |
|
51 |
+
# Ensure the output directory exists and is writable by appuser BEFORE switching user
|
52 |
+
# Create it as root, then chown specifically, then chown the whole app dir.
|
53 |
+
RUN mkdir -p /home/appuser/app/temp_cinegen_media && \
|
54 |
+
chown -R appuser:appgroup /home/appuser/app/temp_cinegen_media && \
|
55 |
+
chown -R appuser:appgroup /home/appuser/app
|
56 |
+
# chmod -R 775 /home/appuser/app/temp_cinegen_media # Optionally, more explicit permissions
|
57 |
|
58 |
+
# Switch to the non-root user
|
59 |
+
USER appuser
|
60 |
+
ENV PATH="/home/appuser/.local/bin:${PATH}"
|
61 |
|
62 |
EXPOSE 8501
|
63 |
CMD ["streamlit", "run", "app.py", "--server.headless=true", "--server.port=8501", "--server.fileWatcherType=none"]
|