File size: 1,633 Bytes
64e55d6
a79fd75
64e55d6
 
 
 
 
a79fd75
64e55d6
 
 
 
 
 
 
 
 
 
 
 
 
a79fd75
64e55d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a79fd75
 
 
64e55d6
 
 
 
 
787d79c
64e55d6
 
787d79c
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
70
# Stage 1: Build stage
FROM python:3.10-slim AS builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
    ffmpeg \
    libsndfile1 \
    git \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN useradd -m -u 1000 user

# Switch to non-root user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Set working directory
WORKDIR /app

# Copy requirements and setup scripts
COPY --chown=user requirements.txt setup_imagebind.py README.md main.py ./

# Install dependencies into a virtual environment
RUN python -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Run setup script to download ImageBind
RUN python setup_imagebind.py

# Install ImageBind
RUN pip install --no-cache-dir .

# Stage 2: Runtime stage
FROM python:3.10-slim

# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
    ffmpeg \
    libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN useradd -m -u 1000 user

# Switch to non-root user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Set working directory
WORKDIR /app

# Copy virtual environment from builder
COPY --from=builder --chown=user /app/venv /app/venv
ENV PATH="/app/venv/bin:$PATH"

# Copy ImageBind from builder
COPY --from=builder --chown=user /app/imagebind* .
COPY --from=builder --chown=user /app/setup.py .
COPY --from=builder --chown=user /app/build .

# Copy application code
COPY --chown=user main.py .

# Expose the port
EXPOSE 7860

# Command to run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]