File size: 1,165 Bytes
89ed536
 
df83c02
89ed536
 
 
df83c02
89ed536
 
 
8e9e509
89ed536
 
 
ffc40d5
89ed536
 
 
 
df83c02
89ed536
 
 
 
df83c02
89ed536
 
df83c02
89ed536
 
 
 
096835f
df83c02
89ed536
fcc8497
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
# Use a specific, stable version of the slim image
FROM python:3.10.13-slim-bullseye

# Set environment variables to prevent interactive prompts during build
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1

# Install git and other system dependencies as root
RUN apt-get update && apt-get install -y --no-install-recommends git curl && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Create a non-root user and its home directory
RUN useradd -m -u 1000 user
WORKDIR /home/user/code

# Set the cache directory for Hugging Face libraries
# This directory will be created with the correct ownership later
ENV HF_HOME=/home/user/code/.cache
ENV PATH="/home/user/.local/bin:${PATH}"

# Copy requirements file and install dependencies as the new user
# First, change ownership of the destination directory
RUN chown -R user:user /home/user/code
USER user

COPY --chown=user:user ./requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Copy the rest of the application code
COPY --chown=user:user ./app.py .

# Expose the port
EXPOSE 7860

# Run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]