thanhkt commited on
Commit
4f31e9e
·
verified ·
1 Parent(s): 0307c45

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +40 -39
Dockerfile CHANGED
@@ -1,62 +1,63 @@
1
- # Use a minimal Python base image
2
  FROM python:3.12-slim
3
 
4
- # Install dependencies and clean up in a single layer
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
- gcc libffi-dev curl ca-certificates python3-dev pkg-config \
7
- libcairo2-dev libpango1.0-dev ffmpeg wget perl fontconfig \
8
- fonts-dejavu texlive-full texlive-binaries \
9
- && apt-get clean && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- # Create a non-root user
12
- RUN useradd -m -u 1000 user
13
 
14
- # Install uv for faster package installation
15
  ADD https://astral.sh/uv/install.sh /uv-installer.sh
16
  RUN sh /uv-installer.sh && rm /uv-installer.sh
17
  ENV PATH="/root/.local/bin:${PATH}"
18
 
19
- # Set up the working directory
20
- WORKDIR /app
21
 
22
- # Copy and install dependencies first (leverage Docker cache)
23
- COPY requirements.txt /app/
24
  RUN uv venv /app/manimations \
25
  && . /app/manimations/bin/activate \
26
  && uv pip install --no-cache -r requirements.txt \
27
  && uv pip install --no-cache pycairo pangocffi manim
28
 
29
- # Add virtual environment to PATH
30
  ENV PATH="/app/manimations/bin:${PATH}"
31
 
32
- # Copy the application code
33
  COPY *.py /app/
34
- COPY .env /app/
35
-
36
- # Set environment variables
37
- ENV PYTHONPATH=/app \
38
- MPLBACKEND=Agg \
39
- GRADIO_SERVER_NAME=0.0.0.0 \
40
- GRADIO_SERVER_PORT=7860 \
41
- FONTCONFIG_PATH=/home/user/.cache/fontconfig \
42
- PYTHONWARNINGS="ignore::SyntaxWarning" \
43
- HOME=/home/user \
44
- TEXMFVAR=/home/user/texmf-var
45
-
46
- # Create necessary directories with proper permissions
47
- RUN mkdir -p /app/generated_videos /home/user/.cache/huggingface \
48
- /home/user/.cache/fontconfig /home/user/texmf-var \
49
- && chown -R user:user /app /home/user \
50
- && chmod +x $(which dvisvgm)
51
-
52
- # Verify latex installation
53
- RUN which latex && ls -la $(which latex) && which dvisvgm && ls -la $(which dvisvgm)
54
 
55
  # Switch to non-root user
56
- USER user
57
 
58
- # Expose the port for Gradio
59
  EXPOSE 7860
60
 
61
- # Command to run the application
62
- CMD ["/app/manimations/bin/python", "ai_agent.py"]
 
 
1
  FROM python:3.12-slim
2
 
3
+ # Install all dependencies in one layer
4
  RUN apt-get update && apt-get install -y --no-install-recommends \
5
+ gcc \
6
+ libffi-dev \
7
+ curl \
8
+ ca-certificates \
9
+ python3-dev \
10
+ pkg-config \
11
+ libcairo2-dev \
12
+ libpango1.0-dev \
13
+ ffmpeg \
14
+ texlive-full \
15
+ dvisvgm \
16
+ fonts-dejavu \
17
+ && apt-get clean \
18
+ && rm -rf /var/lib/apt/lists/* \
19
+ && which dvisvgm
20
+
21
+ # Create a non-root user to run the application
22
+ RUN groupadd -r appuser && useradd -r -g appuser -m appuser
23
 
24
+ WORKDIR /app
 
25
 
26
+ # Install uv for faster pip operations
27
  ADD https://astral.sh/uv/install.sh /uv-installer.sh
28
  RUN sh /uv-installer.sh && rm /uv-installer.sh
29
  ENV PATH="/root/.local/bin:${PATH}"
30
 
31
+ # Copy virtual environment and project files
32
+ COPY requirements.txt .
33
 
34
+ # Create and activate virtual environment, install packages
 
35
  RUN uv venv /app/manimations \
36
  && . /app/manimations/bin/activate \
37
  && uv pip install --no-cache -r requirements.txt \
38
  && uv pip install --no-cache pycairo pangocffi manim
39
 
40
+ # Add manim to PATH
41
  ENV PATH="/app/manimations/bin:${PATH}"
42
 
 
43
  COPY *.py /app/
44
+
45
+ # Set environment variables (use environment variable instead of .env file)
46
+ ENV PYTHONPATH=/app
47
+ ENV MPLBACKEND=Agg
48
+ ENV GRADIO_SERVER_NAME=0.0.0.0
49
+ ENV GRADIO_SERVER_PORT=7860
50
+ ENV TOGETHER_API_KEY=cee1393e4d4e7a94121882052a03f30a1d51f5dbd251140844ec616e17f60e9b
51
+
52
+ # Create directory for generated videos with proper permissions
53
+ RUN mkdir -p /app/generated_videos && \
54
+ chown -R appuser:appuser /app
 
 
 
 
 
 
 
 
 
55
 
56
  # Switch to non-root user
57
+ USER appuser
58
 
59
+ # Expose the port for the Gradio interface
60
  EXPOSE 7860
61
 
62
+ # Command to run the application with the virtual environment
63
+ CMD ["/app/manimations/bin/python", "ai_agent.py"]