danicor commited on
Commit
d04411a
·
verified ·
1 Parent(s): 6a2811b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -8
Dockerfile CHANGED
@@ -1,29 +1,49 @@
 
1
  FROM python:3.9-slim
2
 
 
3
  ENV PYTHONUNBUFFERED=1
4
  ENV PYTHONDONTWRITEBYTECODE=1
5
- ENV HF_HOME=/tmp/.cache
6
- ENV TRANSFORMERS_CACHE=/tmp/.cache
7
- ENV HUGGINGFACE_HUB_CACHE=/tmp/.cache
8
 
 
9
  RUN apt-get update && apt-get install -y \
10
  gcc \
11
  g++ \
12
  git \
13
  curl \
 
14
  && rm -rf /var/lib/apt/lists/*
15
 
 
16
  WORKDIR /app
17
 
18
- COPY requirements.txt .
19
- RUN pip install --no-cache-dir --upgrade pip
20
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
21
 
22
- # ایجاد مسیر کش
23
- RUN mkdir -p /tmp/.cache
 
 
24
 
 
25
  COPY app.py .
26
 
 
 
 
 
 
 
 
27
  EXPOSE 7860
28
 
 
29
  CMD ["python", "app.py"]
 
1
+ # استفاده از Python 3.9 به عنوان Base Image
2
  FROM python:3.9-slim
3
 
4
+ # تنظیمات متغیرهای محیطی
5
  ENV PYTHONUNBUFFERED=1
6
  ENV PYTHONDONTWRITEBYTECODE=1
7
+ ENV HF_HOME=/app/.cache
8
+ ENV TRANSFORMERS_CACHE=/app/.cache
9
+ ENV TORCH_HOME=/app/.cache
10
 
11
+ # نصب ابزارهای سیستم مورد نیاز
12
  RUN apt-get update && apt-get install -y \
13
  gcc \
14
  g++ \
15
  git \
16
  curl \
17
+ build-essential \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
+ # تنظیم دایرکتوری کار
21
  WORKDIR /app
22
 
23
+ # ایجاد کاربر غیر-root برای امنیت بهتر
24
+ RUN groupadd -r appuser && useradd -r -g appuser appuser
25
+
26
+ # ایجاد و تنظیم مجوزهای پوشه‌ها
27
+ RUN mkdir -p /app/.cache && \
28
+ chown -R appuser:appuser /app && \
29
+ chmod -R 755 /app
30
 
31
+ # کپی فایل requirements و نصب وابستگی‌ها
32
+ COPY requirements.txt .
33
+ RUN pip install --no-cache-dir --upgrade pip && \
34
+ pip install --no-cache-dir -r requirements.txt
35
 
36
+ # کپی کد اپلیکیشن
37
  COPY app.py .
38
 
39
+ # تغییر مالکیت فایل‌ها به appuser
40
+ RUN chown -R appuser:appuser /app
41
+
42
+ # تغییر به کاربر غیر-root
43
+ USER appuser
44
+
45
+ # تنظیم پورت
46
  EXPOSE 7860
47
 
48
+ # دستور اجرای اپلیکیشن
49
  CMD ["python", "app.py"]