acpc-testing-third / Dockerfile
Stoic-2910's picture
Upload Dockerfile
5aa6158 verified
Raw History Blame Contribute Delete
1.02 kB
# Stage 1: Build dependencies
FROM python:3.11-slim AS builder
# Copy the uv binary from the official image
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Enable bytecode compilation and use copy instead of hardlinks
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
WORKDIR /app
# Copy configuration files
COPY pyproject.toml uv.lock ./
# Install dependencies into a virtual environment
RUN uv sync --frozen --no-dev
# Stage 2: Runtime
FROM python:3.11-slim AS runtime
WORKDIR /app
# Copy the virtual environment from the builder
COPY --from=builder /app/.venv /app/.venv
# Ensure the virtual environment is in the PATH
ENV PATH="/app/.venv/bin:$PATH"
# Create non-root user for security
# Hugging Face Spaces uses UID 1000
RUN useradd -m -u 1000 appuser
# Copy application code
COPY app/ ./app/
# Switch to non-root user
USER appuser
EXPOSE 7860
# Run the application using uvicorn from the virtual environment
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"]