andhikagg commited on
Commit
12503ca
·
verified ·
1 Parent(s): 703b215

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +38 -27
Dockerfile CHANGED
@@ -1,43 +1,54 @@
1
- # Use Python 3.10 slim as the base image
2
- FROM python:3.10-slim
3
 
4
- # Install system dependencies for building C++ extensions
5
  USER root
 
 
 
 
 
 
 
 
 
 
6
  RUN apt-get update && apt-get install -y \
7
- build-essential \
8
- g++ \
9
- python3-dev \
10
- libsndfile1 \
11
  ffmpeg \
12
- && rm -rf /var/lib/apt/lists/*
13
-
14
- # Set up a non-root user as per Hugging Face recommendations
15
- RUN useradd -m -u 1000 user
 
 
 
 
 
16
  USER user
17
  ENV HOME=/home/user \
18
- PATH=/home/user/.local/bin:$PATH
19
 
20
- # Set working directory
21
  WORKDIR $HOME/app
22
 
23
- # Install pip 24.0 (to avoid previous pip>=24.1 issues)
24
  RUN pip install --no-cache-dir pip==24.0
25
 
26
- # Copy and install Python dependencies
27
- COPY --chown=user requirements.txt $HOME/app/requirements.txt
28
- RUN pip install --no-cache-dir -r requirements.txt
 
 
29
 
30
- # Copy the application code
31
- COPY --chown=user . $HOME/app
32
 
33
- # Download pre-trained models or assets (replace with actual URLs if needed)
34
- RUN mkdir -p content
35
- # Example: ADD --chown=user https://<SOME_ASSET_URL> content/<SOME_ASSET_NAME>
36
 
37
- # Expose port 7860 (Hugging Face default)
38
  EXPOSE 7860
39
 
40
- # Command to run the application with --api flag
41
- CMD ["python", "app.py", "--api"]
42
- # CMD ["python", "app.py"]
43
- # CMD ["gradio", "app.py", "--api"]
 
1
+ # Gunakan base image dengan hash agar match cache Hugging Face
2
+ FROM python:3.10@sha256:875c3591e586f66aa65621926230925144920c951902a6c2eef005d9783a7ca7
3
 
4
+ # Gunakan root dulu buat install awal
5
  USER root
6
+
7
+ # Pasang fakeroot + ubah apt-get, lalu buat user UID 1000
8
+ RUN apt-get update && apt-get install -y fakeroot && \
9
+ mv /usr/bin/apt-get /usr/bin/.apt-get && \
10
+ echo '#!/usr/bin/env sh\nfakeroot /usr/bin/.apt-get "$@"' > /usr/bin/apt-get && \
11
+ chmod +x /usr/bin/apt-get && \
12
+ rm -rf /var/lib/apt/lists/* && \
13
+ useradd -m -u 1000 user
14
+
15
+ # Install dependencies umum untuk ML / Gradio / media processing
16
  RUN apt-get update && apt-get install -y \
17
+ git \
18
+ git-lfs \
 
 
19
  ffmpeg \
20
+ libsm6 \
21
+ libxext6 \
22
+ libgl1-mesa-glx \
23
+ cmake \
24
+ rsync \
25
+ && rm -rf /var/lib/apt/lists/* && \
26
+ git lfs install
27
+
28
+ # Switch ke user Hugging Face standard (UID 1000)
29
  USER user
30
  ENV HOME=/home/user \
31
+ PATH=$HOME/.local/bin:$PATH
32
 
 
33
  WORKDIR $HOME/app
34
 
35
+ # Install pip versi 24.0 secara eksplisit
36
  RUN pip install --no-cache-dir pip==24.0
37
 
38
+ # Salin requirements.txt ke tempat sementara
39
+ COPY --chown=1000:1000 requirements.txt /tmp/pre-requirements.txt
40
+
41
+ # Install Python dependencies dari project
42
+ RUN pip install --no-cache-dir -r /tmp/pre-requirements.txt
43
 
44
+ # Salin seluruh kode project
45
+ COPY --link --chown=1000:1000 . .
46
 
47
+ # Simpan semua dependency ke freeze file (buat cache HF)
48
+ RUN pip freeze > /tmp/freeze.txt
 
49
 
50
+ # Expose port default Gradio / FastAPI
51
  EXPOSE 7860
52
 
53
+ # Jalankan app Python
54
+ CMD ["python", "app.py", "--api"]