fahmiaziz98 commited on
Commit
7933a0e
·
1 Parent(s): 23a2f96

refactor dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +8 -14
Dockerfile CHANGED
@@ -1,29 +1,25 @@
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
- # Stage 2: Final image (lebih ringan)
26
- FROM python:3.11-slim
27
 
28
  RUN apt-get update && apt-get install -y \
29
  libjpeg-dev \
@@ -36,11 +32,9 @@ ENV PATH="/home/user/.local/bin:$PATH"
36
 
37
  WORKDIR /app
38
 
39
- # Copy pip packages hasil install dari stage build
40
  COPY --from=build /home/user/.local /home/user/.local
41
-
42
- # Copy file kode app kamu
43
  COPY --chown=user . .
44
 
45
  EXPOSE 7860
46
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
1
  # Stage 1: Build dependencies
2
+ FROM python:3.11.11-slim AS build
3
 
 
4
  RUN apt-get update && apt-get install -y \
5
  build-essential \
6
  libjpeg-dev \
7
  zlib1g-dev \
8
  && rm -rf /var/lib/apt/lists/*
9
 
 
10
  RUN useradd -m -u 1000 user
11
 
12
+ USER user
13
+ ENV PATH="/home/user/.local/bin:$PATH"
14
+
15
  WORKDIR /app
16
+
17
  COPY --chown=user requirements.txt .
18
 
 
19
  RUN pip install --no-cache-dir --user -r requirements.txt
20
 
21
+ # Stage 2: Final image
22
+ FROM python:3.11.11-slim
 
23
 
24
  RUN apt-get update && apt-get install -y \
25
  libjpeg-dev \
 
32
 
33
  WORKDIR /app
34
 
 
35
  COPY --from=build /home/user/.local /home/user/.local
 
 
36
  COPY --chown=user . .
37
 
38
  EXPOSE 7860
39
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
40
+