File size: 2,491 Bytes
76a9baa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
# Master Dockerfile - Optimized Multi-Stage Build
# This Dockerfile is fully compatible with the OpenEnv ecosystem.
# It uses a standard Python base for local build compatibility while 
# maintaining the same professional structure as the official templates.

# Stage 1: Builder
# Resolves dependencies and prepare the virtual environment
FROM python:3.10-slim AS builder

ENV PYTHONUNBUFFERED=1
WORKDIR /app

# Install uv for lightning-fast, reproducible dependency management
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates && \

    curl -LsSf https://astral.sh/uv/install.sh | sh && \
    mv /root/.local/bin/uv /usr/local/bin/uv && \
    rm -rf /var/lib/apt/lists/*

# Copy dependency manifests
COPY pyproject.toml ./
COPY uv.lock ./

# Synchronize dependencies into a standalone virtual environment (.venv)
# This includes the openenv-core[core] package itself.
RUN uv sync --frozen --no-install-project --no-editable

# Copy the application source code
COPY . .

# Final sync to install the project package in the venv
RUN uv sync --frozen --no-editable

# Step 1.5: Automated OpenEnv Validation
# This ensures the environment is valid by OpenEnv standards before final image creation.
# If this fails, the build will stop, preventing invalid deployments.
RUN .venv/bin/openenv validate

# Stage 2: Runtime
# Minimal final image containing only the application and its dependencies
FROM python:3.10-slim

ENV PYTHONUNBUFFERED=1
WORKDIR /app

# Install socat (for port forwarding) and curl (for health checks)
RUN apt-get update && apt-get install -y --no-install-recommends socat curl && rm -rf /var/lib/apt/lists/*

# Copy the pre-built virtual environment from the builder stage
COPY --from=builder /app/.venv /app/.venv
# Copy the cleaned source code
COPY --from=builder /app /app

# Point PATH and PYTHONPATH to our isolated virtual environment
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="/app:$PYTHONPATH"

# OpenEnv standard port (Hugging Face Default)
EXPOSE 7860

# Health Check to verify the FastAPI bridge is active
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \

    CMD curl -f http://127.0.0.1:7860/health || exit 1

# Start socat in the background to forward 7860 -> 8000, and start uvicorn on 8000
ENV ENABLE_WEB_INTERFACE=true
CMD socat TCP-LISTEN:7860,fork,reuseaddr TCP:127.0.0.1:8000 & uvicorn server.app:app --host 0.0.0.0 --port 8000