danicor commited on
Commit
4c311c6
·
verified ·
1 Parent(s): c347685

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -13
Dockerfile CHANGED
@@ -1,30 +1,37 @@
1
  # Base image
2
  FROM python:3.10-slim
3
 
4
- # نصب git و pip tools
5
  RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
6
 
 
 
 
7
 
8
- RUN mkdir -p /home/user/hf_cache && chown -R 1000:1000 /home/user/hf_cache
9
-
10
- RUN mkdir -p /home/user/app/huggingface_models && chown -R 1000:1000 /home/user/app/huggingface_models
11
 
 
 
12
 
13
  # کلون کردن ریپو CelebAMask-HQ
14
  RUN git clone https://github.com/switchablenorms/CelebAMask-HQ.git /home/user/app/huggingface_models/CelebAMask-HQ
15
 
16
- # مسیر PYTHONPATH
17
- ENV PYTHONPATH="/home/user/CelebAMask-HQ:${PYTHONPATH}"
 
 
 
18
 
19
- # نصب پکیج‌ها
20
- COPY requirements.txt /tmp/requirements.txt
21
- RUN pip install --no-cache-dir -r /tmp/requirements.txt
22
 
23
- # ست کردن مسیر کاری
24
- WORKDIR /home/user/app
25
 
26
  # کپی اپلیکیشن
27
- COPY app.py /home/user/app/app.py
28
 
29
  # دستور پیش‌فرض اجرای اپ
30
- CMD ["python", "app.py"]
 
1
  # Base image
2
  FROM python:3.10-slim
3
 
4
+ # نصب وابستگی‌های ضروری
5
  RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
6
 
7
+ # ایجاد کاربر غیر روت برای امنیت
8
+ RUN useradd -m -u 1000 user
9
+ USER user
10
 
11
+ # ایجاد دایرکتوری‌های لازم با مالکیت کاربر
12
+ RUN mkdir -p /home/user/app/hf_cache
13
+ RUN mkdir -p /home/user/app/huggingface_models
14
 
15
+ # تنظیم مسیر کاری
16
+ WORKDIR /home/user/app
17
 
18
  # کلون کردن ریپو CelebAMask-HQ
19
  RUN git clone https://github.com/switchablenorms/CelebAMask-HQ.git /home/user/app/huggingface_models/CelebAMask-HQ
20
 
21
+ # تنظیم متغیرهای محیطی
22
+ ENV PYTHONPATH="/home/user/app/huggingface_models/CelebAMask-HQ:${PYTHONPATH}"
23
+ ENV HF_HOME="/home/user/app/hf_cache"
24
+ ENV TRANSFORMERS_CACHE="/home/user/app/hf_cache"
25
+ ENV HUGGINGFACE_HUB_CACHE="/home/user/app/hf_cache"
26
 
27
+ # کپی فایل requirements
28
+ COPY --chown=user:user requirements.txt .
 
29
 
30
+ # نصب پکیج‌ها
31
+ RUN pip install --no-cache-dir -r requirements.txt
32
 
33
  # کپی اپلیکیشن
34
+ COPY --chown=user:user app.py .
35
 
36
  # دستور پیش‌فرض اجرای اپ
37
+ CMD ["python", "app.py"]