fahmiaziz98 commited on
Commit
3910467
·
1 Parent(s): c034083

refactor dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +35 -5
Dockerfile CHANGED
@@ -1,7 +1,35 @@
1
  # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
  # you will also find guides on how best to write your Dockerfile
3
 
4
- FROM python:3.11.11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  RUN useradd -m -u 1000 user
7
  USER user
@@ -9,9 +37,11 @@ ENV PATH="/home/user/.local/bin:$PATH"
9
 
10
  WORKDIR /app
11
 
12
- COPY --chown=user ./requirements.txt requirements.txt
13
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
 
15
- COPY --chown=user . /app
16
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
17
 
 
 
 
1
  # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
  # you will also find guides on how best to write your Dockerfile
3
 
4
+ # Stage 1: Build dependencies
5
+ FROM python:3.11-slim AS build
6
+
7
+ # Install system dependencies (pillow, torch dll butuh ini)
8
+ RUN apt-get update && apt-get install -y \
9
+ build-essential \
10
+ libjpeg-dev \
11
+ zlib1g-dev \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # Buat user non-root
15
+ RUN useradd -m -u 1000 user
16
+
17
+ # Set workdir & salin requirements
18
+ WORKDIR /app
19
+ COPY --chown=user requirements.txt .
20
+
21
+ # Install pip packages secara lokal (non-root)
22
+ RUN pip install --no-cache-dir --user -r requirements.txt
23
+
24
+ ---
25
+
26
+ # Stage 2: Final image (lebih ringan)
27
+ FROM python:3.11-slim
28
+
29
+ RUN apt-get update && apt-get install -y \
30
+ libjpeg-dev \
31
+ zlib1g-dev \
32
+ && rm -rf /var/lib/apt/lists/*
33
 
34
  RUN useradd -m -u 1000 user
35
  USER user
 
37
 
38
  WORKDIR /app
39
 
40
+ # Copy pip packages hasil install dari stage build
41
+ COPY --from=build /home/user/.local /home/user/.local
42
 
43
+ # Copy file kode app kamu
44
+ COPY --chown=user . .
45
 
46
+ EXPOSE 7860
47
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]