File size: 1,747 Bytes
acfee14
 
 
 
 
 
 
 
 
 
 
 
 
 
96e839c
 
 
 
 
acfee14
 
 
 
 
 
 
96e839c
acfee14
 
 
 
 
 
 
 
 
 
 
 
 
96e839c
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
# 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 and set permissions correctly
ENV HF_HOME=/app/.cache/huggingface
RUN mkdir -p /app/.cache/huggingface && \
    mkdir -p /app/.cache/torch && \
    mkdir -p /app/.cache/transformers

# Install system dependencies
RUN apt-get update && apt-get install -y \
    portaudio19-dev \
    python3-pip \
    gcc \
    git \
    curl \
    && 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 with specific UID/GID
RUN groupadd -r app --gid 1000 && \
    useradd -r -g app --uid 1000 --create-home app

# Set ownership of all cache directories
RUN chown -R app:app /app/.cache && \
    chmod -R 755 /app/.cache

# 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"]