khurrameycon commited on
Commit
4278031
·
verified ·
1 Parent(s): e3f5ff0

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -18
Dockerfile CHANGED
@@ -1,38 +1,43 @@
1
  FROM python:3.9-slim
2
 
3
- # 1. Install system dependencies
 
 
 
4
  RUN apt-get update && apt-get install -y \
5
  espeak-ng \
6
  git \
7
  libsndfile1 \
8
  curl
9
 
10
- # 2. Configure environment
11
  ENV PYTHONUNBUFFERED=1 \
12
- HF_HOME=/app/cache \
13
  PYTHONPATH="/app"
14
 
15
- # 3. Create cache directory with permissions
16
- RUN mkdir -p /app/cache && \
17
- chmod -R 777 /app/cache
 
18
 
19
  WORKDIR /app
20
 
21
- # 4. Install Python dependencies
22
  COPY requirements.txt .
 
23
 
24
- RUN pip install --upgrade pip setuptools wheel && \
25
- pip install --no-cache-dir -r requirements.txt
26
 
27
- # 5. Install misaki from source (with data files)
28
- RUN pip install git+https://github.com/hexgrad/misaki.git --no-cache-dir
 
29
 
30
- # 6. Fix PulseAudio warnings
31
- RUN mkdir -p /.config/pulse && \
32
- chmod -R 777 /.config
33
 
34
- # 7. Copy application code
35
- COPY . .
36
 
37
- # 8. Run FastAPI
38
- CMD uvicorn app:app --host 0.0.0.0 --port 7860
 
1
  FROM python:3.9-slim
2
 
3
+ # Create a non-root user
4
+ RUN useradd -m -u 1000 appuser
5
+
6
+ # Install system dependencies
7
  RUN apt-get update && apt-get install -y \
8
  espeak-ng \
9
  git \
10
  libsndfile1 \
11
  curl
12
 
13
+ # Configure environment
14
  ENV PYTHONUNBUFFERED=1 \
15
+ HF_HOME=/home/appuser/cache \
16
  PYTHONPATH="/app"
17
 
18
+ # Create necessary directories and set permissions
19
+ RUN mkdir -p /app /home/appuser/cache /home/appuser/.local /home/appuser/.config/pulse && \
20
+ chown -R appuser:appuser /app /home/appuser/cache /home/appuser/.local /home/appuser/.config && \
21
+ chmod -R 755 /app /home/appuser/cache /home/appuser/.local /home/appuser/.config
22
 
23
  WORKDIR /app
24
 
25
+ # Copy requirements first for better caching
26
  COPY requirements.txt .
27
+ RUN chown appuser:appuser requirements.txt
28
 
29
+ # Switch to non-root user
30
+ USER appuser
31
 
32
+ # Install Python dependencies
33
+ RUN pip install --user --upgrade pip setuptools wheel && \
34
+ pip install --user --no-cache-dir -r requirements.txt
35
 
36
+ # Install misaki from source (with data files)
37
+ RUN pip install --user git+https://github.com/hexgrad/misaki.git --no-cache-dir
 
38
 
39
+ # Copy application code
40
+ COPY --chown=appuser:appuser . .
41
 
42
+ # Run FastAPI
43
+ CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]