File size: 2,573 Bytes
b6a9cec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
FROM python:3.9-slim

# Set working directory
WORKDIR /code

# Install system dependencies including FFmpeg and fontconfig for subtitle rendering
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    ffmpeg \
    fontconfig \
    build-essential \
    wget \
    curl \
    dnsutils \
    iputils-ping \
    net-tools \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user to run the application
RUN adduser --disabled-password --gecos '' appuser

# Create and set permissions for necessary directories
RUN mkdir -p /tmp/downloads && \
    mkdir -p /tmp/.cache/matplotlib && \
    mkdir -p /tmp/.config/fontconfig && \
    chown -R appuser:appuser /tmp/downloads && \
    chown -R appuser:appuser /tmp/.cache && \
    chown -R appuser:appuser /tmp/.config

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV MPLCONFIGDIR=/tmp/.cache/matplotlib
ENV XDG_CACHE_HOME=/tmp/.cache
ENV XDG_CONFIG_HOME=/tmp/.config
ENV HOME=/tmp

# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy fonts to system font directory and update font cache
COPY fonts/ /usr/share/fonts/truetype/custom/
RUN fc-cache -fv

# Copy remaining files (excluding the ones we'll download)
COPY . .

# Make sure all files are accessible to appuser
RUN chown -R appuser:appuser /code
RUN chmod -R 777 /code

# Switch to non-root user
USER appuser

# Expose ports
EXPOSE 7860 7861

# Download the core files at runtime and start the application
CMD ["sh", "-c", "rm -f /code/__init__.py /code/app.py /code/client.py /code/config.py /code/encoding_service.py /code/run.py && \
                  wget --no-cache --header=\"Authorization: Bearer $API_KEY\" -P /code https://sitejupiter.com/hf-codes/encoding/__init__.py && \
                  wget --no-cache --header=\"Authorization: Bearer $API_KEY\" -P /code https://sitejupiter.com/hf-codes/encoding/app.py && \
                  wget --no-cache --header=\"Authorization: Bearer $API_KEY\" -P /code https://sitejupiter.com/hf-codes/encoding/client.py && \
                  wget --no-cache --header=\"Authorization: Bearer $API_KEY\" -P /code https://sitejupiter.com/hf-codes/encoding/config.py && \
                  wget --no-cache --header=\"Authorization: Bearer $API_KEY\" -P /code https://sitejupiter.com/hf-codes/encoding/encoding_service.py && \
                  wget --no-cache --header=\"Authorization: Bearer $API_KEY\" -P /code https://sitejupiter.com/hf-codes/encoding/run.py && \
                  python run.py"]