mike23415 commited on
Commit
1b26681
·
verified ·
1 Parent(s): a3b8412

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +11 -10
Dockerfile CHANGED
@@ -10,13 +10,14 @@ RUN apt-get update && \
10
  fonts-liberation \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
- # Create cache directory with full permissions
14
- RUN mkdir -p /app/.cache && \
15
- chmod -R 777 /app/.cache
 
16
 
17
  WORKDIR /app
18
 
19
- # Set updated Hugging Face environment variables
20
  ENV HF_HOME=/app/.cache \
21
  XDG_CACHE_HOME=/app/.cache
22
 
@@ -24,14 +25,14 @@ ENV HF_HOME=/app/.cache \
24
  COPY requirements.txt .
25
  RUN pip install --no-cache-dir -r requirements.txt
26
 
27
- # Pre-download model
28
  RUN python -c "from transformers import GPT2LMHeadModel; \
29
  GPT2LMHeadModel.from_pretrained('gpt2-medium', use_safetensors=True)" && \
30
- chmod -R 777 /app/.cache
31
 
32
- COPY . .
 
 
 
33
 
34
- # Run as non-root user with explicit permissions
35
- USER 1000
36
- RUN chmod -R 777 /app/.cache
37
  CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--timeout", "600", "app:app"]
 
10
  fonts-liberation \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
+ # Create app user and cache directory
14
+ RUN useradd -m appuser && \
15
+ mkdir -p /app/.cache && \
16
+ chown -R appuser:appuser /app/.cache
17
 
18
  WORKDIR /app
19
 
20
+ # Set environment variables
21
  ENV HF_HOME=/app/.cache \
22
  XDG_CACHE_HOME=/app/.cache
23
 
 
25
  COPY requirements.txt .
26
  RUN pip install --no-cache-dir -r requirements.txt
27
 
28
+ # Download model as root then fix permissions
29
  RUN python -c "from transformers import GPT2LMHeadModel; \
30
  GPT2LMHeadModel.from_pretrained('gpt2-medium', use_safetensors=True)" && \
31
+ chown -R appuser:appuser /app/.cache
32
 
33
+ COPY --chown=appuser:appuser . .
34
+
35
+ # Run as non-root user
36
+ USER appuser
37
 
 
 
 
38
  CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--timeout", "600", "app:app"]