File size: 1,584 Bytes
aa33679
d1ed69b
 
aa33679
d1ed69b
 
 
 
 
aa33679
 
d1ed69b
aa33679
 
 
 
 
 
 
 
 
 
 
d1ed69b
 
aa33679
 
 
 
 
 
 
 
 
 
 
 
 
d1ed69b
aa33679
 
d1ed69b
aa33679
 
d1ed69b
 
 
 
6454c0e
d1ed69b
aa33679
6454c0e
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
# Use a minimal Python image
FROM python:3.12.1-slim

# Install system dependencies required for UV and Git
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl ca-certificates git && \
    rm -rf /var/lib/apt/lists/*

# Install UV (fast Python dependency manager)
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
    mv /root/.local/bin/uv /usr/local/bin/uv && chmod +x /usr/local/bin/uv

# Verify UV installation
RUN uv --version

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

# Set environment variables properly
ENV HOME=/home/uvuser \
    PATH="/usr/local/bin:$PATH" \
    XDG_CACHE_HOME=/home/uvuser/.cache \
    UV_VENV_PATH="/home/uvuser/.venv"

# Set working directory
WORKDIR /home/uvuser/app

# Ensure necessary directories exist and are writable
RUN mkdir -p /app/uploaded_files /home/uvuser/.cache && chown -R uvuser:uvuser /app /home/uvuser

# Copy pyproject.toml and uv.lock to the working directory
COPY pyproject.toml uv.lock ./

# Create the virtual environment and install dependencies as root
RUN uv venv && uv sync $(test -f uv.lock && echo "--frozen" || echo "")

# Fix ownership of cache and installed dependencies
RUN chown -R uvuser:uvuser /home/uvuser/.cache /home/uvuser/.venv /home/uvuser/app || true

# Switch to non-root user before running the app
USER uvuser

# Copy the rest of the application code
COPY --chown=uvuser:uvuser . ./

# Expose Gradio app port
EXPOSE 7860
ENV GRADIO_SERVER_NAME="0.0.0.0"
ENV SYSTEM=spaces

# Run the application
CMD ["uv", "run", "python", "yourbench_space/app.py"]