anushaacharya commited on
Commit
e096903
·
verified ·
1 Parent(s): d218d3a

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. Dockerfile +16 -52
  2. client.py +4 -4
  3. models.py +2 -2
  4. server/app.py +9 -4
  5. server/minesweeper_environment.py +3 -3
Dockerfile CHANGED
@@ -4,69 +4,33 @@
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
- ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
8
- FROM ${BASE_IMAGE} AS builder
9
 
10
- WORKDIR /app
11
-
12
- # Build argument to control whether we're building standalone or in-repo
13
- ARG BUILD_MODE=in-repo
14
-
15
- # Copy environment code (always at root of build context)
16
- COPY . /app/env
17
-
18
- # For in-repo builds, openenv-core is already in the pyproject.toml dependencies
19
- # For standalone builds, openenv-core will be installed from pip via pyproject.toml
20
  WORKDIR /app/env
21
 
22
- # Ensure uv is available (for local builds where base image lacks it)
23
- RUN if ! command -v uv >/dev/null 2>&1; then \
24
- curl -LsSf https://astral.sh/uv/install.sh | sh && \
25
- mv /root/.local/bin/uv /usr/local/bin/uv && \
26
- mv /root/.local/bin/uvx /usr/local/bin/uvx; \
27
- fi
28
-
29
- # Install git for building from git repos (build-time only)
30
- RUN apt-get update && apt-get install -y --no-install-recommends \
31
  git \
