Spaces:
Sleeping
Sleeping
File size: 2,250 Bytes
57a6d0c 22b11ca 57a6d0c 22b11ca 57a6d0c 22b11ca 57a6d0c 22b11ca 57a6d0c 22b11ca 3ba81b5 57a6d0c 22b11ca 3ba81b5 57a6d0c 22b11ca 57a6d0c 22b11ca 57a6d0c 22b11ca 57a6d0c 22b11ca 57a6d0c 8412998 57a6d0c 22b11ca 57a6d0c 22b11ca 57a6d0c 22b11ca | 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 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# Multi-stage build tuned for both local docker validation and Hugging Face
# Docker Spaces. The app itself still serves OpenEnv on port 8000, but the
# container exposes the Space-facing port 7860 and forwards traffic there.
FROM python:3.10-slim AS builder
ENV PYTHONUNBUFFERED=1
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends curl ca-certificates git && \
curl -LsSf https://astral.sh/uv/install.sh | sh && \
mv /root/.local/bin/uv /usr/local/bin/uv && \
mv /root/.local/bin/uvx /usr/local/bin/uvx && \
rm -rf /var/lib/apt/lists/*
# Install only the server/runtime dependencies so the deployment image stays
# lean and does not pull the full training stack.
COPY server/requirements.txt /app/server-requirements.txt
RUN uv venv /app/.venv && \
uv pip install --python /app/.venv/bin/python -r /app/server-requirements.txt
COPY . /app/env
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="/app/env:$PYTHONPATH"
# Validate the environment during build so bad deploys fail early.
RUN cd /app/env && openenv validate
FROM python:3.10-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends socat curl ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app/env /app/env
COPY --from=builder /app/env/README.md /app/README.md
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="/app/env:$PYTHONPATH"
EXPOSE 7860
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://127.0.0.1:7860/health || exit 1
# Hugging Face Docker Spaces expects the public app port to be the README
# `app_port` (7860 here). OpenEnv itself stays on 8000 internally.
ENV ENABLE_WEB_INTERFACE=true
CMD ["sh", "-c", "SPACE_PORT=${PORT:-7860}; cd /app/env && socat TCP-LISTEN:${SPACE_PORT},fork,reuseaddr TCP:127.0.0.1:8000 & exec uvicorn server.app:app --host 0.0.0.0 --port 8000"]
|