File size: 1,138 Bytes
14067dc
 
 
3910467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14067dc
 
 
 
 
 
 
3910467
 
14067dc
3910467
 
14067dc
3910467
 
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
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile

# Stage 1: Build dependencies
FROM python:3.11-slim AS build

# Install system dependencies (pillow, torch dll butuh ini)
RUN apt-get update && apt-get install -y \
    build-essential \
    libjpeg-dev \
    zlib1g-dev \
    && rm -rf /var/lib/apt/lists/*

# Buat user non-root
RUN useradd -m -u 1000 user

# Set workdir & salin requirements
WORKDIR /app
COPY --chown=user requirements.txt .

# Install pip packages secara lokal (non-root)
RUN pip install --no-cache-dir --user -r requirements.txt

---

# Stage 2: Final image (lebih ringan)
FROM python:3.11-slim

RUN apt-get update && apt-get install -y \
    libjpeg-dev \
    zlib1g-dev \
    && rm -rf /var/lib/apt/lists/*

RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

WORKDIR /app

# Copy pip packages hasil install dari stage build
COPY --from=build /home/user/.local /home/user/.local

# Copy file kode app kamu
COPY --chown=user . .

EXPOSE 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]