File size: 1,464 Bytes
acfee14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Use Python 3.12 slim image as base
FROM python:3.12-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    POETRY_VERSION=1.7.1 \
    POETRY_HOME="/opt/poetry" \
    POETRY_NO_INTERACTION=1 \
    GRADIO_SERVER_NAME=0.0.0.0 \
    GRADIO_SERVER_PORT=7860

# Set working directory
WORKDIR /app

# Create cache directories for Hugging Face
ENV HF_HOME=/home/app/.cache/huggingface
RUN mkdir -p /home/app/.cache/huggingface

# Install system dependencies
RUN apt-get update && apt-get install -y \
    portaudio19-dev \
    python3-pip \
    gcc \
    git \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Install poetry
RUN pip install poetry==${POETRY_VERSION} && \
    poetry config virtualenvs.create false

# Copy dependency files first
COPY pyproject.toml poetry.lock ./

# Install dependencies using the lock file
RUN poetry install --no-dev --no-interaction --no-ansi

# Create app user and group
RUN groupadd -r app && useradd -r -g app app

# Before switching to non-root user, create and set permissions
RUN mkdir -p /home/app/.cache && \
    mkdir -p /home/app/.config/matplotlib && \
    chown -R app:app /home/app/.cache && \
    chown -R app:app /home/app/.config

# Set matplotlib config dir
ENV MPLCONFIGDIR=/home/app/.config/matplotlib

# Switch to non-root user
USER app

# Copy the rest of the application
COPY --chown=app:app . .

# Expose the port the app runs on
EXPOSE 7860

# Run the application
CMD ["python", "app.py"]