Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- DockerFile +66 -0
DockerFile
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Master Dockerfile - Optimized Multi-Stage Build
|
| 2 |
+
# This Dockerfile is fully compatible with the OpenEnv ecosystem.
|
| 3 |
+
# It uses a standard Python base for local build compatibility while
|
| 4 |
+
# maintaining the same professional structure as the official templates.
|
| 5 |
+
|
| 6 |
+
# Stage 1: Builder
|
| 7 |
+
# Resolves dependencies and prepare the virtual environment
|
| 8 |
+
FROM python:3.10-slim AS builder
|
| 9 |
+
|
| 10 |
+
ENV PYTHONUNBUFFERED=1
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
+
# Install uv for lightning-fast, reproducible dependency management
|
| 14 |
+
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates && \
|
| 15 |
+
curl -LsSf https://astral.sh/uv/install.sh | sh && \
|
| 16 |
+
mv /root/.local/bin/uv /usr/local/bin/uv && \
|
| 17 |
+
rm -rf /var/lib/apt/lists/*
|
| 18 |
+
|
| 19 |
+
# Copy dependency manifests
|
| 20 |
+
COPY pyproject.toml ./
|
| 21 |
+
COPY uv.lock ./
|
| 22 |
+
|
| 23 |
+
# Synchronize dependencies into a standalone virtual environment (.venv)
|
| 24 |
+
# This includes the openenv-core[core] package itself.
|
| 25 |
+
RUN uv sync --frozen --no-install-project --no-editable
|
| 26 |
+
|
| 27 |
+
# Copy the application source code
|
| 28 |
+
COPY . .
|
| 29 |
+
|
| 30 |
+
# Final sync to install the project package in the venv
|
| 31 |
+
RUN uv sync --frozen --no-editable
|
| 32 |
+
|
| 33 |
+
# Step 1.5: Automated OpenEnv Validation
|
| 34 |
+
# This ensures the environment is valid by OpenEnv standards before final image creation.
|
| 35 |
+
# If this fails, the build will stop, preventing invalid deployments.
|
| 36 |
+
RUN .venv/bin/openenv validate
|
| 37 |
+
|
| 38 |
+
# Stage 2: Runtime
|
| 39 |
+
# Minimal final image containing only the application and its dependencies
|
| 40 |
+
FROM python:3.10-slim
|
| 41 |
+
|
| 42 |
+
ENV PYTHONUNBUFFERED=1
|
| 43 |
+
WORKDIR /app
|
| 44 |
+
|
| 45 |
+
# Install socat (for port forwarding) and curl (for health checks)
|
| 46 |
+
RUN apt-get update && apt-get install -y --no-install-recommends socat curl && rm -rf /var/lib/apt/lists/*
|
| 47 |
+
|
| 48 |
+
# Copy the pre-built virtual environment from the builder stage
|
| 49 |
+
COPY --from=builder /app/.venv /app/.venv
|
| 50 |
+
# Copy the cleaned source code
|
| 51 |
+
COPY --from=builder /app /app
|
| 52 |
+
|
| 53 |
+
# Point PATH and PYTHONPATH to our isolated virtual environment
|
| 54 |
+
ENV PATH="/app/.venv/bin:$PATH"
|
| 55 |
+
ENV PYTHONPATH="/app:$PYTHONPATH"
|
| 56 |
+
|
| 57 |
+
# OpenEnv standard port (Hugging Face Default)
|
| 58 |
+
EXPOSE 7860
|
| 59 |
+
|
| 60 |
+
# Health Check to verify the FastAPI bridge is active
|
| 61 |
+
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
|
| 62 |
+
CMD curl -f http://127.0.0.1:7860/health || exit 1
|
| 63 |
+
|
| 64 |
+
# Start socat in the background to forward 7860 -> 8000, and start uvicorn on 8000
|
| 65 |
+
ENV ENABLE_WEB_INTERFACE=true
|
| 66 |
+
CMD socat TCP-LISTEN:7860,fork,reuseaddr TCP:127.0.0.1:8000 & uvicorn server.app:app --host 0.0.0.0 --port 8000
|