advanced / Dockerfile
Alina Lozovskaya
Auth
6454c0e
raw
history blame
1.58 kB
# 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"]