Dnfs commited on
Commit
3080fd5
·
verified ·
1 Parent(s): 778eaf5

Update dockerfile

Browse files
Files changed (1) hide show
  1. dockerfile +22 -17
dockerfile CHANGED
@@ -1,31 +1,36 @@
 
1
  FROM python:3.10-slim
2
 
3
- WORKDIR /app
 
 
4
 
5
- # Install system dependencies
6
- RUN apt-get update && apt-get install -y \
7
- build-essential \
8
- curl \
9
- && rm -rf /var/lib/apt/lists/*
10
 
11
- # Copy requirements first for better caching
12
- COPY requirements.txt .
13
 
14
- # Install Python dependencies
15
- RUN pip install --no-cache-dir -r requirements.txt
16
 
17
- # Copy application code
18
- COPY app.py .
 
 
 
19
 
20
- # Create cache directory
21
- RUN mkdir -p /root/.cache/huggingface
22
 
23
- # Expose port
24
  EXPOSE 8000
25
 
26
- # Health check
27
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
28
  CMD curl -f http://localhost:8000/health || exit 1
29
 
30
- # Run the application
31
  CMD ["python", "app.py"]
 
1
+ # 1. Base Image
2
  FROM python:3.10-slim
3
 
4
+ # 2. Set up a non-root user
5
+ RUN useradd -m -u 1000 user
6
+ USER user
7
 
8
+ # 3. Set Environment Variables & Working Directory
9
+ ENV HOME=/home/user
10
+ ENV PATH=$HOME/.local/bin:$PATH
11
+ WORKDIR $HOME/app
 
12
 
13
+ # 4. Copy requirements first for better Docker layer caching
14
+ COPY --chown=user requirements.txt .
15
 
16
+ # 5. Install Python dependencies for the non-root user
17
+ RUN pip install --no-cache-dir --user -r requirements.txt
18
 
19
+ # 6. Download the model during the build process
20
+ # Ini memastikan model sudah ada di dalam image dan tidak diunduh setiap kali Space startup
21
+ RUN huggingface-cli download Dnfs/gema-4b-indra10k-model1-Q4_K_M-GGUF \
22
+ --local-dir ./model \
23
+ --local-dir-use-symlinks False
24
 
25
+ # 7. Copy the rest of the application code
26
+ COPY --chown=user app.py .
27
 
28
+ # 8. Expose the port the app runs on
29
  EXPOSE 8000
30
 
31
+ # 9. Health check to ensure the app is running
32
  HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
33
  CMD curl -f http://localhost:8000/health || exit 1
34
 
35
+ # 10. Command to run the application
36
  CMD ["python", "app.py"]