File size: 1,160 Bytes
1ce5c45
 
d828ce4
df73b1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d828ce4
df73b1b
a4c773d
 
d828ce4
df73b1b
a4c773d
 
df73b1b
a4c773d
 
 
 
 
 
 
2bd30ac
a4c773d
1ce5c45
a4c773d
 
 
 
d828ce4
1ce5c45
d828ce4
df73b1b
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
# Use Python 3.12 slim image as base
FROM python:3.12-slim

# First: System-level operations that require root
RUN apt-get update && apt-get install -y \
    bash \
    wget \
    git \
    git-lfs \
    && rm -rf /var/lib/apt/lists/*

# Second: Create user and set up directories
RUN useradd -m -u 1000 user && \
    mkdir -p /app/logs /app/.cache /app/models && \
    chmod 777 /app/logs /app/.cache /app/models && \
    chown -R user:user /app

# Third: Switch context to user
USER user

# Fourth: Set up environment for user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Fifth: Set working directory
WORKDIR $HOME/app

# Rest of the Dockerfile continues with user-level operations
COPY --chown=user requirements.txt .

RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

COPY --chown=user main $HOME/app/main
COPY --chown=user utils $HOME/app/utils

ENV PYTHONPATH=$HOME/app/main
ENV PYTHONUNBUFFERED=1
ENV HF_HOME=$HOME/app/.cache

RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
    export HF_TOKEN=$(cat /run/secrets/HF_TOKEN)

EXPOSE 7680

CMD ["python", "-m", "main.app"]