Download Dockerfile from Ryz3n758/layoutenv: direct link, hf CLI and curl.
- Browser
- Download file 3.16 kB
-
https://huggingface.co/spaces/Ryz3n758/layoutenv/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/Ryz3n758/layoutenv/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/Ryz3n758/layoutenv/resolve/main/Dockerfile
3.16 kB
| ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest | |
| FROM ${BASE_IMAGE} AS builder | |
| WORKDIR /app | |
| # Ensure git is available (required for installing dependencies from VCS) | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends git && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Build argument to control whether we're building standalone or in-repo | |
| ARG BUILD_MODE=in-repo | |
| ARG ENV_NAME=layoutenv | |
| # Copy environment code (always at root of build context) | |
| COPY . /app/env | |
| # For in-repo builds, openenv is already vendored in the build context | |
| # For standalone builds, openenv will be installed via pyproject.toml | |
| WORKDIR /app/env | |
| # Ensure stats directory exists and copy precomputed dataset stats when present. | |
| # Supports both common build-context layouts: | |
| # - context at repo root -> /app/env/dataset/... | |
| # - context at layoutenv/ -> optional /app/dataset/... fallback | |
| RUN mkdir -p /app/env/dataset && \ | |
| if [ -f /app/env/dataset/genposter_5000_images_stats.npy ]; then \ | |
| echo "Using stats at /app/env/dataset/genposter_5000_images_stats.npy"; \ | |
| elif [ -f /app/dataset/genposter_5000_images_stats.npy ]; then \ | |
| cp /app/dataset/genposter_5000_images_stats.npy /app/env/dataset/genposter_5000_images_stats.npy; \ | |
| echo "Copied stats into /app/env/dataset/genposter_5000_images_stats.npy"; \ | |
| else \ | |
| echo "Warning: genposter_5000_images_stats.npy not found in build context."; \ | |
| fi | |
| # Ensure uv is available (for local builds where base image lacks it) | |
| RUN if ! command -v uv >/dev/null 2>&1; then \ | |
| 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; \ | |
| fi | |
| # Install dependencies using uv sync | |
| # If uv.lock exists, use it; otherwise resolve on the fly | |
| RUN --mount=type=cache,target=/root/.cache/uv \ | |
| if [ -f uv.lock ]; then \ | |
| uv sync --frozen --no-install-project --no-editable; \ | |
| else \ | |
| uv sync --no-install-project --no-editable; \ | |
| fi | |
| RUN --mount=type=cache,target=/root/.cache/uv \ | |
| if [ -f uv.lock ]; then \ | |
| uv sync --frozen --no-editable; \ | |
| else \ | |
| uv sync --no-editable; \ | |
| fi | |
| # Final runtime stage | |
| FROM ${BASE_IMAGE} | |
| WORKDIR /app | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends curl && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Copy the virtual environment from builder | |
| COPY --from=builder /app/env/.venv /app/env/.venv | |
| # Copy the environment code | |
| COPY --from=builder /app/env /app/env | |
| # Set PATH to use the virtual environment | |
| ENV PATH="/app/env/.venv/bin:$PATH" | |
| # Set PYTHONPATH so imports work correctly | |
| ENV PYTHONPATH="/app/env:$PYTHONPATH" | |
| ENV PYTHONUNBUFFERED=1 | |
| # Gradio Web UI at /web (same pattern as snake_env server) | |
| ENV ENABLE_WEB_INTERFACE=true | |
| EXPOSE 8000 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ | |
| CMD curl -fsS http://localhost:8000/health || exit 1 | |
| # Run the FastAPI server | |
| # The module path is constructed to work with the /app/env structure | |
| CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 8000"] | |