Anja97 commited on
Commit
5d65c37
·
1 Parent(s): adad4ac

Initial commit

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -22
Dockerfile CHANGED
@@ -1,43 +1,36 @@
1
- # Use an official Python runtime as a parent image
 
2
  FROM python:3.9-slim
3
 
4
- # Install git and git-lfs
5
  RUN apt-get update && apt-get install -y git git-lfs && git lfs install
6
 
7
- # Create a non-root user 'appuser'
 
 
 
 
 
8
  RUN useradd -ms /bin/bash appuser
9
 
10
  # Set the working directory
11
  WORKDIR /home/appuser/app
12
 
13
- # Copy requirements file
14
  COPY requirements.txt .
15
-
16
- # Install required packages
17
  RUN pip install --no-cache-dir -r requirements.txt
18
 
19
- # Copy application code
20
  COPY . .
21
 
22
- # Set environment variables for cache directories
23
- ENV HF_HOME=/home/appuser/app/.cache
24
- ENV HF_DATASETS_CACHE=/home/appuser/app/.cache
25
-
26
- # Create the cache directory
27
- RUN mkdir -p /home/appuser/app/.cache
28
-
29
- # Change ownership of the application files
30
- RUN chown -R appuser:appuser /home/appuser/app
31
 
32
  # Switch to non-root user
33
  USER appuser
34
 
35
- # Pre-download models and datasets
36
- RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
37
- RUN python -c "from datasets import load_dataset; load_dataset('Gustavosta/Stable-Diffusion-Prompts')"
38
-
39
- # Expose port 7860
40
  EXPOSE 7860
41
 
42
- # Command to run the API
43
  CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Dockerfile
2
+
3
  FROM python:3.9-slim
4
 
5
+ # Install dependencies
6
  RUN apt-get update && apt-get install -y git git-lfs && git lfs install
7
 
8
+ # Set environment variables
9
+ ENV HF_HOME="/home/appuser/.cache/huggingface"
10
+ ENV TRANSFORMERS_CACHE="/home/appuser/.cache/huggingface/transformers"
11
+ ENV HF_DATASETS_CACHE="/home/appuser/.cache/huggingface/datasets"
12
+
13
+ # Create a non-root user
14
  RUN useradd -ms /bin/bash appuser
15
 
16
  # Set the working directory
17
  WORKDIR /home/appuser/app
18
 
19
+ # Copy requirements and install
20
  COPY requirements.txt .
 
 
21
  RUN pip install --no-cache-dir -r requirements.txt
22
 
23
+ # Copy the application code
24
  COPY . .
25
 
26
+ # Change ownership
27
+ RUN chown -R appuser:appuser /home/appuser
 
 
 
 
 
 
 
28
 
29
  # Switch to non-root user
30
  USER appuser
31
 
32
+ # Expose the port
 
 
 
 
33
  EXPOSE 7860
34
 
35
+ # Command to run the application
36
  CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]