32
  && rm -rf /var/lib/apt/lists/*
33
 
34
- # Install dependencies using uv sync
35
- RUN --mount=type=cache,target=/root/.cache/uv \
36
- if [ -f uv.lock ]; then \
37
- uv sync --frozen --no-install-project --no-editable; \
38
- else \
39
- uv sync --no-install-project --no-editable; \
40
- fi
41
-
42
- RUN --mount=type=cache,target=/root/.cache/uv \
43
- if [ -f uv.lock ]; then \
44
- uv sync --frozen --no-editable; \
45
- else \
46
- uv sync --no-editable; \
47
- fi
48
 
49
- # Final runtime stage
50
- FROM ${BASE_IMAGE}
51
 
52
- WORKDIR /app
 
53
 
54
- # Copy the virtual environment from builder
55
- COPY --from=builder /app/env/.venv /app/.venv
56
-
57
- # Copy the environment code
58
- COPY --from=builder /app/env /app/env
59
-
60
- # Set PATH to use the virtual environment
61
- ENV PATH="/app/.venv/bin:$PATH"
62
-
63
- # Set PYTHONPATH so imports work correctly
64
- ENV PYTHONPATH="/app/env:$PYTHONPATH"
65
 
66
- # Health check using Python (more portable than curl/wget)
67
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
68
  CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
69
 
70
  # Run the FastAPI server
71
- ENV ENABLE_WEB_INTERFACE=true
72
- CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 8000"]
 
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
+ # Base image
8
+ FROM python:3.11-slim
9
 
10
+ # Set working directory
 
 
 
 
 
 
 
 
 
11
  WORKDIR /app/env
12
 
13
+ # Install system dependencies
14
+ RUN apt-get update && apt-get install -y \
 
 
 
 
 
 
 
15
  git \
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
+ # Copy environment files
19
+ COPY . .
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ # Install Python dependencies
22
+ RUN pip install --no-cache-dir -e .
23
 
24
+ # Expose port
25
+ EXPOSE 8000
26
 
27
+ # Set environment variables
28
+ ENV PYTHONUNBUFFERED=1
29
+ ENV ENABLE_WEB_INTERFACE=true
 
 
 
 
 
 
 
 
30
 
31
+ # Health check
32
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
33
  CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
34
 
35
  # Run the FastAPI server
36
+ CMD ["python", "-m", "uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
 
client.py CHANGED
@@ -21,10 +21,10 @@ try:
21
  from openenv.core.env_client import EnvClient
22
  from .models import MinesweeperAction, MinesweeperObservation
23
  except ImportError:
24
- # Standalone imports (when environment is standalone with openenv from pip)
25
- from openenv.core.client_types import StepResult
26
- from openenv.core.env_server.types import State
27
- from openenv.core.env_client import EnvClient
28
  from models import MinesweeperAction, MinesweeperObservation
29
 
30
 
 
21
  from openenv.core.env_client import EnvClient
22
  from .models import MinesweeperAction, MinesweeperObservation
23
  except ImportError:
24
+ # Standalone imports (when environment is standalone with openenv-core from pip)
25
+ from openenv_core.client_types import StepResult
26
+ from openenv_core.env_server.types import State
27
+ from openenv_core.env_client import EnvClient
28
  from models import MinesweeperAction, MinesweeperObservation
29
 
30
 
models.py CHANGED
@@ -20,8 +20,8 @@ try:
20
  # In-repo imports (when running from OpenEnv repository)
21
  from openenv.core.env_server.types import Action, Observation
22
  except ImportError:
23
- # Standalone imports (when environment is standalone with openenv from pip)
24
- from openenv.core.env_server.types import Action, Observation
25
 
26
 
27
  class GameStatus(Enum):
 
20
  # In-repo imports (when running from OpenEnv repository)
21
  from openenv.core.env_server.types import Action, Observation
22
  except ImportError:
23
+ # Standalone imports (when environment is standalone with openenv-core from pip)
24
+ from openenv_core.env_server.types import Action, Observation
25
 
26
 
27
  class GameStatus(Enum):
server/app.py CHANGED
@@ -11,8 +11,8 @@ try:
11
  # In-repo imports (when running from OpenEnv repository)
12
  from openenv.core.env_server import create_app
13
  except ImportError:
14
- # Standalone imports (when environment is standalone with openenv from pip)
15
- from openenv.core.env_server import create_app
16
 
17
  try:
18
  from ..models import MinesweeperAction, MinesweeperObservation
@@ -22,7 +22,6 @@ except ImportError:
22
  from server.minesweeper_environment import MinesweeperEnvironment
23
 
24
  # Create the FastAPI app
25
- # Pass the class (factory) instead of an instance for WebSocket session support
26
  app = create_app(
27
  MinesweeperEnvironment,
28
  MinesweeperAction,
@@ -30,6 +29,12 @@ app = create_app(
30
  env_name="minesweeper_env"
31
  )
32
 
33
- if __name__ == "__main__":
 
 
34
  import uvicorn
35
  uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
 
 
 
11
  # In-repo imports (when running from OpenEnv repository)
12
  from openenv.core.env_server import create_app
13
  except ImportError:
14
+ # Standalone imports (when environment is standalone with openenv-core from pip)
15
+ from openenv_core.env_server.http_server import create_app
16
 
17
  try:
18
  from ..models import MinesweeperAction, MinesweeperObservation
 
22
  from server.minesweeper_environment import MinesweeperEnvironment
23
 
24
  # Create the FastAPI app
 
25
  app = create_app(
26
  MinesweeperEnvironment,
27
  MinesweeperAction,
 
29
  env_name="minesweeper_env"
30
  )
31
 
32
+
33
+ def main():
34
+ """Entry point for direct execution."""
35
  import uvicorn
36
  uvicorn.run(app, host="0.0.0.0", port=8000)
37
+
38
+
39
+ if __name__ == "__main__":
40
+ main()
server/minesweeper_environment.py CHANGED
@@ -35,9 +35,9 @@ try:
35
  from openenv.core.env_server.interfaces import Environment
36
  from openenv.core.env_server.types import State
37
  except ImportError:
38
- # Standalone imports (when environment is standalone with openenv from pip)
39
- from openenv.core.env_server.interfaces import Environment
40
- from openenv.core.env_server.types import State
41
 
42
 
43
  class MinesweeperEnvironment(Environment):
 
35
  from openenv.core.env_server.interfaces import Environment
36
  from openenv.core.env_server.types import State
37
  except ImportError:
38
+ # Standalone imports (when environment is standalone with openenv-core from pip)
39
+ from openenv_core.env_server.interfaces import Environment
40
+ from openenv_core.env_server.types import State
41
 
42
 
43
  class MinesweeperEnvironment(Environment):