Pratap-K commited on
Commit
13b198b
·
1 Parent(s): 093787f

Overhaul Docker build: single-stage, system pip, explicit deps

Browse files
Files changed (2) hide show
  1. Dockerfile +22 -55
  2. pyproject.toml +5 -12
Dockerfile CHANGED
@@ -1,77 +1,44 @@
1
  # Copyright (c) Meta Platforms, Inc. and affiliates.
2
  # All rights reserved.
3
- #
4
- # This source code is licensed under the BSD-style license found in the
5
- # LICENSE file in the root directory of this source tree.
6
 
7
- # Multi-stage build using openenv-base
8
- # This Dockerfile is flexible and works for both:
9
- # - In-repo environments (with local OpenEnv sources)
10
- # - Standalone environments (with openenv from PyPI/Git)
11
- # The build script (openenv build) handles context detection and sets appropriate build args.
12
-
13
- ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
14
- FROM ${BASE_IMAGE} AS builder
15
 
16
  WORKDIR /app
17
 
18
- # Ensure git is available (required for installing dependencies from VCS)
19
  RUN apt-get update && \
20
- apt-get install -y --no-install-recommends git && \
21
  rm -rf /var/lib/apt/lists/*
22
 
23
- # Build argument to control whether we're building standalone or in-repo
24
- ARG BUILD_MODE=in-repo
25
- ARG ENV_NAME=AutoMathReasoner
 
26
 
27
- # Copy environment code (always at root of build context)
28
  COPY . /app/env
29
-
30
- # For in-repo builds, openenv is already vendored in the build context
31
- # For standalone builds, openenv will be installed via pyproject.toml
32
  WORKDIR /app/env
33
 
34
- # Ensure uv is available (for local builds where base image lacks it)
35
- RUN if ! command -v uv >/dev/null 2>&1; then \
36
- curl -LsSf https://astral.sh/uv/install.sh | sh && \
37
- mv /root/.local/bin/uv /usr/local/bin/uv && \
38
- mv /root/.local/bin/uvx /usr/local/bin/uvx; \
39
- fi
40
-
41
- # Install dependencies using uv sync
42
- # Bypass Windows generated lock files to securely build native Linux wheels on HF Spaces
43
- RUN --mount=type=cache,target=/root/.cache/uv \
44
- rm -f uv.lock && \
45
- uv sync --no-install-project --no-editable
46
-
47
- RUN --mount=type=cache,target=/root/.cache/uv \
48
- rm -f uv.lock && \
49
- uv sync --no-editable
50
-
51
- # Final runtime stage
52
- FROM ${BASE_IMAGE}
53
-
54
- WORKDIR /app
55
-
56
- # Copy the virtual environment from builder
57
- COPY --from=builder /app/env/.venv /app/.venv
58
-
59
- # Copy the environment code
60
- COPY --from=builder /app/env /app/env
61
 
62
- # Set PATH to use the virtual environment
63
- ENV PATH="/app/.venv/bin:$PATH"
64
-
65
- # Set PYTHONPATH so imports work correctly
66
  ENV PYTHONPATH="/app/env:$PYTHONPATH"
67
 
68
- #Enable Web Interface
69
  ENV ENABLE_WEB_INTERFACE=true
70
 
 
 
 
71
  # Health check
72
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
73
  CMD curl -f http://localhost:7860/health || exit 1
74
 
75
- # Run the FastAPI server
76
- # The module path is constructed to work with the /app/env structure
77
- CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 7860"]
 
1
  # Copyright (c) Meta Platforms, Inc. and affiliates.
2
  # All rights reserved.
 
 
 
3
 
4
+ FROM ghcr.io/meta-pytorch/openenv-base:latest
 
 
 
 
 
 
 
5
 
6
  WORKDIR /app
7
 
8
+ # Ensure git and curl are available
9
  RUN apt-get update && \
10
+ apt-get install -y --no-install-recommends git curl && \
11
  rm -rf /var/lib/apt/lists/*
12
 
13
+ # Install uv explicitly to ensure we have the latest version for pip install
14
+ RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
15
+ mv /root/.local/bin/uv /usr/local/bin/uv && \
16
+ mv /root/.local/bin/uvx /usr/local/bin/uvx
17
 
18
+ # Copy the entire project to /app/env
19
  COPY . /app/env
 
 
 
20
  WORKDIR /app/env
21
 
22
+ # Install dependencies globally into the container (--system) to avoid venv migration issues.
23
+ # We remove uv.lock because it may contain platform-specific pins that conflict with Linux.
24
+ # "openenv-core" and other dependencies from pyproject.toml are installed here.
25
+ RUN rm -f uv.lock && \
26
+ uv pip install --system --no-cache .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ # Set PYTHONPATH so that 'import AutoMathReasoner' works correctly.
29
+ # The project layout has the AutoMathReasoner namespace mapped to the root directory.
 
 
30
  ENV PYTHONPATH="/app/env:$PYTHONPATH"
31
 
32
+ # Enable Web Interface for OpenEnv
33
  ENV ENABLE_WEB_INTERFACE=true
34
 
35
+ # Hugging Face Spaces dynamically assigns a port, but usually expects 7860
36
+ ENV PORT=7860
37
+
38
  # Health check
39
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
40
  CMD curl -f http://localhost:7860/health || exit 1
41
 
42
+ # Launch the FastAPI server.
43
+ # We use the module string to ensure the setup-tools mapped namespace is used.
44
+ CMD ["uvicorn", "AutoMathReasoner.server.app:app", "--host", "0.0.0.0", "--port", "7860"]
pyproject.toml CHANGED
@@ -14,18 +14,11 @@ version = "0.1.0"
14
  description = "Automathreasoner environment for OpenEnv"
15
  requires-python = ">=3.10"
16
  dependencies = [
17
- # Core OpenEnv runtime (provides FastAPI server + HTTP client types)
18
- # install from github
19
- # "openenv-core[core] @ git+https://github.com/meta-pytorch/OpenEnv.git",
20
- "openenv-core[core]>=0.2.2",
21
- # Environment-specific dependencies
22
- # Add all dependencies needed for your environment here
23
- # Examples:
24
- # "numpy>=1.19.0",
25
- # "torch>=2.0.0",
26
- # "gymnasium>=0.29.0",
27
- # "openspiel>=1.0.0",
28
- # "smolagents>=1.22.0,<2",
29
  ]
30
 
31
  [project.optional-dependencies]
 
14
  description = "Automathreasoner environment for OpenEnv"
15
  requires-python = ">=3.10"
16
  dependencies = [
17
+ "openenv-core>=0.2.2",
18
+ "numpy>=1.24.0",
19
+ "pytest>=8.0.0",
20
+ "fastapi>=0.100.0",
21
+ "uvicorn>=0.22.0",
 
 
 
 
 
 
 
22
  ]
23
 
24
  [project.optional-dependencies]